Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ def _prepare_msal_kwargs(options=None):
# Both get_token's kwargs and get_token_info's options are accepted as their schema is the same (at least for now).
msal_kwargs = {}
if options:
# For VM SSH. 'data' support is a CLI-specific extension.
# SDK doesn't support 'data': https://github.com/Azure/azure-sdk-for-python/pull/16397
if 'data' in options:
msal_kwargs['data'] = options['data']
# For CAE
if 'claims' in options:
msal_kwargs['claims_challenge'] = options['claims']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@


MOCK_ACCESS_TOKEN = "mock_access_token"
MOCK_DATA = {
'key_id': 'test',
'req_cnf': 'test',
'token_type': 'ssh-cert'
}
MOCK_CLAIMS = {"test_claims": "value2"}

class MsalCredentialStub:
Expand Down Expand Up @@ -44,7 +39,7 @@ def _now_timestamp_mock():

class TestCredentialAdaptor(unittest.TestCase):

@mock.patch('azure.cli.core.auth.util._now_timestamp', new=_now_timestamp_mock)
@mock.patch('azure.cli.core.auth.util.now_timestamp', new=_now_timestamp_mock)
def test_get_token(self):
msal_cred = MsalCredentialStub()
sdk_cred = CredentialAdaptor(msal_cred)
Expand All @@ -56,15 +51,11 @@ def test_get_token(self):
assert access_token.token == MOCK_ACCESS_TOKEN
assert access_token.expires_on == 1630920323

# Note that SDK doesn't support 'data'. This is a CLI-specific extension.
sdk_cred.get_token('https://management.core.windows.net//.default', data=MOCK_DATA)
assert msal_cred.acquire_token_kwargs['data'] == MOCK_DATA

sdk_cred.get_token('https://management.core.windows.net//.default', claims=MOCK_CLAIMS)
assert msal_cred.acquire_token_claims_challenge == MOCK_CLAIMS


@mock.patch('azure.cli.core.auth.util._now_timestamp', new=_now_timestamp_mock)
@mock.patch('azure.cli.core.auth.util.now_timestamp', new=_now_timestamp_mock)
def test_get_token_info(self):
msal_cred = MsalCredentialStub()
sdk_cred = CredentialAdaptor(msal_cred)
Expand All @@ -78,10 +69,6 @@ def test_get_token_info(self):

assert msal_cred.acquire_token_scopes == ['https://management.core.windows.net//.default']

# Note that SDK doesn't support 'data'. If 'data' were supported, it should be tested with:
sdk_cred.get_token_info('https://management.core.windows.net//.default', options={'data': MOCK_DATA})
assert msal_cred.acquire_token_kwargs['data'] == MOCK_DATA

sdk_cred.get_token_info('https://management.core.windows.net//.default', options={'claims': MOCK_CLAIMS})
assert msal_cred.acquire_token_claims_challenge == MOCK_CLAIMS

Expand Down
Loading