Skip to content

Commit 0b1d730

Browse files
committed
Use serverUrl from the image as a fallback for the Credentials helper
Before this commit, the credential helper used the serverUrl from the Map.Entry<String,Auth> as a fallback. However, the helper only uses the email from the auths. Signed-off-by: Dmytro Nosan <[email protected]>
1 parent 6bb432d commit 0b1d730

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/main/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthentication.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,13 @@ private String getServerUrl(ImageReference imageReference) {
8585
private DockerRegistryAuthentication getAuthentication(String serverUrl) {
8686
Credential credentialsFromHelper = getCredentialsFromHelper(serverUrl);
8787
Map.Entry<String, Auth> authConfigEntry = getAuthConfigEntry(serverUrl);
88-
serverUrl = (authConfigEntry != null) ? authConfigEntry.getKey() : serverUrl;
8988
Auth authConfig = (authConfigEntry != null) ? authConfigEntry.getValue() : null;
9089
if (credentialsFromHelper != null) {
9190
return getAuthentication(credentialsFromHelper, authConfig, serverUrl);
9291
}
93-
if (authConfigEntry != null) {
94-
return DockerRegistryAuthentication.user(authConfig.getUsername(), authConfig.getPassword(), serverUrl,
95-
authConfig.getEmail());
92+
if (authConfig != null) {
93+
return DockerRegistryAuthentication.user(authConfig.getUsername(), authConfig.getPassword(),
94+
authConfigEntry.getKey(), authConfig.getEmail());
9695
}
9796
return this.fallback;
9897
}

spring-boot-project/spring-boot-tools/spring-boot-buildpack-platform/src/test/java/org/springframework/boot/buildpack/platform/docker/configuration/DockerRegistryConfigAuthenticationTests.java

+30
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,36 @@ void getAuthHeaderReturnsFallbackWhenImageReferenceNull(@ResourcesRoot Path dire
348348
then(desktopHelper).should(never()).get(any(String.class));
349349
}
350350

351+
@WithResource(name = "config.json", content = """
352+
{
353+
"auths": {
354+
"https://my-registry.example.com": {
355+
"email": "[email protected]"
356+
}
357+
},
358+
"credsStore": "desktop"
359+
}
360+
""")
361+
@WithResource(name = "credentials.json", content = """
362+
{
363+
"Username": "username",
364+
"Secret": "secret"
365+
}
366+
""")
367+
@Test
368+
void getAuthHeaderWhenUsingHelperFromCredHelpersUsesImageReferenceServerUrlAsFallback(@ResourcesRoot Path directory)
369+
throws Exception {
370+
this.environment.put("DOCKER_CONFIG", directory.toString());
371+
mockHelper("desktop", "my-registry.example.com", "credentials.json");
372+
ImageReference imageReference = ImageReference.of("my-registry.example.com/ubuntu:latest");
373+
String authHeader = getAuthHeader(imageReference);
374+
assertThat(decode(authHeader)).hasSize(4)
375+
.containsEntry("serveraddress", "my-registry.example.com")
376+
.containsEntry("username", "username")
377+
.containsEntry("password", "secret")
378+
.containsEntry("email", "[email protected]");
379+
}
380+
351381
private String getAuthHeader(ImageReference imageReference) {
352382
return getAuthHeader(imageReference, null);
353383
}

0 commit comments

Comments
 (0)