|
| 1 | +import hashlib |
1 | 2 | import json |
2 | 3 | import os |
3 | 4 | import sys |
@@ -80,6 +81,10 @@ def assertCacheStatus(self, app): |
80 | 81 | self.assertEqual("managed_identity", at["realm"], "Should have expected realm") |
81 | 82 |
|
82 | 83 | 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 | + """ |
83 | 88 | result = app.acquire_token_for_client(resource=resource) |
84 | 89 | mocked_http.assert_called() |
85 | 90 | call_count = mocked_http.call_count |
@@ -128,6 +133,12 @@ def test_happy_path(self): |
128 | 133 | text='{"access_token": "AT", "expires_in": "%s", "resource": "R"}' % expires_in, |
129 | 134 | )) as mocked_method: |
130 | 135 | 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 | + ) |
131 | 142 |
|
132 | 143 | def test_vm_error_should_be_returned_as_is(self): |
133 | 144 | raw_error = '{"raw": "error format is undefined"}' |
@@ -238,6 +249,17 @@ def _test_happy_path(self, app): |
238 | 249 | )) as mocked_method: |
239 | 250 | super(ServiceFabricTestCase, self)._test_happy_path( |
240 | 251 | 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 | + ) |
241 | 263 |
|
242 | 264 | def test_happy_path(self): |
243 | 265 | self._test_happy_path(self.app) |
|
0 commit comments