From c376e3d9dfea2ef672ee3070341693629925bf0a Mon Sep 17 00:00:00 2001 From: Oleksandr Vayda Date: Mon, 17 Jul 2023 11:15:23 +0200 Subject: [PATCH] Add a unit test Signed-off-by: Oleksandr Vayda --- .../maven/docker/util/AuthConfigTest.java | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/test/java/io/fabric8/maven/docker/util/AuthConfigTest.java b/src/test/java/io/fabric8/maven/docker/util/AuthConfigTest.java index 79b694b98..02c1d273e 100644 --- a/src/test/java/io/fabric8/maven/docker/util/AuthConfigTest.java +++ b/src/test/java/io/fabric8/maven/docker/util/AuthConfigTest.java @@ -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 @@ -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)); } -} \ No newline at end of file +}