@@ -685,6 +685,46 @@ void managedIdentityTest_WithClaims(ManagedIdentitySourceType source, String end
685
685
verify (httpClientMock , times (2 )).send (any ());
686
686
}
687
687
688
+ @ ParameterizedTest
689
+ @ MethodSource ("com.microsoft.aad.msal4j.ManagedIdentityTestDataProvider#createDataError" )
690
+ void managedIdentityTest_WithCapabilitiesOnly (ManagedIdentitySourceType source , String endpoint ) throws Exception {
691
+ IEnvironmentVariables environmentVariables = new EnvironmentVariablesHelper (source , endpoint );
692
+ ManagedIdentityApplication .setEnvironmentVariables (environmentVariables );
693
+ DefaultHttpClient httpClientMock = mock (DefaultHttpClient .class );
694
+ if (source == SERVICE_FABRIC ) {
695
+ ServiceFabricManagedIdentitySource .setHttpClient (httpClientMock );
696
+ }
697
+
698
+ when (httpClientMock .send (expectedRequest (source , resource , false , true , null ))).thenReturn (expectedResponse (200 , getSuccessfulResponse (resource )));
699
+
700
+ miApp = ManagedIdentityApplication
701
+ .builder (ManagedIdentityId .systemAssigned ())
702
+ .httpClient (httpClientMock )
703
+ .clientCapabilities (singletonList ("cp1" ))
704
+ .build ();
705
+
706
+ // Clear caching to avoid cross test pollution.
707
+ miApp .tokenCache ().accessTokens .clear ();
708
+
709
+ // First call, get the token from the identity provider.
710
+ IAuthenticationResult result = miApp .acquireTokenForManagedIdentity (
711
+ ManagedIdentityParameters .builder (resource )
712
+ .build ()).get ();
713
+
714
+ assertNotNull (result .accessToken ());
715
+ assertEquals (TokenSource .IDENTITY_PROVIDER , result .metadata ().tokenSource ());
716
+
717
+ // Second call, get the token from the cache without passing the claims.
718
+ result = miApp .acquireTokenForManagedIdentity (
719
+ ManagedIdentityParameters .builder (resource )
720
+ .build ()).get ();
721
+
722
+ assertNotNull (result .accessToken ());
723
+ assertEquals (TokenSource .CACHE , result .metadata ().tokenSource ());
724
+
725
+ verify (httpClientMock , times (2 )).send (any ());
726
+ }
727
+
688
728
@ ParameterizedTest
689
729
@ MethodSource ("com.microsoft.aad.msal4j.ManagedIdentityTestDataProvider#createDataError" )
690
730
void managedIdentity_ClaimsAndCapabilities (ManagedIdentitySourceType source , String endpoint ) throws Exception {
0 commit comments