33
44package com .microsoft .aad .msal4j ;
55
6- import com .nimbusds .oauth2 .sdk .util .URLUtils ;
76import org .junit .jupiter .api .AfterAll ;
87import org .junit .jupiter .api .BeforeAll ;
98import org .junit .jupiter .api .Nested ;
@@ -89,15 +88,15 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
8988 Map <String , String > queryParameters = new HashMap <>();
9089
9190 // Add resource to query parameters (common for all sources)
92- queryParameters .put ("resource" , singletonList ( resource ) );
91+ queryParameters .put ("resource" , resource );
9392
9493 // Handle claims and capabilities if supported
9594 if (Constants .TOKEN_REVOCATION_SUPPORTED_ENVIRONMENTS .contains (source )) {
9695 if (hasCapabilities ) {
97- queryParameters .put (Constants .CLIENT_CAPABILITY_REQUEST_PARAM , singletonList ( "cp1" ) );
96+ queryParameters .put (Constants .CLIENT_CAPABILITY_REQUEST_PARAM , "cp1" );
9897 }
9998 if (hasClaims ) {
100- queryParameters .put (Constants .TOKEN_HASH_CLAIM , singletonList ( expectedTokenHash ) );
99+ queryParameters .put (Constants .TOKEN_HASH_CLAIM , expectedTokenHash );
101100 }
102101 }
103102
@@ -110,18 +109,18 @@ private HttpRequest expectedRequest(ManagedIdentitySourceType source, String res
110109 }
111110
112111 if (!queryParameters .isEmpty ()) {
113- endpoint = endpoint + "?" + URLUtils . serializeParameters (queryParameters );
112+ endpoint = endpoint + "?" + StringHelper . serializeQueryParameters (queryParameters );
114113 }
115114
116115 return new HttpRequest (HttpMethod .GET , endpoint , headers );
117116 }
118117
119118 private String configureSourceSpecificParameters (ManagedIdentitySourceType source ,
120119 Map <String , String > headers ,
121- Map <String , List < String > > queryParameters ) {
120+ Map <String , String > queryParameters ) {
122121 switch (source ) {
123122 case APP_SERVICE :
124- queryParameters .put ("api-version" , singletonList ( "2019-08-01" ) );
123+ queryParameters .put ("api-version" , "2019-08-01" );
125124 headers .put ("X-IDENTITY-HEADER" , "secret" );
126125 return ManagedIdentityTestConstants .APP_SERVICE_ENDPOINT ;
127126
@@ -131,37 +130,37 @@ private String configureSourceSpecificParameters(ManagedIdentitySourceType sourc
131130 return ManagedIdentityTestConstants .CLOUDSHELL_ENDPOINT ;
132131
133132 case AZURE_ARC :
134- queryParameters .put ("api-version" , singletonList ( "2019-11-01" ) );
133+ queryParameters .put ("api-version" , "2019-11-01" );
135134 headers .put ("Metadata" , "true" );
136135 return ManagedIdentityTestConstants .AZURE_ARC_ENDPOINT ;
137136
138137 case SERVICE_FABRIC :
139- queryParameters .put ("api-version" , singletonList ( "2019-07-01-preview" ) );
138+ queryParameters .put ("api-version" , "2019-07-01-preview" );
140139 headers .put ("secret" , "secret" );
141140 return ManagedIdentityTestConstants .SERVICE_FABRIC_ENDPOINT ;
142141
143142 case IMDS :
144143 case NONE :
145144 case DEFAULT_TO_IMDS :
146145 default :
147- queryParameters .put ("api-version" , singletonList ( "2018-02-01" ) );
146+ queryParameters .put ("api-version" , "2018-02-01" );
148147 headers .put ("Metadata" , "true" );
149148 return ManagedIdentityTestConstants .IMDS_ENDPOINT ;
150149 }
151150 }
152151
153- private void configureIdentitySpecificParameters (ManagedIdentityId id , Map <String , List < String > > queryParameters ) {
152+ private void configureIdentitySpecificParameters (ManagedIdentityId id , Map <String , String > queryParameters ) {
154153 switch (id .getIdType ()) {
155154 case SYSTEM_ASSIGNED :
156155 break ;
157156 case CLIENT_ID :
158- queryParameters .put ("client_id" , singletonList ( id .getUserAssignedId () ));
157+ queryParameters .put ("client_id" , id .getUserAssignedId ());
159158 break ;
160159 case RESOURCE_ID :
161160 if (ManagedIdentityClient .getManagedIdentitySource () == ManagedIdentitySourceType .IMDS ) {
162- queryParameters .put (Constants .MANAGED_IDENTITY_RESOURCE_ID_IMDS , Collections . singletonList ( id .getUserAssignedId () ));
161+ queryParameters .put (Constants .MANAGED_IDENTITY_RESOURCE_ID_IMDS , id .getUserAssignedId ());
163162 } else {
164- queryParameters .put (Constants .MANAGED_IDENTITY_RESOURCE_ID , Collections . singletonList ( id .getUserAssignedId () ));
163+ queryParameters .put (Constants .MANAGED_IDENTITY_RESOURCE_ID , id .getUserAssignedId ());
165164 }
166165 break ;
167166 case OBJECT_ID :
@@ -359,8 +358,6 @@ void managedIdentityTest_WithClaims(ManagedIdentitySourceType source, String end
359358
360359 when (httpClientMock .send (any ())).thenReturn (expectedResponse (HttpStatus .HTTP_OK , getSuccessfulResponse (ManagedIdentityTestConstants .RESOURCE )));
361360
362- String claimsJson = "{\" default\" :\" claim\" }" ;
363-
364361 // First call, get the token from the identity provider.
365362 IAuthenticationResult result = acquireTokenCommon (ManagedIdentityTestConstants .RESOURCE ).get ();
366363
@@ -378,7 +375,7 @@ void managedIdentityTest_WithClaims(ManagedIdentitySourceType source, String end
378375 // Third call, when claims are passed bypass the cache.
379376 result = miApp .acquireTokenForManagedIdentity (
380377 ManagedIdentityParameters .builder (ManagedIdentityTestConstants .RESOURCE )
381- .claims (claimsJson )
378+ .claims (TestConfiguration . CLAIMS_REQUEST )
382379 .build ()).get ();
383380
384381 assertTokenFromIdentityProvider (result );
@@ -430,7 +427,6 @@ void managedIdentity_ClaimsAndCapabilities(ManagedIdentitySourceType source, Str
430427 .httpClient (httpClientMock )
431428 .build ();
432429
433- String claimsJson = "{\" default\" :\" claim\" }" ;
434430 // First call, get the token from the identity provider.
435431 IAuthenticationResult result = acquireTokenCommon (ManagedIdentityTestConstants .RESOURCE ).get ();
436432
@@ -448,7 +444,7 @@ void managedIdentity_ClaimsAndCapabilities(ManagedIdentitySourceType source, Str
448444 // Third call, when claims are passed bypass the cache.
449445 result = miApp .acquireTokenForManagedIdentity (
450446 ManagedIdentityParameters .builder (ManagedIdentityTestConstants .RESOURCE )
451- .claims (claimsJson )
447+ .claims (TestConfiguration . CLAIMS_REQUEST )
452448 .build ()).get ();
453449
454450 assertTokenFromIdentityProvider (result );
@@ -770,7 +766,7 @@ void managedIdentity_RequestFailed_NoPayload(ManagedIdentitySourceType source, S
770766
771767 when (httpClientMock .send (expectedRequest (source , ManagedIdentityTestConstants .RESOURCE ))).thenReturn (expectedResponse (500 , "" ));
772768
773- assertMsalServiceException (acquireTokenCommon (ManagedIdentityTestConstants .RESOURCE ), source , MsalError .MANAGED_IDENTITY_RESPONSE_PARSE_FAILURE );
769+ assertMsalServiceException (acquireTokenCommon (ManagedIdentityTestConstants .RESOURCE ), source , MsalError .MANAGED_IDENTITY_REQUEST_FAILED );
774770 }
775771
776772 @ ParameterizedTest
0 commit comments