Skip to content
Closed
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 @@ -219,11 +219,11 @@ static final class Auth extends MappedObject {
Auth(JsonNode node) {
super(node, MethodHandles.lookup());
String auth = valueAt("/auth", String.class);
if (StringUtils.hasText(auth)) {
if (StringUtils.hasLength(auth)) {
String[] parts = new String(Base64.getDecoder().decode(auth)).split(":", 2);
Assert.state(parts.length == 2, "Malformed auth in docker configuration metadata");
this.username = parts[0];
this.password = parts[1];
this.password = trim(parts[1], Character.MIN_VALUE);
}
else {
this.username = valueAt("/username", String.class);
Expand All @@ -244,6 +244,11 @@ String getEmail() {
return this.email;
}

private static String trim(String source, char character) {
source = StringUtils.trimLeadingCharacter(source, character);
return StringUtils.trimTrailingCharacter(source, character);
}

}

static final class DockerContext extends MappedObject {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void configWithAuthIsRead() throws Exception {
.containsEntry("gcr.io", "gcr");
assertThat(configuration.getAuths()).hasSize(3).hasEntrySatisfying("https://index.docker.io/v1/", (auth) -> {
assertThat(auth.getUsername()).isEqualTo("username");
assertThat(auth.getPassword()).isEqualTo("password");
assertThat(auth.getPassword()).isEqualTo("pass\u0000word");
assertThat(auth.getEmail()).isEqualTo("[email protected]");
}).hasEntrySatisfying("custom-registry.example.com", (auth) -> {
assertThat(auth.getUsername()).isEqualTo("customUser");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"auths": {
"https://index.docker.io/v1/": {
"auth": "dXNlcm5hbWU6cGFzc3dvcmQ=",
"auth": "dXNlcm5hbWU6AABwYXNzAHdvcmQAAA==",
"email": "[email protected]"
},
"custom-registry.example.com": {
Expand Down