@@ -71,7 +71,6 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
7171 String endpoint = null ;
7272 Map <String , String > headers = new HashMap <>();
7373 Map <String , List <String >> queryParameters = new HashMap <>();
74- Map <String , List <String >> bodyParameters = new HashMap <>();
7574
7675 switch (source ) {
7776 case APP_SERVICE : {
@@ -89,10 +88,8 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
8988 headers .put ("ContentType" , "application/x-www-form-urlencoded" );
9089 headers .put ("Metadata" , "true" );
9190
92- bodyParameters .put ("resource" , singletonList (resource ));
93-
9491 queryParameters .put ("resource" , singletonList (resource ));
95- return new HttpRequest ( HttpMethod . GET , computeUri ( endpoint , queryParameters ), headers , URLUtils . serializeParameters ( bodyParameters )) ;
92+ break ;
9693 }
9794 case IMDS : {
9895 endpoint = IMDS_ENDPOINT ;
@@ -110,11 +107,14 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
110107 headers .put ("Metadata" , "true" );
111108 break ;
112109 }
113- case SERVICE_FABRIC :
110+ case SERVICE_FABRIC : {
114111 endpoint = serviceFabricEndpoint ;
115112 queryParameters .put ("api-version" , singletonList ("2019-07-01-preview" ));
116113 queryParameters .put ("resource" , singletonList (resource ));
114+
115+ headers .put ("secret" , "secret" );
117116 break ;
117+ }
118118 }
119119
120120 switch (id .getIdType ()) {
@@ -172,6 +172,9 @@ void managedIdentityTest_SystemAssigned_SuccessfulResponse(ManagedIdentitySource
172172 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
173173 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
174174 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
175+ if (source == SERVICE_FABRIC ) {
176+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
177+ }
175178
176179 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
177180
@@ -206,6 +209,9 @@ void managedIdentityTest_UserAssigned_SuccessfulResponse(ManagedIdentitySourceTy
206209 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
207210 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
208211 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
212+ if (source == SERVICE_FABRIC ) {
213+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
214+ }
209215
210216 when (httpClientMock .send (expectedRequest (source , resource , id ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
211217
@@ -294,6 +300,9 @@ void managedIdentityTest_DifferentScopes_RequestsNewToken(ManagedIdentitySourceT
294300 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
295301 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
296302 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
303+ if (source == SERVICE_FABRIC ) {
304+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
305+ }
297306
298307 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
299308 when (httpClientMock .send (expectedRequest (source , anotherResource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
@@ -327,6 +336,9 @@ void managedIdentityTest_WrongScopes(ManagedIdentitySourceType source, String en
327336 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
328337 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
329338 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
339+ if (source == SERVICE_FABRIC ) {
340+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
341+ }
330342
331343 if (environmentVariables .getEnvironmentVariable ("SourceType" ).equals (ManagedIdentitySourceType .CLOUD_SHELL .toString ())) {
332344 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (500 , getMsiErrorResponseCloudShell ()));
@@ -364,7 +376,11 @@ void managedIdentityTest_WrongScopes(ManagedIdentitySourceType source, String en
364376 void managedIdentityTest_Retry (ManagedIdentitySourceType source , String endpoint , String resource ) throws Exception {
365377 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
366378 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
367- DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
379+
380+ DefaultHttpClientManagedIdentity httpClientMock = mock (DefaultHttpClientManagedIdentity .class );
381+ if (source == SERVICE_FABRIC ) {
382+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
383+ }
368384
369385 miApp = ManagedIdentityApplication
370386 .builder (ManagedIdentityId .systemAssigned ())
@@ -415,6 +431,9 @@ void managedIdentity_RequestFailed_NoPayload(ManagedIdentitySourceType source, S
415431 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
416432 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
417433 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
434+ if (source == SERVICE_FABRIC ) {
435+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
436+ }
418437
419438 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (500 , "" ));
420439
@@ -449,7 +468,9 @@ void managedIdentity_RequestFailed_NullResponse(ManagedIdentitySourceType source
449468 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
450469 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
451470 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
452-
471+ if (source == SERVICE_FABRIC ) {
472+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
473+ }
453474 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , "" ));
454475
455476 miApp = ManagedIdentityApplication
@@ -483,6 +504,9 @@ void managedIdentity_RequestFailed_UnreachableNetwork(ManagedIdentitySourceType
483504 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
484505 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
485506 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
507+ if (source == SERVICE_FABRIC ) {
508+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
509+ }
486510
487511 when (httpClientMock .send (expectedRequest (source , resource ))).thenThrow (new SocketException ("A socket operation was attempted to an unreachable network." ));
488512
@@ -517,6 +541,9 @@ void managedIdentity_SharedCache(ManagedIdentitySourceType source, String endpoi
517541 IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
518542 ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
519543 DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
544+ if (source == SERVICE_FABRIC ) {
545+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
546+ }
520547
521548 when (httpClientMock .send (expectedRequest (source , resource ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
522549
0 commit comments