Skip to content

Commit

Permalink
Add a unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Oleksandr Vayda <oleksandr.vayda@gmail.com>
  • Loading branch information
wajda authored and rohanKanojia committed Jul 24, 2023
1 parent 68b9371 commit c376e3d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/test/java/io/fabric8/maven/docker/util/AuthConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,28 @@ void toJsonConfig() {
Assertions.assertEquals("{\"auths\":{\"druidia.com/registry\":{\"auth\":\"a2luZy5yb2xhbmQ6MTIzNDU=\"}}}", config.toJson());
}

@Test
void toJsonConfig_dockerio() {
// This test covers a fix for the issue #1688.
// When the registry is `docker.io` the auth URL has to be a predefined constant.
AuthConfig config = new AuthConfig("king.roland", "12345", "king_roland@druidia.com", null);

// default registry (docker.io)
Assertions.assertEquals("{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"a2luZy5yb2xhbmQ6MTIzNDU=\"}}}", config.toJson());

// docker.io explicitly set
config.setRegistry("docker.io");
Assertions.assertEquals("{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"a2luZy5yb2xhbmQ6MTIzNDU=\"}}}", config.toJson());

// docker.io with a trailing slash
config.setRegistry("docker.io/");
Assertions.assertEquals("{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"a2luZy5yb2xhbmQ6MTIzNDU=\"}}}", config.toJson());

// docker.io with a username
config.setRegistry("docker.io/smith");
Assertions.assertEquals("{\"auths\":{\"https://index.docker.io/v1/\":{\"auth\":\"a2luZy5yb2xhbmQ6MTIzNDU=\"}}}", config.toJson());
}

private void check(AuthConfig config) {
// Since Base64.decodeBase64 handles URL-safe encoding, must explicitly check
// the correct characters are used
Expand All @@ -61,4 +83,4 @@ private void check(AuthConfig config) {
Assertions.assertEquals("roland@jolokia.org",data.get(AuthConfig.AUTH_EMAIL).getAsString());
Assertions.assertFalse(data.has(AuthConfig.AUTH_AUTH));
}
}
}

0 comments on commit c376e3d

Please sign in to comment.