|
| 1 | +import base64 |
1 | 2 | import pytest |
2 | 3 |
|
3 | 4 | from httoop.exceptions import InvalidHeader |
@@ -27,7 +28,28 @@ def test_basic_authorization(headers): |
27 | 28 | assert elem.password == 'test' |
28 | 29 |
|
29 | 30 |
|
30 | | -@pytest.mark.parametrize('invalid', [b'foo', b'Zm9v', 'föo'.encode('latin1')]) |
| 31 | +@pytest.mark.parametrize('invalid,username,password', [ |
| 32 | + (base64.b64encode(b'username:pass:word'), b'username', b'pass:word'), |
| 33 | + (base64.b64encode(b'username:'), b'username', b''), |
| 34 | + (base64.b64encode(b'user\nname:password'), b'user\nname', b'password'), |
| 35 | + (base64.b64encode(b'username:pass\nword'), b'username', b'pass\nword'), |
| 36 | + # TODO: different encodings |
| 37 | +]) |
| 38 | +def test_valid_headers(headers, invalid, username, password): |
| 39 | + headers.parse(b'Authorization: Basic %s' % (invalid,)) |
| 40 | + elem = headers.element('Authorization') |
| 41 | + assert elem.params['username'] == username |
| 42 | + assert elem.params['password'] == password |
| 43 | + headers.clear() |
| 44 | + |
| 45 | + |
| 46 | +@pytest.mark.parametrize('invalid', [ |
| 47 | + b'foo', |
| 48 | + b'Zm9v', |
| 49 | + 'föo'.encode('latin1'), |
| 50 | + base64.b64encode(b':password'), |
| 51 | + base64.b64encode(b'username:password')+b'"$"_' |
| 52 | +]) |
31 | 53 | def test_invalid_headers(headers, invalid): |
32 | 54 | headers.parse(b'Authorization: Basic %s' % (invalid,)) |
33 | 55 | with pytest.raises(InvalidHeader): |
|
0 commit comments