mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 05:07:50 -06:00
Expand the oath tests with some extra failure cases
This commit is contained in:
parent
2937575be5
commit
0c11304a7b
1 changed files with 52 additions and 0 deletions
|
@ -38,6 +38,13 @@ SUCCESSFUL_AUTH_RESPONSE = AuthenticationResponse(
|
||||||
success = True
|
success = True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
NO_REFRESH_AUTH_RESPONSE = AuthenticationResponse(
|
||||||
|
access_token = "beep",
|
||||||
|
received_at = datetime.now().strftime(TOKEN_TIMESTAMP_FORMAT),
|
||||||
|
expires_in = 300, # 5 minutes should be more than enough for testing
|
||||||
|
success = True
|
||||||
|
)
|
||||||
|
|
||||||
MALFORMED_AUTH_RESPONSE = AuthenticationResponse()
|
MALFORMED_AUTH_RESPONSE = AuthenticationResponse()
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,6 +68,43 @@ def test_refreshAccessTokenSuccess():
|
||||||
assert authorization_service.onAuthStateChanged.emit.called_with(True)
|
assert authorization_service.onAuthStateChanged.emit.called_with(True)
|
||||||
|
|
||||||
|
|
||||||
|
def test__parseJWTNoRefreshToken():
|
||||||
|
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||||
|
with patch.object(AuthorizationService, "getUserProfile", return_value=UserProfile()):
|
||||||
|
authorization_service._storeAuthData(NO_REFRESH_AUTH_RESPONSE)
|
||||||
|
assert authorization_service._parseJWT() is None
|
||||||
|
|
||||||
|
|
||||||
|
def test__parseJWTFailOnRefresh():
|
||||||
|
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||||
|
with patch.object(AuthorizationService, "getUserProfile", return_value=UserProfile()):
|
||||||
|
authorization_service._storeAuthData(SUCCESSFUL_AUTH_RESPONSE)
|
||||||
|
|
||||||
|
with patch.object(AuthorizationHelpers, "getAccessTokenUsingRefreshToken", return_value=FAILED_AUTH_RESPONSE):
|
||||||
|
assert authorization_service._parseJWT() is None
|
||||||
|
|
||||||
|
|
||||||
|
def test__parseJWTSucceedOnRefresh():
|
||||||
|
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||||
|
authorization_service.initialize()
|
||||||
|
with patch.object(AuthorizationService, "getUserProfile", return_value=UserProfile()):
|
||||||
|
authorization_service._storeAuthData(SUCCESSFUL_AUTH_RESPONSE)
|
||||||
|
|
||||||
|
with patch.object(AuthorizationHelpers, "getAccessTokenUsingRefreshToken", return_value=SUCCESSFUL_AUTH_RESPONSE):
|
||||||
|
with patch.object(AuthorizationHelpers, "parseJWT", MagicMock(return_value = None)) as mocked_parseJWT:
|
||||||
|
authorization_service._parseJWT()
|
||||||
|
mocked_parseJWT.assert_called_with("beep")
|
||||||
|
|
||||||
|
|
||||||
|
def test_initialize():
|
||||||
|
original_preference = MagicMock()
|
||||||
|
initialize_preferences = MagicMock()
|
||||||
|
authorization_service = AuthorizationService(OAUTH_SETTINGS, original_preference)
|
||||||
|
authorization_service.initialize(initialize_preferences)
|
||||||
|
initialize_preferences.addPreference.assert_called_once()
|
||||||
|
original_preference.addPreference.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_refreshAccessTokenFailed():
|
def test_refreshAccessTokenFailed():
|
||||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||||
authorization_service.initialize()
|
authorization_service.initialize()
|
||||||
|
@ -72,6 +116,14 @@ def test_refreshAccessTokenFailed():
|
||||||
assert authorization_service.onAuthStateChanged.emit.called_with(False)
|
assert authorization_service.onAuthStateChanged.emit.called_with(False)
|
||||||
|
|
||||||
|
|
||||||
|
def test_refreshAccesTokenWithoutData():
|
||||||
|
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||||
|
authorization_service.initialize()
|
||||||
|
authorization_service.onAuthStateChanged.emit = MagicMock()
|
||||||
|
authorization_service.refreshAccessToken()
|
||||||
|
authorization_service.onAuthStateChanged.emit.assert_not_called()
|
||||||
|
|
||||||
|
|
||||||
def test_userProfileException():
|
def test_userProfileException():
|
||||||
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
authorization_service = AuthorizationService(OAUTH_SETTINGS, Preferences())
|
||||||
authorization_service.initialize()
|
authorization_service.initialize()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue