Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove domain parsing for UPN-formatted names #89

Merged
merged 1 commit into from
Dec 19, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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