Skip to content

Commit

Permalink
Raise ValueError if BasicAuth login has a ":" (#1307)
Browse files Browse the repository at this point in the history
  • Loading branch information
kawadia authored and asvetlov committed Oct 13, 2016
1 parent 63a0d5c commit 1d47bf7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -231,3 +231,5 @@ CHANGES
domains (BACKWARD INCOMPATIBLE) #1125

- Support binary Content-Transfer-Encoding #1169

- Raise ValueError if BasicAuth login has a ":"
1 change: 1 addition & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,4 @@ Yusuke Tsutsumi
Семён Марьясин
Pau Freixes
Alexey Firsov
Vikas Kawadia
4 changes: 4 additions & 0 deletions aiohttp/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def __new__(cls, login, password='', encoding='latin1'):
if password is None:
raise ValueError('None is not allowed as password value')

if ':' in login:
raise ValueError(
'A ":" is not allowed in login (RFC 1945#section-11.1)')

return super().__new__(cls, login, password, encoding)

@classmethod
Expand Down
5 changes: 5 additions & 0 deletions tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ def test_basic_auth2():
helpers.BasicAuth('nkim', None)


def test_basic_with_auth_colon_in_login():
with pytest.raises(ValueError):
helpers.BasicAuth('nkim:1', 'pwd')


def test_basic_auth3():
auth = helpers.BasicAuth('nkim')
assert auth.login == 'nkim'
Expand Down

0 comments on commit 1d47bf7

Please sign in to comment.