8000 Prevent auths field in config.json to be null (#2142) · docker-java/docker-java@e92c30e · GitHub
[go: up one dir, main page]

Skip to content

Commit e92c30e

Browse files
authored
Prevent auths field in config.json to be null (#2142)
Fixes #2138
1 parent ca8b859 commit e92c30e

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

docker-java-core/src/main/java/com/github/dockerjava/core/DockerConfigFile.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.github.dockerjava.core;
22

33
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import com.fasterxml.jackson.annotation.JsonSetter;
45
import com.fasterxml.jackson.core.type.TypeReference;
56
import com.fasterxml.jackson.databind.ObjectMapper;
67
import com.github.dockerjava.api.model.AuthConfig;
@@ -28,7 +29,7 @@ public class DockerConfigFile {
2829
};
2930

3031
@JsonProperty
31-
private final Map<String, AuthConfig> auths;
32+
private Map<String, AuthConfig> auths;
3233

3334
@JsonProperty
3435
private String currentContext;
@@ -46,6 +47,11 @@ public Map<String, AuthConfig> getAuths() {
4647
return auths;
4748
}
4849

50+
@JsonSetter
51+
public void setAuths(Map<String, AuthConfig> authConfigMap) {
52+
auths = (authConfigMap == null || authConfigMap.size() == 0) ? new HashMap<>() : authConfigMap;
53+
}
54+
4955
void addAuthConfig(AuthConfig config) {
5056
auths.put(config.getRegistryAddress(), config);
5157
}

docker-java/src/test/java/com/github/dockerjava/core/DockerConfigFileTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,12 @@ public void nonExistent() throws IOException {
164164
assertThat(runTest("idontexist"), is(expected));
165165
}
166166

167+
@Test
168+
public void validJsonAuthsNull() throws IOException {
169+
DockerConfigFile expected = new DockerConfigFile();
170+
assertThat(runTest("validJsonAuthsNull"), is(expected));
171+
}
172+
167173
private DockerConfigFile runTest(String testFileName) throws IOException {
168174
return DockerConfigFile.loadConfig(JSONTestHelper.getMapper(), new File(FILESROOT, testFileName).getAbsolutePath());
169175
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"auths": null,
3+
"credsStore": "desktop",
4+
"plugins": {
5+
"-x-cli-hints": {
6+
"enabled": "true"
7+
}
8+
}
9+
}

0 commit comments

Comments
 (0)
0