From 225e542a057369f3e08ddc2fcce4ccc32735a620 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 16 Aug 2026 01:39:42 +0000 Subject: [PATCH 1/2] Initial plan From 02c1269c79d0e967876732914ec4a8a7f1fac1d8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sun, 16 Aug 2026 01:44:37 +0000 Subject: [PATCH 2/2] Fix Azure pod identity IMDS endpoint path Co-authored-by: gladjohn <90415114+gladjohn@users.noreply.github.com> --- .../aad/msal4j/IMDSManagedIdentitySource.java | 2 +- .../aad/msal4j/ManagedIdentityTests.java | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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 {