split deserialization test
@@ -18,7 +18,7 @@ from six.moves.urllib_parse import urlparse
from helpers import mock_response
-def test_authn_client_deserialization():
+def test_deserialization_expires_integers():
now = 6
expires_in = 59 - now
expires_on = now + expires_in
@@ -32,36 +32,58 @@ def test_authn_client_deserialization():
token = AuthnClient(endpoint="http://foo", transport=Mock(send=mock_send)).request_token(scope)
assert token == expected_access_token
- # response with expires_on only and it's a datetime string (App Service MSI)
+ # response with expires_in as well
token_payload = {
"access_token": access_token,
- "expires_on": "01/01/1970 00:00:{} +00:00".format(now + expires_in),
+ "expires_in": expires_in,
"token_type": "Bearer",
- "resource": scope,
+ "ext_expires_in": expires_in,
}
+ with patch(AuthnClient.__module__ + ".time.time") as mock_time:
+ mock_time.return_value = now
+ mock_send = Mock(return_value=mock_response(json_payload=token_payload))
token = AuthnClient(endpoint="http://foo", transport=Mock(send=mock_send)).request_token(scope)
assert token == expected_access_token
- # response with string expires_in and expires_on (IMDS, Cloud Shell)
+
+def test_deserialization_app_service_msi():
+ now = 6
+ expires_in = 59 - now
+ expires_on = now + expires_in
+ access_token = "***"
+ expected_access_token = AccessToken(access_token, expires_on)
+ scope = "scope"
+
+ # response with expires_on only and it's a datetime string (App Service MSI, Linux)
token_payload = {
"access_token": access_token,
- "expires_in": str(expires_in),
- "expires_on": str(expires_on),
+ "expires_on": "01/01/1970 00:00:{} +00:00".format(now + expires_in),
"token_type": "Bearer",
"resource": scope,
}
+ mock_send = Mock(return_value=mock_response(json_payload=token_payload))
token = AuthnClient(endpoint="http://foo", transport=Mock(send=mock_send)).request_token(scope)
assert token == expected_access_token
- # response with int expires_in (AAD)
+
+def test_deserialization_expires_strings():
+ now = 6
+ expires_in = 59 - now
+ expires_on = now + expires_in
+ access_token = "***"
+ expected_access_token = AccessToken(access_token, expires_on)
+ scope = "scope"
+
+ # response with string expires_in and expires_on (IMDS, Cloud Shell)
token_payload = {
"access_token": access_token,
- "expires_in": expires_in,
+ "expires_in": str(expires_in),
+ "ext_expires_in": str(expires_in),
+ "expires_on": str(expires_on),
"token_type": "Bearer",
- "ext_expires_in": expires_in,
+ "resource": scope,
}
- with patch("azure.identity._authn_client.time.time") as mock_time:
- mock_time.return_value = now
+ mock_send = Mock(return_value=mock_response(json_payload=token_payload))
token = AuthnClient(endpoint="http://foo", transport=Mock(send=mock_send)).request_token(scope)
assert token == expected_access_token
