fix(#806): filter config.json before unmarshalling · kylechase/docker-java@23d7e80 · GitHub
Skip to content

Commit 23d7e80

Browse files
David LeischnigKostyaSha
authored andcommitted
fix(docker-java#806): filter config.json before unmarshalling
As ObjectMapper expects all propeties of json content to match AuthConfig it fails on any other like "credStore" or "HttpHeaders". As only "auths" is used the json is mapped to ObjectNode so we can remove any other property. The content of this filtered node can be used as source for unmarshalling AuthConfig.
1 parent 2f28677 commit 23d7e80

7 files changed

Lines changed: 70 additions & 20 deletions

File tree

src/main/java/com/github/dockerjava/core/AuthConfigFile.java

Lines changed: 21 additions & 5 deletions

src/test/java/com/github/dockerjava/core/AuthConfigFileTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,23 @@ public void validJson() throws IOException {
6464
expected.addConfig(authConfig1);
6565
expected.addConfig(authConfig2);
6666

67-
Assert.assertEquals(runTest("validJson"), expected);
67+
Assert.assertEquals(runTest("validJson.json"), expected);
6868

6969
}
7070

71+
@Test
72+
public void validJsonWithUnknown() throws IOException {
73+
AuthConfig authConfig1 = new AuthConfig()
74+
.withEmail("foo@example.com")
75+
.withUsername("foo")
76+
.withPassword("bar")
77+
.withRegistryAddress("quay.io");
78+
79+
AuthConfigFile expected = new AuthConfigFile();
80+
expected.addConfig(authConfig1);
81+
runTest("validJsonWithUnknown.json");
82+
}
83+
7184
@Test
7285
public void validLegacy() throws IOException {
7386
AuthConfig authConfig = new AuthConfig()

src/test/java/com/github/dockerjava/core/command/ListContainersCmdImplTest.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ public void testListContainers() throws Exception {
5757

5858
String testImage = "busybox";
5959

60-
// need to block until image is pulled completely
61-
dockerClient.pullImageCmd(testImage).exec(new PullImageResultCallback()).awaitSuccess();
62-
6360
List<Container> containers = dockerClient.listContainersCmd().withShowAll(true).exec();
6461
assertThat(containers, notNullValue());
6562
LOG.info("Container List: {}", containers);

src/test/java/com/github/dockerjava/netty/exec/ListContainersCmdExecTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ public void testListContainers() throws Exception {
5959

6060
String testImage = "busybox";
6161

62-
// // need to block until image is pulled completely
63-
// dockerClient.pullImageCmd(testImage).exec(new PullImageResultCallback()).awaitSuccess();
64-
6562
List<Container> containers = dockerClient.listContainersCmd().withShowAll(true).exec();
6663
assertThat(containers, notNullValue());
6764
LOG.info("Container List: {}", containers);
@@ -107,9 +104,6 @@ public void testListContainersWithLabelsFilter() throws Exception {
107104

108105
String testImage = "busybox";
109106

110-
// need to block until image is pulled completely
111-
dockerClient.pullImageCmd(testImage).exec(new PullImageResultCallback()).awaitCompletion();
112-
113107
List<Container> containers = dockerClient.listContainersCmd().withShowAll(true).exec();
114108
assertThat(containers, notNullValue());
115109
LOG.info("Container List: {}", containers);
@@ -152,16 +146,25 @@ public void testListContainersWithLabelsFilter() throws Exception {
152146
Map<String, String> labels = ImmutableMap.of("test", "docker-java");
153147

154148
// list with filter by label
155-
dockerClient.createContainerCmd(testImage).withCmd("echo").withLabels(labels).exec();
156-
filteredContainers = dockerClient.listContainersCmd().withShowAll(true)
157-
.withLabelFilter(labels).exec();
149+
dockerClient.createContainerCmd(testImage)
150+
.withCmd("echo")
151+
.withLabels(labels)
152+
.exec();
153+
154+
filteredContainers = dockerClient.listContainersCmd()
155+
.withShowAll(true)
156+
.withLabelFilter(labels)
157+
.exec();
158+
158159
assertThat(filteredContainers.size(), is(equalTo(1)));
159160
Container container3 = filteredContainers.get(0);
160161
assertThat(container3.getCommand(), not(isEmptyString()));
161162
assertThat(container3.getImage(), startsWith(testImage));
162163

163164
filteredContainers = dockerClient.listContainersCmd().withShowAll(true)
164-
.withLabelFilter("test").exec();
165+
.withLabelFilter("test")
166+
.exec();
167+
165168
assertThat(filteredContainers.size(), is(equalTo(1)));
166169
container3 = filteredContainers.get(0);
167170
assertThat(container3.getCommand(), not(isEmptyString()));

src/test/resources/testAuthConfigFile/validJson

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"quay.io": {
3+
"auth": "Zm9vOmJhcg==",
4+
"email": "foo@example.com"
5+
},
6+
"https://index.docker.io/v1/": {
7+
"auth": "Zm9vMTpiYXIx",
8+
"email": "moo@example.com"
9+
}
10+
}
Lines changed: 12 additions & 0 deletions

0 commit comments

Comments
 (0)