@@ -155,18 +155,22 @@ private HttpResponse expectedResponse(int statusCode, String response) {
155155 void managedIdentity_GetManagedIdentitySource (ManagedIdentitySourceType source , String endpoint , ManagedIdentitySourceType expectedSource ) {
156156 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
157157 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
158- ManagedIdentityClient .resetManagedIdentitySourceType ();
159158
160- ManagedIdentitySourceType managedIdentitySourceType = ManagedIdentityClient .getManagedIdentitySource ();
161- assertEquals (expectedSource , managedIdentitySourceType );
159+ miApp = ManagedIdentityApplication
160+ .builder (ManagedIdentityId .systemAssigned ())
161+ .build ();
162+
163+ ManagedIdentitySourceType miClientSourceType = ManagedIdentityClient .getManagedIdentitySource ();
164+ ManagedIdentitySourceType miAppSourceType = miApp .managedIdentitySource ;
165+ assertEquals (expectedSource , miClientSourceType );
166+ assertEquals (expectedSource , miAppSourceType );
162167 }
163168
164169 @ ParameterizedTest
165170 @ MethodSource ("com.microsoft.aad.msal4j.ManagedIdentityTestDataProvider#createData" )
166171 void managedIdentityTest_SystemAssigned_SuccessfulResponse (ManagedIdentitySourceType source , String endpoint , String resource ) throws Exception {
167172 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
168173 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
169- ManagedIdentityClient .resetManagedIdentitySourceType ();
170174 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
171175
172176 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
@@ -201,7 +205,6 @@ void managedIdentityTest_SystemAssigned_SuccessfulResponse(ManagedIdentitySource
201205 void managedIdentityTest_UserAssigned_SuccessfulResponse (ManagedIdentitySourceType source , String endpoint , ManagedIdentityId id ) throws Exception {
202206 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
203207 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
204- ManagedIdentityClient .resetManagedIdentitySourceType ();
205208 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
206209
207210 when (httpClientMock .send (expectedRequest (source , resource , id ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
@@ -228,7 +231,6 @@ void managedIdentityTest_RefreshOnHalfOfExpiresOn() throws Exception {
228231 // so any of the MI options should let us verify that it's being set correctly
229232 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .APP_SERVICE , appServiceEndpoint );
230233 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
231- ManagedIdentityClient .resetManagedIdentitySourceType ();
232234 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
233235
234236 when (httpClientMock .send (expectedRequest (ManagedIdentitySourceType .APP_SERVICE , resource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
@@ -255,7 +257,6 @@ void managedIdentityTest_RefreshOnHalfOfExpiresOn() throws Exception {
255257 void managedIdentityTest_UserAssigned_NotSupported (ManagedIdentitySourceType source , String endpoint , ManagedIdentityId id ) throws Exception {
256258 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
257259 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
258- ManagedIdentityClient .resetManagedIdentitySourceType ();
259260 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
260261
261262 miApp = ManagedIdentityApplication
@@ -292,7 +293,6 @@ void managedIdentityTest_DifferentScopes_RequestsNewToken(ManagedIdentitySourceT
292293
293294 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
294295 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
295- ManagedIdentityClient .resetManagedIdentitySourceType ();
296296 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
297297
298298 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
@@ -326,7 +326,6 @@ void managedIdentityTest_DifferentScopes_RequestsNewToken(ManagedIdentitySourceT
326326 void managedIdentityTest_WrongScopes (ManagedIdentitySourceType source , String endpoint , String resource ) throws Exception {
327327 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
328328 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
329- ManagedIdentityClient .resetManagedIdentitySourceType ();
330329 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
331330
332331 if (environmentVariables .getEnvironmentVariable ("SourceType" ).equals (ManagedIdentitySourceType .CLOUD_SHELL .toString ())) {
@@ -365,7 +364,6 @@ void managedIdentityTest_WrongScopes(ManagedIdentitySourceType source, String en
365364 void managedIdentityTest_Retry (ManagedIdentitySourceType source , String endpoint , String resource ) throws Exception {
366365 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
367366 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
368- ManagedIdentityClient .resetManagedIdentitySourceType ();
369367 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
370368
371369 miApp = ManagedIdentityApplication
@@ -416,7 +414,6 @@ void managedIdentityTest_Retry(ManagedIdentitySourceType source, String endpoint
416414 void managedIdentity_RequestFailed_NoPayload (ManagedIdentitySourceType source , String endpoint ) throws Exception {
417415 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
418416 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
419- ManagedIdentityClient .resetManagedIdentitySourceType ();
420417 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
421418
422419 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (500 , "" ));
@@ -451,7 +448,6 @@ void managedIdentity_RequestFailed_NoPayload(ManagedIdentitySourceType source, S
451448 void managedIdentity_RequestFailed_NullResponse (ManagedIdentitySourceType source , String endpoint ) throws Exception {
452449 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
453450 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
454- ManagedIdentityClient .resetManagedIdentitySourceType ();
455451 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
456452
457453 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , "" ));
@@ -486,7 +482,6 @@ void managedIdentity_RequestFailed_NullResponse(ManagedIdentitySourceType source
486482 void managedIdentity_RequestFailed_UnreachableNetwork (ManagedIdentitySourceType source , String endpoint ) throws Exception {
487483 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
488484 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
489- ManagedIdentityClient .resetManagedIdentitySourceType ();
490485 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
491486
492487 when (httpClientMock .send (expectedRequest (source , resource ))).thenThrow (new SocketException ("A socket operation was attempted to an unreachable network." ));
@@ -520,7 +515,6 @@ void managedIdentity_RequestFailed_UnreachableNetwork(ManagedIdentitySourceType
520515 void azureArcManagedIdentity_MissingAuthHeader () throws Exception {
521516 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .AZURE_ARC , azureArcEndpoint );
522517 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
523- ManagedIdentityClient .resetManagedIdentitySourceType ();
524518 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
525519
526520 HttpResponse response = new HttpResponse ();
@@ -559,7 +553,6 @@ void azureArcManagedIdentity_MissingAuthHeader() throws Exception {
559553 void managedIdentity_SharedCache (ManagedIdentitySourceType source , String endpoint ) throws Exception {
560554 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
561555 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
562- ManagedIdentityClient .resetManagedIdentitySourceType ();
563556 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
564557
565558 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
@@ -600,7 +593,6 @@ void managedIdentity_SharedCache(ManagedIdentitySourceType source, String endpoi
600593 void azureArcManagedIdentity_InvalidAuthHeader () throws Exception {
601594 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .AZURE_ARC , azureArcEndpoint );
602595 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
603- ManagedIdentityClient .resetManagedIdentitySourceType ();
604596 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
605597
606598 HttpResponse response = new HttpResponse ();
@@ -639,7 +631,6 @@ void azureArcManagedIdentity_InvalidAuthHeader() throws Exception {
639631 void azureArcManagedIdentityAuthheaderValidationTest () throws Exception {
640632 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (ManagedIdentitySourceType .AZURE_ARC , azureArcEndpoint );
641633 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
642- ManagedIdentityClient .resetManagedIdentitySourceType ();
643634 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
644635
645636 //Both a missing file and an invalid path structure should throw an exception
0 commit comments