Skip to content

Commit

Permalink
Merge pull request #89 from nitzmahone/no_parse_upn
Browse files Browse the repository at this point in the history
Remove domain parsing for UPN-formatted names
  • Loading branch information
Lukasa authored Dec 19, 2016
2 parents b04ed00 + c5e45fc commit 9708c3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 4 additions & 6 deletions requests_ntlm/requests_ntlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,11 @@ def __init__(self, username, password, session=None):
try:
self.domain, self.username = username.split('\\', 1)
except ValueError:
try:
self.username, self.domain = username.split('@', 1)
except ValueError:
self.username = username
self.domain = '.'
self.username = username
self.domain = ''

self.domain = self.domain.upper()
if self.domain:
self.domain = self.domain.upper()
self.password = password

# This exposes the encrypt/decrypt methods used to encrypt and decrypt messages
Expand Down
10 changes: 6 additions & 4 deletions tests/unit/test_requests_ntlm.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ def test_username_parse_backslash(self):
assert actual_user == expected_user

def test_username_parse_at(self):
test_user = 'user@domain'
expected_domain = 'DOMAIN'
expected_user = 'user'
test_user = 'user@domain.com'
# UPN format should not be split, since "stuff after @" not always == domain
# (eg, email address with alt UPN suffix)
expected_domain = ''
expected_user = 'user@domain.com'

context = requests_ntlm.HttpNtlmAuth(test_user, 'pass')

Expand All @@ -67,7 +69,7 @@ def test_username_parse_at(self):

def test_username_parse_no_domain(self):
test_user = 'user'
expected_domain = '.'
expected_domain = ''
expected_user = 'user'

context = requests_ntlm.HttpNtlmAuth(test_user, 'pass')
Expand Down

0 comments on commit 9708c3b

Please sign in to comment.