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. See gh-45345 Signed-off-by: Dmytro Nosan <dimanosan@gmail.com>
This commit is contained in:
parent
4c108c28c8
commit
439dd2299e
|
@ -85,14 +85,13 @@ class DockerRegistryConfigAuthentication implements DockerRegistryAuthentication
|
|||
private DockerRegistryAuthentication getAuthentication(String serverUrl) {
|
||||
Credential credentialsFromHelper = getCredentialsFromHelper(serverUrl);
|
||||
Map.Entry<String, Auth> 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;
|
||||
}
|
||||
|
|
|
@ -348,6 +348,36 @@ class DockerRegistryConfigAuthenticationTests {
|
|||
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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue