Skip to content

Commit 9b50e14

Browse files
committed
ManagedIdentityClient will send claims and token_sha256_to_refresh to SF
1 parent 8c2269b commit 9b50e14

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tests/test_mi.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import hashlib
12
import json
23
import os
34
import sys
@@ -80,6 +81,10 @@ def assertCacheStatus(self, app):
8081
self.assertEqual("managed_identity", at["realm"], "Should have expected realm")
8182

8283
def _test_happy_path(self, app, mocked_http, expires_in, resource="R"):
84+
"""It tests a normal token request that is expected to be sent on wire,
85+
a subsequent same token request that is expected to hit cache,
86+
and then a request with claims_challenge.
87+
"""
8388
result = app.acquire_token_for_client(resource=resource)
8489
mocked_http.assert_called()
8590
call_count = mocked_http.call_count
@@ -128,6 +133,12 @@ def test_happy_path(self):
128133
text='{"access_token": "AT", "expires_in": "%s", "resource": "R"}' % expires_in,
129134
)) as mocked_method:
130135
self._test_happy_path(self.app, mocked_method, expires_in)
136+
mocked_method.assert_called_with(
137+
# The last call contained claims_challenge but IMDS doesn't support claims
138+
'http://169.254.169.254/metadata/identity/oauth2/token',
139+
params={'api-version': '2018-02-01', 'resource': 'R'},
140+
headers={'Metadata': 'true'},
141+
)
131142

132143
def test_vm_error_should_be_returned_as_is(self):
133144
raw_error = '{"raw": "error format is undefined"}'
@@ -238,6 +249,17 @@ def _test_happy_path(self, app):
238249
)) as mocked_method:
239250
super(ServiceFabricTestCase, self)._test_happy_path(
240251
app, mocked_method, expires_in)
252+
mocked_method.assert_called_with(
253+
# The last call contained claims_challenge so it should relay both claims and hash to SF
254+
'http://localhost',
255+
params={
256+
'api-version': '2019-07-01-preview',
257+
'resource': 'R',
258+
'claims': 'foo',
259+
'token_sha256_to_refresh': hashlib.sha256(b"AT").hexdigest(),
260+
},
261+
headers={'Secret': 'foo'}
262+
)
241263

242264
def test_happy_path(self):
243265
self._test_happy_path(self.app)

0 commit comments

Comments
 (0)