Skip to content

Commit

Permalink
update Managed Identity credential Test (#17389)
Browse files Browse the repository at this point in the history
  • Loading branch information
g2vinay authored Nov 10, 2020
1 parent 3954b67 commit 3540be5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ArcIdentityCredential extends ManagedIdentityServiceCredential {
* @return A publisher that emits an {@link AccessToken}.
*/
public Mono<AccessToken> authenticate(TokenRequestContext request) {
if (getClientId() == null) {
if (getClientId() != null) {
return Mono.error(logger.logExceptionAsError(new ClientAuthenticationException(
"User assigned identity is not supported by the Azure Arc Managed Identity Endpoint. To authenticate "
+ "with the system assigned identity omit the client id when constructing the"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ public final class ManagedIdentityCredential implements TokenCredential {
managedIdentityServiceCredential = new AppServiceMsiCredential(clientId, identityClient);
} else if (configuration.contains(Configuration.PROPERTY_IDENTITY_ENDPOINT)) {
if (configuration.contains(Configuration.PROPERTY_IDENTITY_HEADER)) {
if (configuration.contains(PROPERTY_IDENTITY_SERVER_THUMBPRINT)) {
if (configuration.get(PROPERTY_IDENTITY_SERVER_THUMBPRINT) != null) {
managedIdentityServiceCredential = new ServiceFabricMsiCredential(clientId, identityClient);
} else {
managedIdentityServiceCredential = new VirtualMachineMsiCredential(clientId, identityClient);
}
} else if (configuration.contains(PROPERTY_IMDS_ENDPOINT)) {
} else if (configuration.get(PROPERTY_IMDS_ENDPOINT) != null) {
managedIdentityServiceCredential = new ArcIdentityCredential(clientId, identityClient);
} else {
managedIdentityServiceCredential = new VirtualMachineMsiCredential(clientId, identityClient);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package com.azure.identity;

import com.azure.core.credential.TokenRequestContext;
import com.azure.core.exception.ClientAuthenticationException;
import com.azure.core.util.Configuration;
import com.azure.identity.implementation.IdentityClient;
import com.azure.identity.util.TestUtils;
Expand Down Expand Up @@ -86,4 +87,24 @@ public void testIMDS() throws Exception {
&& expiresOn.getSecond() == token.getExpiresAt().getSecond())
.verifyComplete();
}

@Test
public void testArcUserAssigned() throws Exception {
Configuration configuration = Configuration.getGlobalConfiguration().clone();

// setup
String token1 = "token1";
String endpoint = "http://localhost";
TokenRequestContext request = new TokenRequestContext().addScopes("https://management.azure.com");
configuration.put("IDENTITY_ENDPOINT", endpoint);
configuration.put("IMDS_ENDPOINT", endpoint);


// test
ManagedIdentityCredential credential = new ManagedIdentityCredentialBuilder().clientId(CLIENT_ID).build();
StepVerifier.create(credential.getToken(request))
.expectErrorMatches(t -> t instanceof ClientAuthenticationException)
.verify();
}

}

0 comments on commit 3540be5

Please sign in to comment.