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

Added Microsoft Authenticator specific exceptions along with tests. #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions lastpass/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ class LastPassIncorrectGoogleAuthenticatorCodeError(Error):
pass


class LastPassIncorrectMicrosoftAuthenticatorCodeError(Error):
"""LastPass error: missing or incorrect Microsoft Authenticator code"""
pass


class LastPassIncorrectYubikeyPasswordError(Error):
"""LastPass error: missing or incorrect Yubikey password"""
pass
Expand Down
3 changes: 3 additions & 0 deletions lastpass/fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
LastPassUnknownUsernameError,
LastPassInvalidPasswordError,
LastPassIncorrectGoogleAuthenticatorCodeError,
LastPassIncorrectMicrosoftAuthenticatorCodeError,
LastPassIncorrectYubikeyPasswordError,
LastPassUnknownError
)
Expand Down Expand Up @@ -120,6 +121,8 @@ def login_error(parsed_response):
"unknownpassword": LastPassInvalidPasswordError,
"googleauthrequired": LastPassIncorrectGoogleAuthenticatorCodeError,
"googleauthfailed": LastPassIncorrectGoogleAuthenticatorCodeError,
"microsoftauthrequired": LastPassIncorrectMicrosoftAuthenticatorCodeError,
"microsoftauthfailed": LastPassIncorrectMicrosoftAuthenticatorCodeError,
"yubikeyrestricted": LastPassIncorrectYubikeyPasswordError,
}

Expand Down
20 changes: 20 additions & 0 deletions tests/test_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ def setUp(self):
self.login_post_data_with_device_id.update({'imei': self.device_id})

self.google_authenticator_code = '12345'
self.microsoft_authenticator_code = '12345'
self.yubikey_password = 'emdbwzemyisymdnevznyqhqnklaqheaxszzvtnxjrmkb'

self.login_post_data_with_google_authenticator_code = self.login_post_data.copy()
self.login_post_data_with_google_authenticator_code['otp'] = self.google_authenticator_code

self.login_post_data_with_microsoft_authenticator_code = self.login_post_data.copy()
self.login_post_data_with_microsoft_authenticator_code['otp'] = self.microsoft_authenticator_code

self.login_post_data_with_yubikey_password = self.login_post_data.copy()
self.login_post_data_with_yubikey_password['otp'] = self.yubikey_password

Expand Down Expand Up @@ -100,6 +104,11 @@ def test_request_login_makes_a_post_request_with_google_authenticator_code(self)
None,
self.login_post_data_with_google_authenticator_code)

def test_request_login_makes_a_post_request_with_microsoft_authenticator_code(self):
self._verify_request_login_post_request(self.microsoft_authenticator_code,
None,
self.login_post_data_with_microsoft_authenticator_code)

def test_request_login_makes_a_post_request_with_yubikey_password(self):
self._verify_request_login_post_request(self.yubikey_password,
None,
Expand Down Expand Up @@ -143,6 +152,17 @@ def test_request_login_raises_an_exception_on_incorrect_google_authenticator_cod
self.assertRaises(lastpass.LastPassIncorrectGoogleAuthenticatorCodeError,
self._request_login_with_lastpass_error, 'googleauthfailed', message)

def test_request_login_raises_an_exception_on_missing_microsoft_authenticator_code(self):
message = 'Microsoft Authenticator authentication required! ' \
'Upgrade your browser extension so you can enter it.'
self.assertRaises(lastpass.LastPassIncorrectMicrosoftAuthenticatorCodeError,
self._request_login_with_lastpass_error, 'microsoftauthrequired', message)

def test_request_login_raises_an_exception_on_incorrect_microsoft_authenticator_code(self):
message = 'Microsoft Authenticator authentication failed!'
self.assertRaises(lastpass.LastPassIncorrectMicrosoftAuthenticatorCodeError,
self._request_login_with_lastpass_error, 'microsoftauthfailed', message)

def test_request_login_raises_an_exception_on_missing_or_incorrect_yubikey_password(self):
message = 'Your account settings have restricted you from logging in ' \
'from mobile devices that do not support YubiKey authentication.'
Expand Down