Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,12 @@ private AuthConfig runCredentialProvider(String hostName, String helperOrStoreNa

final String username = helperResponse.at("/Username").asText();
final String password = helperResponse.at("/Secret").asText();
final String serverUrl = helperResponse.at("/ServerURL").asText();
final AuthConfig authConfig = new AuthConfig().withRegistryAddress(serverUrl.isEmpty() ? hostName : serverUrl);
if ("<token>".equals(username)) {
return new AuthConfig().withIdentityToken(password);
return authConfig.withIdentityToken(password);
} else {
return new AuthConfig()
.withRegistryAddress(helperResponse.at("/ServerURL").asText())
.withUsername(username)
.withPassword(password);
return authConfig.withUsername(username).withPassword(password);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ public void lookupAuthConfigUsingHelperWithToken() throws URISyntaxException, IO
new AuthConfig()
);

assertThat(authConfig.getRegistryAddress())
.as("Correct server URL is obtained from a credential store")
.isEqualTo("url");
assertThat(authConfig.getIdentitytoken())
.as("Correct identitytoken is obtained from a credential store")
.isEqualTo("secret");
Expand Down Expand Up @@ -176,6 +179,45 @@ public void lookupNonEmptyAuthWithHelper() throws URISyntaxException, IOExceptio
.isEqualTo("secret");
}

@Test
public void lookupAuthConfigUsingHelperNoServerUrl() throws URISyntaxException, IOException {
final RegistryAuthLocator authLocator = createTestAuthLocator("config-with-helper-no-server-url.json");

final AuthConfig authConfig = authLocator.lookupAuthConfig(
DockerImageName.parse("registrynoserverurl.example.com/org/repo"),
new AuthConfig()
);

assertThat(authConfig.getRegistryAddress())
.as("Fallback (registry) server URL is used")
.isEqualTo("registrynoserverurl.example.com");
assertThat(authConfig.getUsername())
.as("Correct username is obtained from a credential store")
.isEqualTo("username");
assertThat(authConfig.getPassword())
.as("Correct secret is obtained from a credential store")
.isEqualTo("secret");
}

@Test
public void lookupAuthConfigUsingHelperNoServerUrlWithToken() throws URISyntaxException, IOException {
final RegistryAuthLocator authLocator = createTestAuthLocator(
"config-with-helper-no-server-url-using-token.json"
);

final AuthConfig authConfig = authLocator.lookupAuthConfig(
DockerImageName.parse("registrynoserverurltoken.example.com/org/repo"),
new AuthConfig()
);

assertThat(authConfig.getRegistryAddress())
.as("Fallback (registry) server URL is used")
.isEqualTo("registrynoserverurltoken.example.com");
assertThat(authConfig.getIdentitytoken())
.as("Correct identitytoken is obtained from a credential store")
.isEqualTo("secret");
}

@Test
public void lookupAuthConfigWithCredentialsNotFound() throws URISyntaxException, IOException {
Map<String, String> notFoundMessagesReference = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"auths": {
"registrynoserverurltoken.example.com": {}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.03.0-ce (darwin)"
},
"credHelpers": {
"registrynoserverurltoken.example.com": "fake"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"auths": {
"registrynoserverurl.example.com": {}
},
"HttpHeaders": {
"User-Agent": "Docker-Client/18.03.0-ce (darwin)"
},
"credHelpers": {
"registrynoserverurl.example.com": "fake"
}
}
14 changes: 14 additions & 0 deletions core/src/test/resources/auth-config/docker-credential-fake
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,19 @@ if [ "$inputLine" = "registrytoken.example.com" ]; then
'}'
exit 0
fi
if [ "$inputLine" = "registrynoserverurl.example.com" ]; then
echo '{' \
' "Username": "username",' \
' "Secret": "secret"' \
'}'
exit 0
fi
if [ "$inputLine" = "registrynoserverurltoken.example.com" ]; then
echo '{' \
' "Username": "<token>",' \
' "Secret": "secret"' \
'}'
exit 0
fi

exit 1