diff --git a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java index 10bbbf81..2358d025 100644 --- a/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java +++ b/msal4j-sdk/src/main/java/com/microsoft/aad/msal4j/IMDSManagedIdentitySource.java @@ -50,7 +50,7 @@ public IMDSManagedIdentitySource(MsalRequest msalRequest, } StringBuilder builder = new StringBuilder(environmentVariables.getEnvironmentVariable(Constants.AZURE_POD_IDENTITY_AUTHORITY_HOST)); - builder.append("/" + IMDS_TOKEN_PATH); + builder.append(IMDS_TOKEN_PATH); try { imdsEndpoint = new URI(builder.toString()); } catch (URISyntaxException e) { diff --git a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java index a3f35f94..5f6a5e36 100644 --- a/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java +++ b/msal4j-sdk/src/test/java/com/microsoft/aad/msal4j/ManagedIdentityTests.java @@ -366,6 +366,27 @@ void managedIdentityTest_DifferentScopes_RequestsNewToken(ManagedIdentitySourceT class ManagedIdentityBehaviorTests extends BaseManagedIdentityTest { //Tests covering specific behavior/scenarios/use cases/etc. for Managed Identity flows + @Test + void managedIdentityTest_AzurePodIdentityAuthorityHostBuildsImdsEndpointWithoutDoubleSlash() throws Exception { + String authorityHost = "http://127.0.0.1:80"; + EnvironmentVariablesHelper environmentVariables = new EnvironmentVariablesHelper(IMDS, null); + environmentVariables.mockedEnvironmentVariables.put( + Constants.AZURE_POD_IDENTITY_AUTHORITY_HOST, authorityHost); + ManagedIdentityApplication.setEnvironmentVariables(environmentVariables); + initHttpClientMock(IMDS); + initManagedIdentityApplication(ManagedIdentityId.systemAssigned()); + + when(httpClientMock.send(any())) + .thenReturn(expectedResponse(HttpStatus.HTTP_OK, + getSuccessfulResponse(ManagedIdentityTestConstants.RESOURCE))); + + acquireTokenCommon(ManagedIdentityTestConstants.RESOURCE).get(); + + ArgumentCaptor captor = ArgumentCaptor.forClass(HttpRequest.class); + verify(httpClientMock).send(captor.capture()); + assertEquals("/metadata/identity/oauth2/token", captor.getValue().url().getPath()); + } + @ParameterizedTest @MethodSource("com.microsoft.aad.msal4j.ManagedIdentityTestDataProvider#createDataError") void managedIdentityTest_WithClaims(ManagedIdentitySourceType source, String endpoint) throws Exception {