Skip to content

Commit e5483d1

Browse files
committed
DP-2022 Add failing test for refresh with inactive session
1 parent 5ad229b commit e5483d1

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

tests/auth/auth_test.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,34 @@ def test_authenticate_fail(self, requests_mock, mock_home_dir):
161161
auth.login()
162162
except ApiAuthenticateError:
163163
assert True
164+
165+
def test_refresh_inactive_session(self, requests_mock, mock_home_dir):
166+
client_credentials_provider = ClientCredentialsProvider(config)
167+
auth = Authenticate(config=config, token_provider=client_credentials_provider)
168+
169+
auth.file_cache.credentials_cache_enabled = True
170+
171+
cached_credentials = {
172+
"provider": "TokenServiceProvider",
173+
"access_token": from_cache_expired_token,
174+
"refresh_token": from_cache_not_expired_token,
175+
}
176+
177+
auth.file_cache.write_credentials(json.dumps(cached_credentials))
178+
179+
error_msg = {
180+
"error": "invalid_grant",
181+
"error_description": "Session not active",
182+
}
183+
refresh_response = {"text": json.dumps(error_msg), "status_code": 400}
184+
login_response = {
185+
"text": json.dumps(client_credentials_response),
186+
"status_code": 200,
187+
}
188+
matcher = re.compile(token_endpoint)
189+
requests_mock.register_uri("POST", matcher, [refresh_response, login_response])
190+
191+
auth.login()
192+
193+
assert auth._access_token == from_cache_not_expired_token
194+
assert auth._refresh_token == cached_credentials["refresh_token"]

0 commit comments

Comments
 (0)