diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthentication.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthentication.java index 5d1495dc744d..1cb196f66472 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthentication.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthentication.java @@ -85,14 +85,13 @@ private String getServerUrl(ImageReference imageReference) { private DockerRegistryAuthentication getAuthentication(String serverUrl) { Credential credentialsFromHelper = getCredentialsFromHelper(serverUrl); Map.Entry authConfigEntry = getAuthConfigEntry(serverUrl); - serverUrl = (authConfigEntry != null) ? authConfigEntry.getKey() : serverUrl; Auth authConfig = (authConfigEntry != null) ? authConfigEntry.getValue() : null; if (credentialsFromHelper != null) { return getAuthentication(credentialsFromHelper, authConfig, serverUrl); } - if (authConfigEntry != null) { - return DockerRegistryAuthentication.user(authConfig.getUsername(), authConfig.getPassword(), serverUrl, - authConfig.getEmail()); + if (authConfig != null) { + return DockerRegistryAuthentication.user(authConfig.getUsername(), authConfig.getPassword(), + authConfigEntry.getKey(), authConfig.getEmail()); } return this.fallback; } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthenticationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthenticationTests.java index a60e04f184ec..d0ddf02c4836 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthenticationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthenticationTests.java @@ -348,6 +348,36 @@ void getAuthHeaderReturnsFallbackWhenImageReferenceNull(@ResourcesRoot Path dire then(desktopHelper).should(never()).get(any(String.class)); } + @WithResource(name = "config.json", content = """ + { + "auths": { + "https://my-registry.example.com": { + "email": "test@gmail.com" + } + }, + "credsStore": "desktop" + } + """) + @WithResource(name = "credentials.json", content = """ + { + "Username": "username", + "Secret": "secret" + } + """) + @Test + void getAuthHeaderWhenUsingHelperFromCredHelpersUsesImageReferenceServerUrlAsFallback(@ResourcesRoot Path directory) + throws Exception { + this.environment.put("DOCKER_CONFIG", directory.toString()); + mockHelper("desktop", "my-registry.example.com", "credentials.json"); + ImageReference imageReference = ImageReference.of("my-registry.example.com/ubuntu:latest"); + String authHeader = getAuthHeader(imageReference); + assertThat(decode(authHeader)).hasSize(4) + .containsEntry("serveraddress", "my-registry.example.com") + .containsEntry("username", "username") + .containsEntry("password", "secret") + .containsEntry("email", "test@gmail.com"); + } + private String getAuthHeader(ImageReference imageReference) { return getAuthHeader(imageReference, null); }