Skip to content

Commit c429d2a

Browse files
authored
Merge branch 'dev' into dharshanb/brokerSupportLinux
2 parents 6806041 + 689e862 commit c429d2a

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

msal/managed_identity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,9 @@ def _obtain_token_on_azure_vm(http_client, managed_identity, resource):
448448
}
449449
_adjust_param(params, managed_identity)
450450
resp = http_client.get(
451-
"http://169.254.169.254/metadata/identity/oauth2/token",
451+
os.getenv(
452+
"AZURE_POD_IDENTITY_AUTHORITY_HOST", "http://169.254.169.254"
453+
).strip("/") + "/metadata/identity/oauth2/token",
452454
params=params,
453455
headers={"Metadata": "true"},
454456
)

tests/test_e2e.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,11 +851,13 @@ def test_adfs4_fed_user(self):
851851
config["password"] = self.get_lab_user_secret(config["lab_name"])
852852
self._test_username_password(**config)
853853

854+
@unittest.skip("ADFSv3 is decommissioned in our test environment")
854855
def test_adfs3_fed_user(self):
855856
config = self.get_lab_user(usertype="federated", federationProvider="ADFSv3")
856857
config["password"] = self.get_lab_user_secret(config["lab_name"])
857858
self._test_username_password(**config)
858859

860+
@unittest.skip("ADFSv2 is decommissioned in our test environment")
859861
def test_adfs2_fed_user(self):
860862
config = self.get_lab_user(usertype="federated", federationProvider="ADFSv2")
861863
config["password"] = self.get_lab_user_secret(config["lab_name"])

tests/test_mi.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,29 @@ def _test_happy_path(self, app, mocked_http, expires_in, resource="R"):
121121

122122
class VmTestCase(ClientTestCase):
123123

124-
def test_happy_path(self):
124+
def _test_happy_path(self) -> callable:
125125
expires_in = 7890 # We test a bigger than 7200 value here
126126
with patch.object(self.app._http_client, "get", return_value=MinimalResponse(
127127
status_code=200,
128128
text='{"access_token": "AT", "expires_in": "%s", "resource": "R"}' % expires_in,
129129
)) as mocked_method:
130-
self._test_happy_path(self.app, mocked_method, expires_in)
130+
super(VmTestCase, self)._test_happy_path(self.app, mocked_method, expires_in)
131+
return mocked_method
132+
133+
def test_happy_path_of_vm(self):
134+
self._test_happy_path().assert_called_with(
135+
'http://169.254.169.254/metadata/identity/oauth2/token',
136+
params={'api-version': '2018-02-01', 'resource': 'R'},
137+
headers={'Metadata': 'true'},
138+
)
139+
140+
@patch.dict(os.environ, {"AZURE_POD_IDENTITY_AUTHORITY_HOST": "http://localhost:1234//"})
141+
def test_happy_path_of_pod_identity(self):
142+
self._test_happy_path().assert_called_with(
143+
'http://localhost:1234/metadata/identity/oauth2/token',
144+
params={'api-version': '2018-02-01', 'resource': 'R'},
145+
headers={'Metadata': 'true'},
146+
)
131147

132148
def test_vm_error_should_be_returned_as_is(self):
133149
raw_error = '{"raw": "error format is undefined"}'

0 commit comments

Comments
 (0)