From a4ed09e5d2970eacf0e97cfbc089acb7a3622ced Mon Sep 17 00:00:00 2001 From: Dmytro Nosan Date: Sun, 25 Jan 2026 23:23:53 +0100 Subject: [PATCH] Ensure Windows Docker credential helper resolves correctly Before this commit, "cmd /c" was never added to the final command, which meant the Docker credential helper was not executed correctly. See gh-48965 Signed-off-by: Dmytro Nosan --- .../docker/configuration/CredentialHelper.java | 3 ++- .../configuration/CredentialHelperTests.java | 18 ++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelper.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelper.java index e6d11e92600..79dcb350c8a 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelper.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelper.java @@ -21,6 +21,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Set; @@ -78,7 +79,7 @@ class CredentialHelper { if (Platform.isWindows()) { processBuilder.command("cmd", "/c"); } - processBuilder.command(this.executable, action); + processBuilder.command().addAll(Arrays.asList(this.executable, action)); return processBuilder; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelperTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelperTests.java index d3a1e38a588..84a14ddd7f5 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelperTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/CredentialHelperTests.java @@ -38,10 +38,20 @@ class CredentialHelperTests { @BeforeAll static void setUp() throws Exception { - String executableName = "docker-credential-test" + ((Platform.isWindows()) ? ".bat" : ".sh"); - String executable = new ClassPathResource(executableName, CredentialHelperTests.class).getFile() - .getAbsolutePath(); - helper = new CredentialHelper(executable); + helper = new CredentialHelper(getExecutableName()); + } + + private static String getExecutableName() throws Exception { + if (Platform.isWindows()) { + String executablePath = geExecutableAbsolutePath("docker-credential-test.bat"); + // cmd /c must resolve automatically .bat suffix + return executablePath.substring(0, executablePath.lastIndexOf(".bat")); + } + return geExecutableAbsolutePath("docker-credential-test.sh"); + } + + private static String geExecutableAbsolutePath(String executableName) throws Exception { + return new ClassPathResource(executableName, CredentialHelperTests.class).getFile().getAbsolutePath(); } @Test