| 1 | From ed2ec6f0243249d3673a23d99aefc919e24cdeca Mon Sep 17 00:00:00 2001
|
| 2 | From: Pyrox <[email protected]>
|
| 3 | Date: Fri, 2 Aug 2024 14:40:37 -0400
|
| 4 | Subject: [PATCH 1/4] autoconvert nose assertions with nose2pytest
|
| 5 |
|
| 6 | ---
|
| 7 | mohawk/tests.py | 22 +++++++++++-----------
|
| 8 | 1 file changed, 11 insertions(+), 11 deletions(-)
|
| 9 |
|
| 10 | diff --git a/mohawk/tests.py b/mohawk/tests.py
|
| 11 | index e680cf8..505c7d8 100644
|
| 12 | |
| 13 | |
| 14 | @@ -288,8 +288,8 @@ def test_expired_exception_reports_localtime(self):
|
| 15 | except:
|
| 16 | etype, exc, tb = sys.exc_info()
|
| 17 |
|
| 18 | - eq_(type(exc), TokenExpired)
|
| 19 | - eq_(exc.localtime_in_seconds, now)
|
| 20 | + assert type(exc) == TokenExpired
|
| 21 | + assert exc.localtime_in_seconds == now
|
| 22 |
|
| 23 | def test_localtime_offset(self):
|
| 24 | now = utc_now() - 120
|
| 25 | @@ -371,7 +371,7 @@ def test_ext_with_equality_sign(self):
|
| 26 | sn = self.Sender(ext="foo=bar&foo2=bar2;foo3=bar3")
|
| 27 | self.receive(sn.request_header)
|
| 28 | parsed = parse_authorization_header(sn.request_header)
|
| 29 | - eq_(parsed['ext'], "foo=bar&foo2=bar2;foo3=bar3")
|
| 30 | + assert parsed['ext'] == "foo=bar&foo2=bar2;foo3=bar3"
|
| 31 |
|
| 32 | @raises(HawkFail)
|
| 33 | def test_non_hawk_scheme(self):
|
| 34 | @@ -385,7 +385,7 @@ def test_ext_with_all_valid_characters(self):
|
| 35 | valid_characters = "!#$%&'()*+,-./:;<=>?@[]^_`{|}~ azAZ09_"
|
| 36 | sender = self.Sender(ext=valid_characters)
|
| 37 | parsed = parse_authorization_header(sender.request_header)
|
| 38 | - eq_(parsed['ext'], valid_characters)
|
| 39 | + assert parsed['ext'] == valid_characters
|
| 40 |
|
| 41 | @raises(BadHeaderValue)
|
| 42 | def test_ext_with_illegal_chars(self):
|
| 43 | @@ -421,7 +421,7 @@ def test_app_ok(self):
|
| 44 | sn = self.Sender(app=app)
|
| 45 | self.receive(sn.request_header)
|
| 46 | parsed = parse_authorization_header(sn.request_header)
|
| 47 | - eq_(parsed['app'], app)
|
| 48 | + assert parsed['app'] == app
|
| 49 |
|
| 50 | @raises(MacMismatch)
|
| 51 | def test_tampered_app(self):
|
| 52 | @@ -435,7 +435,7 @@ def test_dlg_ok(self):
|
| 53 | sn = self.Sender(dlg=dlg)
|
| 54 | self.receive(sn.request_header)
|
| 55 | parsed = parse_authorization_header(sn.request_header)
|
| 56 | - eq_(parsed['dlg'], dlg)
|
| 57 | + assert parsed['dlg'] == dlg
|
| 58 |
|
| 59 | @raises(MacMismatch)
|
| 60 | def test_tampered_dlg(self):
|
| 61 | @@ -589,7 +589,7 @@ def test_respond_with_expired_ts(self):
|
| 62 | calculated = calculate_ts_mac(fn(), self.credentials)
|
| 63 | if isinstance(calculated, six.binary_type):
|
| 64 | calculated = calculated.decode('ascii')
|
| 65 | - eq_(hdr['tsm'], calculated)
|
| 66 | + assert hdr['tsm'] == calculated
|
| 67 | raise
|
| 68 |
|
| 69 | def test_respond_with_bad_ts_skew_ok(self):
|
| 70 | @@ -611,7 +611,7 @@ def test_respond_with_ext(self):
|
| 71 | ext = 'custom-ext'
|
| 72 | self.respond(ext=ext)
|
| 73 | header = parse_authorization_header(self.receiver.response_header)
|
| 74 | - eq_(header['ext'], ext)
|
| 75 | + assert header['ext'] == ext
|
| 76 |
|
| 77 | @raises(MacMismatch)
|
| 78 | def test_respond_with_wrong_app(self):
|
| 79 | @@ -854,7 +854,7 @@ def test_bewit(self):
|
| 80 | bewit = get_bewit(res)
|
| 81 |
|
| 82 | expected = '123456\\1356420707\\IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=\\'
|
| 83 | - eq_(b64decode(bewit).decode('ascii'), expected)
|
| 84 | + assert b64decode(bewit).decode('ascii') == expected
|
| 85 |
|
| 86 | def test_bewit_with_binary_id(self):
|
| 87 | # Check for exceptions in get_bewit call with binary id
|
| 88 | @@ -877,7 +877,7 @@ def test_bewit_with_ext(self):
|
| 89 | bewit = get_bewit(res)
|
| 90 |
|
| 91 | expected = '123456\\1356420707\\kscxwNR2tJpP1T1zDLNPbB5UiKIU9tOSJXTUdG7X9h8=\\xandyandz'
|
| 92 | - eq_(b64decode(bewit).decode('ascii'), expected)
|
| 93 | + assert b64decode(bewit).decode('ascii') == expected
|
| 94 |
|
| 95 | @raises(BadHeaderValue)
|
| 96 | def test_bewit_with_invalid_ext(self):
|
| 97 | @@ -905,7 +905,7 @@ def test_bewit_with_port(self):
|
| 98 | bewit = get_bewit(res)
|
| 99 |
|
| 100 | expected = '123456\\1356420707\\hZbJ3P2cKEo4ky0C8jkZAkRyCZueg4WSNbxV7vq3xHU=\\xandyandz'
|
| 101 | - eq_(b64decode(bewit).decode('ascii'), expected)
|
| 102 | + assert b64decode(bewit).decode('ascii') == expected
|
| 103 |
|
| 104 | @raises(ValueError)
|
| 105 | def test_bewit_with_nonce(self):
|
| 106 |
|
| 107 | From 66157c7efbf6b0d18c30a9ffe5dfd84bef27bd3a Mon Sep 17 00:00:00 2001
|
| 108 | From: Pyrox <[email protected]>
|
| 109 | Date: Fri, 2 Aug 2024 15:20:34 -0400
|
| 110 | Subject: [PATCH 2/4] nose.raises -> unittest.assertRaises
|
| 111 |
|
| 112 | ---
|
| 113 | mohawk/tests.py | 385 ++++++++++++++++++++++++------------------------
|
| 114 | 1 file changed, 191 insertions(+), 194 deletions(-)
|
| 115 |
|
| 116 | diff --git a/mohawk/tests.py b/mohawk/tests.py
|
| 117 | index 505c7d8..801c1dd 100644
|
| 118 | |
| 119 | |
| 120 | @@ -1,10 +1,8 @@
|
| 121 | import sys
|
| 122 | import warnings
|
| 123 | -from unittest import TestCase
|
| 124 | +from unittest import TestCase, mock
|
| 125 | from base64 import b64decode, urlsafe_b64encode
|
| 126 |
|
| 127 | -import mock
|
| 128 | -from nose.tools import eq_, raises
|
| 129 | import six
|
| 130 |
|
| 131 | from . import Receiver, Sender
|
| 132 | @@ -60,27 +58,27 @@ def credentials_map(self, id):
|
| 133 |
|
| 134 | class TestConfig(Base):
|
| 135 |
|
| 136 | - @raises(InvalidCredentials)
|
| 137 | def test_no_id(self):
|
| 138 | c = self.credentials.copy()
|
| 139 | del c['id']
|
| 140 | - validate_credentials(c)
|
| 141 | + with self.assertRaises(InvalidCredentials):
|
| 142 | + validate_credentials(c)
|
| 143 |
|
| 144 | - @raises(InvalidCredentials)
|
| 145 | def test_no_key(self):
|
| 146 | c = self.credentials.copy()
|
| 147 | del c['key']
|
| 148 | - validate_credentials(c)
|
| 149 | + with self.assertRaises(InvalidCredentials):
|
| 150 | + validate_credentials(c)
|
| 151 |
|
| 152 | - @raises(InvalidCredentials)
|
| 153 | def test_no_algo(self):
|
| 154 | c = self.credentials.copy()
|
| 155 | del c['algorithm']
|
| 156 | - validate_credentials(c)
|
| 157 | + with self.assertRaises(InvalidCredentials):
|
| 158 | + validate_credentials(c)
|
| 159 |
|
| 160 | - @raises(InvalidCredentials)
|
| 161 | def test_no_credentials(self):
|
| 162 | - validate_credentials(None)
|
| 163 | + with self.assertRaises(InvalidCredentials):
|
| 164 | + validate_credentials(None)
|
| 165 |
|
| 166 | def test_non_dict_credentials(self):
|
| 167 | class WeirdThing(object):
|
| 168 | @@ -144,10 +142,10 @@ def test_post_content_type_with_trailing_charset(self):
|
| 169 | self.receive(sn.request_header, method=method, content=content,
|
| 170 | content_type='application/json; charset=other')
|
| 171 |
|
| 172 | - @raises(MissingContent)
|
| 173 | def test_missing_payload_details(self):
|
| 174 | - self.Sender(method='POST', content=EmptyValue,
|
| 175 | - content_type=EmptyValue)
|
| 176 | + with self.assertRaises(MissingContent):
|
| 177 | + self.Sender(method='POST', content=EmptyValue,
|
| 178 | + content_type=EmptyValue)
|
| 179 |
|
| 180 | def test_skip_payload_hashing(self):
|
| 181 | method = 'POST'
|
| 182 | @@ -193,73 +191,72 @@ def test_empty_payload_hashing_accept_untrusted(self):
|
| 183 | content_type=content_type,
|
| 184 | accept_untrusted_content=True)
|
| 185 |
|
| 186 | - @raises(MissingContent)
|
| 187 | def test_cannot_skip_content_only(self):
|
| 188 | - self.Sender(method='POST', content=EmptyValue,
|
| 189 | - content_type='application/json')
|
| 190 | + with self.assertRaises(MissingContent):
|
| 191 | + self.Sender(method='POST', content=EmptyValue,
|
| 192 | + content_type='application/json')
|
| 193 |
|
| 194 | - @raises(MissingContent)
|
| 195 | def test_cannot_skip_content_type_only(self):
|
| 196 | - self.Sender(method='POST', content='{"foo": "bar"}',
|
| 197 | - content_type=EmptyValue)
|
| 198 | + with self.assertRaises(MissingContent):
|
| 199 | + self.Sender(method='POST', content='{"foo": "bar"}',
|
| 200 | + content_type=EmptyValue)
|
| 201 |
|
| 202 | - @raises(MacMismatch)
|
| 203 | def test_tamper_with_host(self):
|
| 204 | sn = self.Sender()
|
| 205 | - self.receive(sn.request_header, url='http://TAMPERED-WITH.com')
|
| 206 | + with self.assertRaises(MacMismatch):
|
| 207 | + self.receive(sn.request_header, url='http://TAMPERED-WITH.com')
|
| 208 |
|
| 209 | - @raises(MacMismatch)
|
| 210 | def test_tamper_with_method(self):
|
| 211 | sn = self.Sender(method='GET')
|
| 212 | - self.receive(sn.request_header, method='POST')
|
| 213 | + with self.assertRaises(MacMismatch):
|
| 214 | + self.receive(sn.request_header, method='POST')
|
| 215 |
|
| 216 | - @raises(MacMismatch)
|
| 217 | def test_tamper_with_path(self):
|
| 218 | sn = self.Sender()
|
| 219 | - self.receive(sn.request_header,
|
| 220 | - url='http://site.com/TAMPERED?bar=1')
|
| 221 | + with self.assertRaises(MacMismatch):
|
| 222 | + self.receive(sn.request_header,
|
| 223 | + url='http://site.com/TAMPERED?bar=1')
|
| 224 |
|
| 225 | - @raises(MacMismatch)
|
| 226 | def test_tamper_with_query(self):
|
| 227 | sn = self.Sender()
|
| 228 | - self.receive(sn.request_header,
|
| 229 | - url='http://site.com/foo?bar=TAMPERED')
|
| 230 | + with self.assertRaises(MacMismatch):
|
| 231 | + self.receive(sn.request_header,
|
| 232 | + url='http://site.com/foo?bar=TAMPERED')
|
| 233 |
|
| 234 | - @raises(MacMismatch)
|
| 235 | def test_tamper_with_scheme(self):
|
| 236 | sn = self.Sender()
|
| 237 | - self.receive(sn.request_header, url='https://site.com/foo?bar=1')
|
| 238 | + with self.assertRaises(MacMismatch):
|
| 239 | + self.receive(sn.request_header, url='https://site.com/foo?bar=1')
|
| 240 |
|
| 241 | - @raises(MacMismatch)
|
| 242 | def test_tamper_with_port(self):
|
| 243 | sn = self.Sender()
|
| 244 | - self.receive(sn.request_header,
|
| 245 | - url='http://site.com:8000/foo?bar=1')
|
| 246 | + with self.assertRaises(MacMismatch):
|
| 247 | + self.receive(sn.request_header,
|
| 248 | + url='http://site.com:8000/foo?bar=1')
|
| 249 |
|
| 250 | - @raises(MisComputedContentHash)
|
| 251 | def test_tamper_with_content(self):
|
| 252 | sn = self.Sender()
|
| 253 | - self.receive(sn.request_header, content='stuff=nope')
|
| 254 | + with self.assertRaises(MisComputedContentHash):
|
| 255 | + self.receive(sn.request_header, content='stuff=nope')
|
| 256 |
|
| 257 | def test_non_ascii_content(self):
|
| 258 | content = u'Ivan Kristi\u0107'
|
| 259 | sn = self.Sender(content=content)
|
| 260 | self.receive(sn.request_header, content=content)
|
| 261 |
|
| 262 | - @raises(MacMismatch)
|
| 263 | def test_tamper_with_content_type(self):
|
| 264 | sn = self.Sender(method='POST')
|
| 265 | - self.receive(sn.request_header, content_type='application/json')
|
| 266 | + with self.assertRaises(MacMismatch):
|
| 267 | + self.receive(sn.request_header, content_type='application/json')
|
| 268 |
|
| 269 | - @raises(AlreadyProcessed)
|
| 270 | def test_nonce_fail(self):
|
| 271 |
|
| 272 | def seen_nonce(id, nonce, ts):
|
| 273 | return True
|
| 274 |
|
| 275 | sn = self.Sender()
|
| 276 | -
|
| 277 | - self.receive(sn.request_header, seen_nonce=seen_nonce)
|
| 278 | + with self.assertRaises(AlreadyProcessed):
|
| 279 | + self.receive(sn.request_header, seen_nonce=seen_nonce)
|
| 280 |
|
| 281 | def test_nonce_ok(self):
|
| 282 |
|
| 283 | @@ -269,11 +266,11 @@ def seen_nonce(id, nonce, ts):
|
| 284 | sn = self.Sender(seen_nonce=seen_nonce)
|
| 285 | self.receive(sn.request_header)
|
| 286 |
|
| 287 | - @raises(TokenExpired)
|
| 288 | def test_expired_ts(self):
|
| 289 | now = utc_now() - 120
|
| 290 | sn = self.Sender(_timestamp=now)
|
| 291 | - self.receive(sn.request_header)
|
| 292 | + with self.assertRaises(TokenExpired):
|
| 293 | + self.receive(sn.request_header)
|
| 294 |
|
| 295 | def test_expired_exception_reports_localtime(self):
|
| 296 | now = utc_now()
|
| 297 | @@ -303,13 +300,12 @@ def test_localtime_skew(self):
|
| 298 | # Without an offset this will raise an expired exception.
|
| 299 | self.receive(sn.request_header, timestamp_skew_in_seconds=120)
|
| 300 |
|
| 301 | - @raises(MacMismatch)
|
| 302 | def test_hash_tampering(self):
|
| 303 | sn = self.Sender()
|
| 304 | header = sn.request_header.replace('hash="', 'hash="nope')
|
| 305 | - self.receive(header)
|
| 306 | + with self.assertRaises(MacMismatch):
|
| 307 | + self.receive(header)
|
| 308 |
|
| 309 | - @raises(MacMismatch)
|
| 310 | def test_bad_secret(self):
|
| 311 | cfg = {
|
| 312 | 'id': 'my-hawk-id',
|
| 313 | @@ -317,55 +313,56 @@ def test_bad_secret(self):
|
| 314 | 'algorithm': 'sha256',
|
| 315 | }
|
| 316 | sn = self.Sender(credentials=cfg)
|
| 317 | - self.receive(sn.request_header)
|
| 318 | + with self.assertRaises(MacMismatch):
|
| 319 | + self.receive(sn.request_header)
|
| 320 |
|
| 321 | - @raises(MacMismatch)
|
| 322 | def test_unexpected_algorithm(self):
|
| 323 | cr = self.credentials.copy()
|
| 324 | cr['algorithm'] = 'sha512'
|
| 325 | sn = self.Sender(credentials=cr)
|
| 326 |
|
| 327 | # Validate with mismatched credentials (sha256).
|
| 328 | - self.receive(sn.request_header)
|
| 329 | + with self.assertRaises(MacMismatch):
|
| 330 | + self.receive(sn.request_header)
|
| 331 |
|
| 332 | - @raises(InvalidCredentials)
|
| 333 | def test_invalid_credentials(self):
|
| 334 | cfg = self.credentials.copy()
|
| 335 | # Create an invalid credentials.
|
| 336 | del cfg['algorithm']
|
| 337 |
|
| 338 | - self.Sender(credentials=cfg)
|
| 339 | + with self.assertRaises(InvalidCredentials):
|
| 340 | + self.Sender(credentials=cfg)
|
| 341 |
|
| 342 | - @raises(CredentialsLookupError)
|
| 343 | def test_unknown_id(self):
|
| 344 | cr = self.credentials.copy()
|
| 345 | cr['id'] = 'someone-else'
|
| 346 | sn = self.Sender(credentials=cr)
|
| 347 |
|
| 348 | - self.receive(sn.request_header)
|
| 349 | + with self.assertRaises(CredentialsLookupError):
|
| 350 | + self.receive(sn.request_header)
|
| 351 |
|
| 352 | - @raises(MacMismatch)
|
| 353 | def test_bad_ext(self):
|
| 354 | sn = self.Sender(ext='my external data')
|
| 355 |
|
| 356 | header = sn.request_header.replace('my external data', 'TAMPERED')
|
| 357 | - self.receive(header)
|
| 358 | + with self.assertRaises(MacMismatch):
|
| 359 | + self.receive(header)
|
| 360 |
|
| 361 | - @raises(BadHeaderValue)
|
| 362 | def test_duplicate_keys(self):
|
| 363 | sn = self.Sender(ext='someext')
|
| 364 | header = sn.request_header + ', ext="otherext"'
|
| 365 | - self.receive(header)
|
| 366 | + with self.assertRaises(BadHeaderValue):
|
| 367 | + self.receive(header)
|
| 368 |
|
| 369 | - @raises(BadHeaderValue)
|
| 370 | def test_ext_with_quotes(self):
|
| 371 | - sn = self.Sender(ext='quotes=""')
|
| 372 | - self.receive(sn.request_header)
|
| 373 | + with self.assertRaises(BadHeaderValue):
|
| 374 | + sn = self.Sender(ext='quotes=""')
|
| 375 | + self.receive(sn.request_header)
|
| 376 |
|
| 377 | - @raises(BadHeaderValue)
|
| 378 | def test_ext_with_new_line(self):
|
| 379 | - sn = self.Sender(ext="new line \n in the middle")
|
| 380 | - self.receive(sn.request_header)
|
| 381 | + with self.assertRaises(BadHeaderValue):
|
| 382 | + sn = self.Sender(ext="new line \n in the middle")
|
| 383 | + self.receive(sn.request_header)
|
| 384 |
|
| 385 | def test_ext_with_equality_sign(self):
|
| 386 | sn = self.Sender(ext="foo=bar&foo2=bar2;foo3=bar3")
|
| 387 | @@ -373,13 +370,13 @@ def test_ext_with_equality_sign(self):
|
| 388 | parsed = parse_authorization_header(sn.request_header)
|
| 389 | assert parsed['ext'] == "foo=bar&foo2=bar2;foo3=bar3"
|
| 390 |
|
| 391 | - @raises(HawkFail)
|
| 392 | def test_non_hawk_scheme(self):
|
| 393 | - parse_authorization_header('Basic user:base64pw')
|
| 394 | + with self.assertRaises(HawkFail):
|
| 395 | + parse_authorization_header('Basic user:base64pw')
|
| 396 |
|
| 397 | - @raises(HawkFail)
|
| 398 | def test_invalid_key(self):
|
| 399 | - parse_authorization_header('Hawk mac="validmac" unknownkey="value"')
|
| 400 | + with self.assertRaises(HawkFail):
|
| 401 | + parse_authorization_header('Hawk mac="validmac" unknownkey="value"')
|
| 402 |
|
| 403 | def test_ext_with_all_valid_characters(self):
|
| 404 | valid_characters = "!#$%&'()*+,-./:;<=>?@[]^_`{|}~ azAZ09_"
|
| 405 | @@ -387,9 +384,9 @@ def test_ext_with_all_valid_characters(self):
|
| 406 | parsed = parse_authorization_header(sender.request_header)
|
| 407 | assert parsed['ext'] == valid_characters
|
| 408 |
|
| 409 | - @raises(BadHeaderValue)
|
| 410 | def test_ext_with_illegal_chars(self):
|
| 411 | - self.Sender(ext="something like \t is illegal")
|
| 412 | + with self.assertRaises(BadHeaderValue):
|
| 413 | + self.Sender(ext="something like \t is illegal")
|
| 414 |
|
| 415 | def test_unparseable_header(self):
|
| 416 | try:
|
| 417 | @@ -401,20 +398,20 @@ def test_unparseable_header(self):
|
| 418 | else:
|
| 419 | self.fail('should raise')
|
| 420 |
|
| 421 | - @raises(BadHeaderValue)
|
| 422 | def test_ext_with_illegal_unicode(self):
|
| 423 | - self.Sender(ext=u'Ivan Kristi\u0107')
|
| 424 | + with self.assertRaises(BadHeaderValue):
|
| 425 | + self.Sender(ext=u'Ivan Kristi\u0107')
|
| 426 |
|
| 427 | - @raises(BadHeaderValue)
|
| 428 | def test_too_long_header(self):
|
| 429 | sn = self.Sender(ext='a'*5000)
|
| 430 | - self.receive(sn.request_header)
|
| 431 | + with self.assertRaises(BadHeaderValue):
|
| 432 | + self.receive(sn.request_header)
|
| 433 |
|
| 434 | - @raises(BadHeaderValue)
|
| 435 | def test_ext_with_illegal_utf8(self):
|
| 436 | # This isn't allowed because the escaped byte chars are out of
|
| 437 | # range.
|
| 438 | - self.Sender(ext=u'Ivan Kristi\u0107'.encode('utf8'))
|
| 439 | + with self.assertRaises(BadHeaderValue):
|
| 440 | + self.Sender(ext=u'Ivan Kristi\u0107'.encode('utf8'))
|
| 441 |
|
| 442 | def test_app_ok(self):
|
| 443 | app = 'custom-app'
|
| 444 | @@ -423,12 +420,12 @@ def test_app_ok(self):
|
| 445 | parsed = parse_authorization_header(sn.request_header)
|
| 446 | assert parsed['app'] == app
|
| 447 |
|
| 448 | - @raises(MacMismatch)
|
| 449 | def test_tampered_app(self):
|
| 450 | app = 'custom-app'
|
| 451 | sn = self.Sender(app=app)
|
| 452 | header = sn.request_header.replace(app, 'TAMPERED-WITH')
|
| 453 | - self.receive(header)
|
| 454 | + with self.assertRaises(MacMismatch):
|
| 455 | + self.receive(header)
|
| 456 |
|
| 457 | def test_dlg_ok(self):
|
| 458 | dlg = 'custom-dlg'
|
| 459 | @@ -437,12 +434,12 @@ def test_dlg_ok(self):
|
| 460 | parsed = parse_authorization_header(sn.request_header)
|
| 461 | assert parsed['dlg'] == dlg
|
| 462 |
|
| 463 | - @raises(MacMismatch)
|
| 464 | def test_tampered_dlg(self):
|
| 465 | dlg = 'custom-dlg'
|
| 466 | sn = self.Sender(dlg=dlg, app='some-app')
|
| 467 | header = sn.request_header.replace(dlg, 'TAMPERED-WITH')
|
| 468 | - self.receive(header)
|
| 469 | + with self.assertRaises(MacMismatch):
|
| 470 | + self.receive(header)
|
| 471 |
|
| 472 | def test_file_content(self):
|
| 473 | method = "POST"
|
| 474 | @@ -456,12 +453,12 @@ def test_binary_file_content(self):
|
| 475 | sn = self.Sender(method, content=content)
|
| 476 | self.receive(sn.request_header, method=method, content=content.getvalue())
|
| 477 |
|
| 478 | - @raises(MisComputedContentHash)
|
| 479 | def test_bad_file_content(self):
|
| 480 | method = "POST"
|
| 481 | content = six.BytesIO(b"FILE CONTENT")
|
| 482 | sn = self.Sender(method, content=content)
|
| 483 | - self.receive(sn.request_header, method=method, content="BAD FILE CONTENT")
|
| 484 | + with self.assertRaises(MisComputedContentHash):
|
| 485 | + self.receive(sn.request_header, method=method, content="BAD FILE CONTENT")
|
| 486 |
|
| 487 |
|
| 488 | class TestReceiver(Base):
|
| 489 | @@ -508,10 +505,10 @@ def respond(self, **kw):
|
| 490 |
|
| 491 | return receiver.response_header
|
| 492 |
|
| 493 | - @raises(InvalidCredentials)
|
| 494 | def test_invalid_credentials_lookup(self):
|
| 495 | # Return invalid credentials.
|
| 496 | - self.receive(credentials_map=lambda *a: {})
|
| 497 | + with self.assertRaises(InvalidCredentials):
|
| 498 | + self.receive(credentials_map=lambda *a: {})
|
| 499 |
|
| 500 | def test_get_ok(self):
|
| 501 | method = 'GET'
|
| 502 | @@ -523,49 +520,49 @@ def test_post_ok(self):
|
| 503 | self.receive(method=method)
|
| 504 | self.respond()
|
| 505 |
|
| 506 | - @raises(MisComputedContentHash)
|
| 507 | def test_respond_with_wrong_content(self):
|
| 508 | self.receive()
|
| 509 | - self.respond(content='real content',
|
| 510 | - accept_kw=dict(content='TAMPERED WITH'))
|
| 511 | + with self.assertRaises(MisComputedContentHash):
|
| 512 | + self.respond(content='real content',
|
| 513 | + accept_kw=dict(content='TAMPERED WITH'))
|
| 514 |
|
| 515 | - @raises(MisComputedContentHash)
|
| 516 | def test_respond_with_wrong_content_type(self):
|
| 517 | self.receive()
|
| 518 | - self.respond(content_type='text/html',
|
| 519 | - accept_kw=dict(content_type='application/json'))
|
| 520 | + with self.assertRaises(MisComputedContentHash):
|
| 521 | + self.respond(content_type='text/html',
|
| 522 | + accept_kw=dict(content_type='application/json'))
|
| 523 |
|
| 524 | - @raises(MissingAuthorization)
|
| 525 | def test_missing_authorization(self):
|
| 526 | - Receiver(lambda id: self.credentials, None, '/', 'GET')
|
| 527 | + with self.assertRaises(MissingAuthorization):
|
| 528 | + Receiver(lambda id: self.credentials, None, '/', 'GET')
|
| 529 |
|
| 530 | - @raises(MacMismatch)
|
| 531 | def test_respond_with_wrong_url(self):
|
| 532 | - self.receive(url='http://fakesite.com')
|
| 533 | - wrong_receiver = self.receiver
|
| 534 | + with self.assertRaises(MacMismatch):
|
| 535 | + self.receive(url='http://fakesite.com')
|
| 536 | + wrong_receiver = self.receiver
|
| 537 |
|
| 538 | - self.receive(url='http://realsite.com')
|
| 539 | + self.receive(url='http://realsite.com')
|
| 540 |
|
| 541 | - self.respond(receiver=wrong_receiver)
|
| 542 | + self.respond(receiver=wrong_receiver)
|
| 543 |
|
| 544 | - @raises(MacMismatch)
|
| 545 | def test_respond_with_wrong_method(self):
|
| 546 | - self.receive(method='GET')
|
| 547 | - wrong_receiver = self.receiver
|
| 548 | + with self.assertRaises(MacMismatch):
|
| 549 | + self.receive(method='GET')
|
| 550 | + wrong_receiver = self.receiver
|
| 551 |
|
| 552 | - self.receive(method='POST')
|
| 553 | + self.receive(method='POST')
|
| 554 |
|
| 555 | - self.respond(receiver=wrong_receiver)
|
| 556 | + self.respond(receiver=wrong_receiver)
|
| 557 |
|
| 558 | - @raises(MacMismatch)
|
| 559 | def test_respond_with_wrong_nonce(self):
|
| 560 | - self.receive(sender_kw=dict(nonce='another-nonce'))
|
| 561 | - wrong_receiver = self.receiver
|
| 562 | + with self.assertRaises(MacMismatch):
|
| 563 | + self.receive(sender_kw=dict(nonce='another-nonce'))
|
| 564 | + wrong_receiver = self.receiver
|
| 565 |
|
| 566 | - self.receive()
|
| 567 | + self.receive()
|
| 568 |
|
| 569 | - # The nonce must match the one sent in the original request.
|
| 570 | - self.respond(receiver=wrong_receiver)
|
| 571 | + # The nonce must match the one sent in the original request.
|
| 572 | + self.respond(receiver=wrong_receiver)
|
| 573 |
|
| 574 | def test_respond_with_unhashed_content(self):
|
| 575 | self.receive()
|
| 576 | @@ -574,23 +571,23 @@ def test_respond_with_unhashed_content(self):
|
| 577 | content_type=None,
|
| 578 | accept_kw=dict(accept_untrusted_content=True))
|
| 579 |
|
| 580 | - @raises(TokenExpired)
|
| 581 | def test_respond_with_expired_ts(self):
|
| 582 | self.receive()
|
| 583 | hdr = self.receiver.respond(content='', content_type='')
|
| 584 |
|
| 585 | - with mock.patch('mohawk.base.utc_now') as fn:
|
| 586 | - fn.return_value = 0 # force an expiry
|
| 587 | - try:
|
| 588 | - self.sender.accept_response(hdr, content='', content_type='')
|
| 589 | - except TokenExpired:
|
| 590 | - etype, exc, tb = sys.exc_info()
|
| 591 | - hdr = parse_authorization_header(exc.www_authenticate)
|
| 592 | - calculated = calculate_ts_mac(fn(), self.credentials)
|
| 593 | - if isinstance(calculated, six.binary_type):
|
| 594 | - calculated = calculated.decode('ascii')
|
| 595 | - assert hdr['tsm'] == calculated
|
| 596 | - raise
|
| 597 | + with self.assertRaises(TokenExpired):
|
| 598 | + with mock.patch('mohawk.base.utc_now') as fn:
|
| 599 | + fn.return_value = 0 # force an expiry
|
| 600 | + try:
|
| 601 | + self.sender.accept_response(hdr, content='', content_type='')
|
| 602 | + except TokenExpired:
|
| 603 | + etype, exc, tb = sys.exc_info()
|
| 604 | + hdr = parse_authorization_header(exc.www_authenticate)
|
| 605 | + calculated = calculate_ts_mac(fn(), self.credentials)
|
| 606 | + if isinstance(calculated, six.binary_type):
|
| 607 | + calculated = calculated.decode('ascii')
|
| 608 | + assert hdr['tsm'] == calculated
|
| 609 | + raise
|
| 610 |
|
| 611 | def test_respond_with_bad_ts_skew_ok(self):
|
| 612 | now = utc_now() - 120
|
| 613 | @@ -613,7 +610,6 @@ def test_respond_with_ext(self):
|
| 614 | header = parse_authorization_header(self.receiver.response_header)
|
| 615 | assert header['ext'] == ext
|
| 616 |
|
| 617 | - @raises(MacMismatch)
|
| 618 | def test_respond_with_wrong_app(self):
|
| 619 | self.receive(sender_kw=dict(app='TAMPERED-WITH', dlg='delegation'))
|
| 620 | self.receiver.respond(content='', content_type='')
|
| 621 | @@ -621,10 +617,10 @@ def test_respond_with_wrong_app(self):
|
| 622 |
|
| 623 | self.receive(sender_kw=dict(app='real-app', dlg='delegation'))
|
| 624 |
|
| 625 | - self.sender.accept_response(wrong_receiver.response_header,
|
| 626 | - content='', content_type='')
|
| 627 | + with self.assertRaises(MacMismatch):
|
| 628 | + self.sender.accept_response(wrong_receiver.response_header,
|
| 629 | + content='', content_type='')
|
| 630 |
|
| 631 | - @raises(MacMismatch)
|
| 632 | def test_respond_with_wrong_dlg(self):
|
| 633 | self.receive(sender_kw=dict(app='app', dlg='TAMPERED-WITH'))
|
| 634 | self.receiver.respond(content='', content_type='')
|
| 635 | @@ -632,27 +628,28 @@ def test_respond_with_wrong_dlg(self):
|
| 636 |
|
| 637 | self.receive(sender_kw=dict(app='app', dlg='real-dlg'))
|
| 638 |
|
| 639 | - self.sender.accept_response(wrong_receiver.response_header,
|
| 640 | - content='', content_type='')
|
| 641 | + with self.assertRaises(MacMismatch):
|
| 642 | + self.sender.accept_response(wrong_receiver.response_header,
|
| 643 | + content='', content_type='')
|
| 644 |
|
| 645 | - @raises(MacMismatch)
|
| 646 | def test_receive_wrong_method(self):
|
| 647 | self.receive(method='GET')
|
| 648 | wrong_sender = self.sender
|
| 649 | - self.receive(method='POST', sender=wrong_sender)
|
| 650 | + with self.assertRaises(MacMismatch):
|
| 651 | + self.receive(method='POST', sender=wrong_sender)
|
| 652 |
|
| 653 | - @raises(MacMismatch)
|
| 654 | def test_receive_wrong_url(self):
|
| 655 | self.receive(url='http://fakesite.com/')
|
| 656 | wrong_sender = self.sender
|
| 657 | - self.receive(url='http://realsite.com/', sender=wrong_sender)
|
| 658 | + with self.assertRaises(MacMismatch):
|
| 659 | + self.receive(url='http://realsite.com/', sender=wrong_sender)
|
| 660 |
|
| 661 | - @raises(MisComputedContentHash)
|
| 662 | def test_receive_wrong_content(self):
|
| 663 | self.receive(sender_kw=dict(content='real request'),
|
| 664 | content='real request')
|
| 665 | wrong_sender = self.sender
|
| 666 | - self.receive(content='TAMPERED WITH', sender=wrong_sender)
|
| 667 | + with self.assertRaises(MisComputedContentHash):
|
| 668 | + self.receive(content='TAMPERED WITH', sender=wrong_sender)
|
| 669 |
|
| 670 | def test_expected_unhashed_empty_content(self):
|
| 671 | # This test sets up a scenario where the receiver will receive empty
|
| 672 | @@ -669,7 +666,6 @@ def test_expected_unhashed_empty_content(self):
|
| 673 | content_type=EmptyValue,
|
| 674 | always_hash_content=False))
|
| 675 |
|
| 676 | - @raises(MisComputedContentHash)
|
| 677 | def test_expected_unhashed_empty_content_with_content_type(self):
|
| 678 | # This test sets up a scenario where the receiver will receive an
|
| 679 | # empty content string and no content hash in the auth header, but
|
| 680 | @@ -677,13 +673,13 @@ def test_expected_unhashed_empty_content_with_content_type(self):
|
| 681 | # This is to confirm that the hash is calculated and compared (to the
|
| 682 | # hash of mock empty payload, which should fail) when it appears that
|
| 683 | # the sender has sent a 0-length payload body.
|
| 684 | - self.receive(content='',
|
| 685 | - content_type='text/plain',
|
| 686 | - sender_kw=dict(content=EmptyValue,
|
| 687 | - content_type=EmptyValue,
|
| 688 | - always_hash_content=False))
|
| 689 | + with self.assertRaises(MisComputedContentHash):
|
| 690 | + self.receive(content='',
|
| 691 | + content_type='text/plain',
|
| 692 | + sender_kw=dict(content=EmptyValue,
|
| 693 | + content_type=EmptyValue,
|
| 694 | + always_hash_content=False))
|
| 695 |
|
| 696 | - @raises(MisComputedContentHash)
|
| 697 | def test_expected_unhashed_content_with_empty_content_type(self):
|
| 698 | # This test sets up a scenario where the receiver will receive some
|
| 699 | # content but the empty string for the content_type and no content hash
|
| 700 | @@ -691,11 +687,12 @@ def test_expected_unhashed_content_with_empty_content_type(self):
|
| 701 | # This is to confirm that the hash is calculated and compared (to the
|
| 702 | # hash of mock empty payload, which should fail) when the sender has
|
| 703 | # sent unhashed content.
|
| 704 | - self.receive(content='some content',
|
| 705 | - content_type='',
|
| 706 | - sender_kw=dict(content=EmptyValue,
|
| 707 | - content_type=EmptyValue,
|
| 708 | - always_hash_content=False))
|
| 709 | + with self.assertRaises(MisComputedContentHash):
|
| 710 | + self.receive(content='some content',
|
| 711 | + content_type='',
|
| 712 | + sender_kw=dict(content=EmptyValue,
|
| 713 | + content_type=EmptyValue,
|
| 714 | + always_hash_content=False))
|
| 715 |
|
| 716 | def test_empty_content_with_content_type(self):
|
| 717 | # This test sets up a scenario where the receiver will receive an
|
| 718 | @@ -719,7 +716,6 @@ def test_expected_unhashed_no_content(self):
|
| 719 | content_type=EmptyValue,
|
| 720 | always_hash_content=False))
|
| 721 |
|
| 722 | - @raises(MisComputedContentHash)
|
| 723 | def test_expected_unhashed_no_content_with_content_type(self):
|
| 724 | # This test sets up a scenario where the receiver will receive None for
|
| 725 | # content and no content hash in the auth header, but some value for
|
| 726 | @@ -729,13 +725,13 @@ def test_expected_unhashed_no_content_with_content_type(self):
|
| 727 | # hash in the request to compare against. While this may not be in
|
| 728 | # accordance with the js reference spec, it's the safest (ie. most
|
| 729 | # secure) way of handling this bizarre set of circumstances.
|
| 730 | - self.receive(content=None,
|
| 731 | - content_type='text/plain',
|
| 732 | - sender_kw=dict(content=EmptyValue,
|
| 733 | - content_type=EmptyValue,
|
| 734 | - always_hash_content=False))
|
| 735 | + with self.assertRaises(MisComputedContentHash):
|
| 736 | + self.receive(content=None,
|
| 737 | + content_type='text/plain',
|
| 738 | + sender_kw=dict(content=EmptyValue,
|
| 739 | + content_type=EmptyValue,
|
| 740 | + always_hash_content=False))
|
| 741 |
|
| 742 | - @raises(MisComputedContentHash)
|
| 743 | def test_expected_unhashed_content_with_no_content_type(self):
|
| 744 | # This test sets up a scenario where the receiver will receive some
|
| 745 | # content but no value for the content_type and no content hash in
|
| 746 | @@ -743,11 +739,12 @@ def test_expected_unhashed_content_with_no_content_type(self):
|
| 747 | # This is to confirm that the hash is calculated and compared (to the
|
| 748 | # hash of mock empty payload, which should fail) when the sender has
|
| 749 | # sent unhashed content.
|
| 750 | - self.receive(content='some content',
|
| 751 | - content_type=None,
|
| 752 | - sender_kw=dict(content=EmptyValue,
|
| 753 | - content_type=EmptyValue,
|
| 754 | - always_hash_content=False))
|
| 755 | + with self.assertRaises(MisComputedContentHash):
|
| 756 | + self.receive(content='some content',
|
| 757 | + content_type=None,
|
| 758 | + sender_kw=dict(content=EmptyValue,
|
| 759 | + content_type=EmptyValue,
|
| 760 | + always_hash_content=False))
|
| 761 |
|
| 762 | def test_no_content_with_content_type(self):
|
| 763 | # This test sets up a scenario where the receiver will receive None for
|
| 764 | @@ -760,28 +757,28 @@ def test_no_content_with_content_type(self):
|
| 765 | sender_kw=dict(content='',
|
| 766 | content_type='text/plain'))
|
| 767 |
|
| 768 | - @raises(MissingContent)
|
| 769 | def test_cannot_receive_empty_content_only(self):
|
| 770 | content_type = 'text/plain'
|
| 771 | - self.receive(sender_kw=dict(content='<content>',
|
| 772 | - content_type=content_type),
|
| 773 | - content=EmptyValue, content_type=content_type)
|
| 774 | + with self.assertRaises(MissingContent):
|
| 775 | + self.receive(sender_kw=dict(content='<content>',
|
| 776 | + content_type=content_type),
|
| 777 | + content=EmptyValue, content_type=content_type)
|
| 778 |
|
| 779 | - @raises(MissingContent)
|
| 780 | def test_cannot_receive_empty_content_type_only(self):
|
| 781 | content = '<content>'
|
| 782 | - self.receive(sender_kw=dict(content=content,
|
| 783 | - content_type='text/plain'),
|
| 784 | - content=content, content_type=EmptyValue)
|
| 785 | + with self.assertRaises(MissingContent):
|
| 786 | + self.receive(sender_kw=dict(content=content,
|
| 787 | + content_type='text/plain'),
|
| 788 | + content=content, content_type=EmptyValue)
|
| 789 |
|
| 790 | - @raises(MisComputedContentHash)
|
| 791 | def test_receive_wrong_content_type(self):
|
| 792 | self.receive(sender_kw=dict(content_type='text/html'),
|
| 793 | content_type='text/html')
|
| 794 | wrong_sender = self.sender
|
| 795 |
|
| 796 | - self.receive(content_type='application/json',
|
| 797 | - sender=wrong_sender)
|
| 798 | + with self.assertRaises(MisComputedContentHash):
|
| 799 | + self.receive(content_type='application/json',
|
| 800 | + sender=wrong_sender)
|
| 801 |
|
| 802 |
|
| 803 | class TestSendAndReceive(Base):
|
| 804 | @@ -879,24 +876,24 @@ def test_bewit_with_ext(self):
|
| 805 | expected = '123456\\1356420707\\kscxwNR2tJpP1T1zDLNPbB5UiKIU9tOSJXTUdG7X9h8=\\xandyandz'
|
| 806 | assert b64decode(bewit).decode('ascii') == expected
|
| 807 |
|
| 808 | - @raises(BadHeaderValue)
|
| 809 | def test_bewit_with_invalid_ext(self):
|
| 810 | res = Resource(url='https://example.com/somewhere/over/the/rainbow',
|
| 811 | method='GET', credentials=self.credentials,
|
| 812 | timestamp=1356420407 + 300,
|
| 813 | nonce='',
|
| 814 | ext='xand\\yandz')
|
| 815 | - get_bewit(res)
|
| 816 | + with self.assertRaises(BadHeaderValue):
|
| 817 | + get_bewit(res)
|
| 818 |
|
| 819 | - @raises(BadHeaderValue)
|
| 820 | def test_bewit_with_backslashes_in_id(self):
|
| 821 | credentials = self.credentials
|
| 822 | credentials['id'] = '123\\456'
|
| 823 | - res = Resource(url='https://example.com/somewhere/over/the/rainbow',
|
| 824 | - method='GET', credentials=self.credentials,
|
| 825 | - timestamp=1356420407 + 300,
|
| 826 | - nonce='')
|
| 827 | - get_bewit(res)
|
| 828 | + with self.assertRaises(BadHeaderValue):
|
| 829 | + res = Resource(url='https://example.com/somewhere/over/the/rainbow',
|
| 830 | + method='GET', credentials=self.credentials,
|
| 831 | + timestamp=1356420407 + 300,
|
| 832 | + nonce='')
|
| 833 | + get_bewit(res)
|
| 834 |
|
| 835 | def test_bewit_with_port(self):
|
| 836 | res = Resource(url='https://example.com:8080/somewhere/over/the/rainbow',
|
| 837 | @@ -907,20 +904,20 @@ def test_bewit_with_port(self):
|
| 838 | expected = '123456\\1356420707\\hZbJ3P2cKEo4ky0C8jkZAkRyCZueg4WSNbxV7vq3xHU=\\xandyandz'
|
| 839 | assert b64decode(bewit).decode('ascii') == expected
|
| 840 |
|
| 841 | - @raises(ValueError)
|
| 842 | def test_bewit_with_nonce(self):
|
| 843 | res = Resource(url='https://example.com/somewhere/over/the/rainbow',
|
| 844 | method='GET', credentials=self.credentials,
|
| 845 | timestamp=1356420407 + 300,
|
| 846 | nonce='n1')
|
| 847 | - get_bewit(res)
|
| 848 | + with self.assertRaises(ValueError):
|
| 849 | + get_bewit(res)
|
| 850 |
|
| 851 | - @raises(ValueError)
|
| 852 | def test_bewit_invalid_method(self):
|
| 853 | res = Resource(url='https://example.com:8080/somewhere/over/the/rainbow',
|
| 854 | method='POST', credentials=self.credentials,
|
| 855 | timestamp=1356420407 + 300, nonce='')
|
| 856 | - get_bewit(res)
|
| 857 | + with self.assertRaises(ValueError):
|
| 858 | + get_bewit(res)
|
| 859 |
|
| 860 | def test_strip_bewit(self):
|
| 861 | bewit = b'123456\\1356420707\\IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=\\'
|
| 862 | @@ -931,10 +928,10 @@ def test_strip_bewit(self):
|
| 863 | self.assertEqual(raw_bewit, bewit)
|
| 864 | self.assertEqual(stripped_url, "https://example.com/somewhere/over/the/rainbow")
|
| 865 |
|
| 866 | - @raises(InvalidBewit)
|
| 867 | def test_strip_url_without_bewit(self):
|
| 868 | url = "https://example.com/somewhere/over/the/rainbow"
|
| 869 | - strip_bewit(url)
|
| 870 | + with self.assertRaises(InvalidBewit):
|
| 871 | + strip_bewit(url)
|
| 872 |
|
| 873 | def test_parse_bewit(self):
|
| 874 | bewit = b'123456\\1356420707\\IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=\\'
|
| 875 | @@ -954,23 +951,23 @@ def test_parse_bewit_with_ext(self):
|
| 876 | self.assertEqual(bewit.mac, 'IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=')
|
| 877 | self.assertEqual(bewit.ext, 'xandyandz')
|
| 878 |
|
| 879 | - @raises(InvalidBewit)
|
| 880 | def test_parse_bewit_with_ext_and_backslashes(self):
|
| 881 | bewit = b'123456\\1356420707\\IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=\\xand\\yandz'
|
| 882 | bewit = urlsafe_b64encode(bewit).decode('ascii')
|
| 883 | - parse_bewit(bewit)
|
| 884 | + with self.assertRaises(InvalidBewit):
|
| 885 | + parse_bewit(bewit)
|
| 886 |
|
| 887 | - @raises(InvalidBewit)
|
| 888 | def test_parse_invalid_bewit_with_only_one_part(self):
|
| 889 | bewit = b'12345'
|
| 890 | bewit = urlsafe_b64encode(bewit).decode('ascii')
|
| 891 | - bewit = parse_bewit(bewit)
|
| 892 | + with self.assertRaises(InvalidBewit):
|
| 893 | + bewit = parse_bewit(bewit)
|
| 894 |
|
| 895 | - @raises(InvalidBewit)
|
| 896 | def test_parse_invalid_bewit_with_only_two_parts(self):
|
| 897 | bewit = b'1\\2'
|
| 898 | bewit = urlsafe_b64encode(bewit).decode('ascii')
|
| 899 | - bewit = parse_bewit(bewit)
|
| 900 | + with self.assertRaises(InvalidBewit):
|
| 901 | + bewit = parse_bewit(bewit)
|
| 902 |
|
| 903 | def test_validate_bewit(self):
|
| 904 | bewit = b'123456\\1356420707\\IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=\\'
|
| 905 | @@ -990,7 +987,6 @@ def test_validate_bewit_with_ext(self):
|
| 906 | })
|
| 907 | self.assertTrue(check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 10))
|
| 908 |
|
| 909 | - @raises(InvalidBewit)
|
| 910 | def test_validate_bewit_with_ext_and_backslashes(self):
|
| 911 | bewit = b'123456\\1356420707\\b82LLIxG5UDkaChLU953mC+SMrbniV1sb8KiZi9cSsc=\\xand\\yandz'
|
| 912 | bewit = urlsafe_b64encode(bewit).decode('ascii')
|
| 913 | @@ -998,9 +994,9 @@ def test_validate_bewit_with_ext_and_backslashes(self):
|
| 914 | credential_lookup = self.make_credential_lookup({
|
| 915 | self.credentials['id']: self.credentials,
|
| 916 | })
|
| 917 | - check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 10)
|
| 918 | + with self.assertRaises(InvalidBewit):
|
| 919 | + check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 10)
|
| 920 |
|
| 921 | - @raises(TokenExpired)
|
| 922 | def test_validate_expired_bewit(self):
|
| 923 | bewit = b'123456\\1356420707\\IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=\\'
|
| 924 | bewit = urlsafe_b64encode(bewit).decode('ascii')
|
| 925 | @@ -1008,9 +1004,9 @@ def test_validate_expired_bewit(self):
|
| 926 | credential_lookup = self.make_credential_lookup({
|
| 927 | self.credentials['id']: self.credentials,
|
| 928 | })
|
| 929 | - check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 1000)
|
| 930 | + with self.assertRaises(TokenExpired):
|
| 931 | + check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 1000)
|
| 932 |
|
| 933 | - @raises(CredentialsLookupError)
|
| 934 | def test_validate_bewit_with_unknown_credentials(self):
|
| 935 | bewit = b'123456\\1356420707\\IGYmLgIqLrCe8CxvKPs4JlWIA+UjWJJouwgARiVhCAg=\\'
|
| 936 | bewit = urlsafe_b64encode(bewit).decode('ascii')
|
| 937 | @@ -1018,7 +1014,8 @@ def test_validate_bewit_with_unknown_credentials(self):
|
| 938 | credential_lookup = self.make_credential_lookup({
|
| 939 | 'other_id': self.credentials,
|
| 940 | })
|
| 941 | - check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 10)
|
| 942 | + with self.assertRaises(CredentialsLookupError):
|
| 943 | + check_bewit(url, credential_lookup=credential_lookup, now=1356420407 + 10)
|
| 944 |
|
| 945 |
|
| 946 | class TestPayloadHash(Base):
|
| 947 |
|
| 948 | From e5ea6c8b0fad6a4b2e575c4f4ff669b9ac775fad Mon Sep 17 00:00:00 2001
|
| 949 | From: Pyrox <[email protected]>
|
| 950 | Date: Fri, 2 Aug 2024 15:20:41 -0400
|
| 951 | Subject: [PATCH 3/4] update dependencies
|
| 952 |
|
| 953 | ---
|
| 954 | requirements/dev.txt | 4 ++--
|
| 955 | 1 file changed, 2 insertions(+), 2 deletions(-)
|
| 956 |
|
| 957 | diff --git a/requirements/dev.txt b/requirements/dev.txt
|
| 958 | index 5636a39..4fa2e67 100644
|
| 959 | |
| 960 | |
| 961 | @@ -1,6 +1,6 @@
|
| 962 | # For testing.
|
| 963 | -mock >= 3.0.5
|
| 964 | -nose >= 1.3.7
|
| 965 | +mock >= 3.0.5; python_version < '3'
|
| 966 | +pytest >=8.0.0
|
| 967 |
|
| 968 | # For documentation.
|
| 969 | docutils >= 0.15.2
|
| 970 |
|
| 971 | From 1788cdfc47273d18c0624bca9bb543f9a88a22e2 Mon Sep 17 00:00:00 2001
|
| 972 | From: Pyrox <[email protected]>
|
| 973 | Date: Fri, 2 Aug 2024 15:20:47 -0400
|
| 974 | Subject: [PATCH 4/4] update supported python versions
|
| 975 |
|
| 976 | ---
|
| 977 | setup.py | 5 +++++
|
| 978 | tox.ini | 4 ++--
|
| 979 | 2 files changed, 7 insertions(+), 2 deletions(-)
|
| 980 |
|
| 981 | diff --git a/setup.py b/setup.py
|
| 982 | index 122bb36..53617b1 100644
|
| 983 | |
| 984 | |
| 985 | @@ -33,6 +33,11 @@
|
| 986 | 'Programming Language :: Python :: 3.5',
|
| 987 | 'Programming Language :: Python :: 3.6',
|
| 988 | 'Programming Language :: Python :: 3.7',
|
| 989 | + 'Programming Language :: Python :: 3.8',
|
| 990 | + 'Programming Language :: Python :: 3.9',
|
| 991 | + 'Programming Language :: Python :: 3.10',
|
| 992 | + 'Programming Language :: Python :: 3.11',
|
| 993 | + 'Programming Language :: Python :: 3.12',
|
| 994 | 'Topic :: Internet :: WWW/HTTP',
|
| 995 | ],
|
| 996 | packages=find_packages(exclude=['tests']),
|
| 997 | diff --git a/tox.ini b/tox.ini
|
| 998 | index 7357100..3fdeacf 100644
|
| 999 | |
| 1000 | |
| 1001 | @@ -2,7 +2,7 @@
|
| 1002 |
|
| 1003 | [tox]
|
| 1004 | # Also see .travis.yml where this is maintained separately.
|
| 1005 | -envlist=py27,py34,py35,py36,py37,py38,docs
|
| 1006 | +envlist=py27,py34,py35,py36,py37,py38,py39,py310,py311,py312,docs
|
| 1007 |
|
| 1008 | [base]
|
| 1009 | deps=
|
| 1010 | @@ -11,7 +11,7 @@ deps=
|
| 1011 | [testenv]
|
| 1012 | deps={[base]deps}
|
| 1013 | commands=
|
| 1014 | - nosetests []
|
| 1015 | + pytest mohawk/tests.py
|
| 1016 |
|
| 1017 | [testenv:docs]
|
| 1018 | basepython=python3.7
|