@@ -139,6 +139,22 @@ def test_vm_error_should_be_returned_as_is(self):
139
139
json .loads (raw_error ), self .app .acquire_token_for_client (resource = "R" ))
140
140
self .assertEqual ({}, self .app ._token_cache ._cache )
141
141
142
+ def test_vm_resource_id_parameter_should_be_msi_res_id (self ):
143
+ app = ManagedIdentityClient (
144
+ {"ManagedIdentityIdType" : "ResourceId" , "Id" : "1234" },
145
+ http_client = requests .Session (),
146
+ )
147
+ with patch .object (app ._http_client , "get" , return_value = MinimalResponse (
148
+ status_code = 200 ,
149
+ text = '{"access_token": "AT", "expires_in": 3600, "resource": "R"}' ,
150
+ )) as mocked_method :
151
+ app .acquire_token_for_client (resource = "R" )
152
+ mocked_method .assert_called_with (
153
+ 'http://169.254.169.254/metadata/identity/oauth2/token' ,
154
+ params = {'api-version' : '2018-02-01' , 'resource' : 'R' , 'msi_res_id' : '1234' },
155
+ headers = {'Metadata' : 'true' },
156
+ )
157
+
142
158
143
159
@patch .dict (os .environ , {"IDENTITY_ENDPOINT" : "http://localhost" , "IDENTITY_HEADER" : "foo" })
144
160
class AppServiceTestCase (ClientTestCase ):
@@ -164,6 +180,22 @@ def test_app_service_error_should_be_normalized(self):
164
180
}, self .app .acquire_token_for_client (resource = "R" ))
165
181
self .assertEqual ({}, self .app ._token_cache ._cache )
166
182
183
+ def test_app_service_resource_id_parameter_should_be_mi_res_id (self ):
184
+ app = ManagedIdentityClient (
185
+ {"ManagedIdentityIdType" : "ResourceId" , "Id" : "1234" },
186
+ http_client = requests .Session (),
187
+ )
188
+ with patch .object (app ._http_client , "get" , return_value = MinimalResponse (
189
+ status_code = 200 ,
190
+ text = '{"access_token": "AT", "expires_on": 12345, "resource": "R"}' ,
191
+ )) as mocked_method :
192
+ app .acquire_token_for_client (resource = "R" )
193
+ mocked_method .assert_called_with (
194
+ 'http://localhost' ,
195
+ params = {'api-version' : '2019-08-01' , 'resource' : 'R' , 'mi_res_id' : '1234' },
196
+ headers = {'X-IDENTITY-HEADER' : 'foo' , 'Metadata' : 'true' },
197
+ )
198
+
167
199
168
200
@patch .dict (os .environ , {"MSI_ENDPOINT" : "http://localhost" , "MSI_SECRET" : "foo" })
169
201
class MachineLearningTestCase (ClientTestCase ):
0 commit comments