From 1978ae37661b98016ec1da9bf2cb23c395f77707 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Mon, 11 Mar 2024 09:09:45 +0100 Subject: [PATCH 1/2] Use UTF-8 for basic authentication --- .../client/utils/HttpClientUtils.java | 2 +- .../client/utils/HttpClientUtilsTest.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java index 7b9af4bcd4c..c613acc590a 100644 --- a/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java +++ b/kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java @@ -118,7 +118,7 @@ public static Map createA public static String basicCredentials(String username, String password) { String usernameAndPassword = username + ":" + password; - String encoded = Base64.getEncoder().encodeToString(usernameAndPassword.getBytes(StandardCharsets.ISO_8859_1)); + String encoded = Base64.getEncoder().encodeToString(usernameAndPassword.getBytes(StandardCharsets.UTF_8)); return "Basic " + encoded; } diff --git a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java index a9e0cb30cb9..f623728c03a 100644 --- a/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java +++ b/kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java @@ -39,7 +39,9 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.Base64; import java.util.Collection; import java.util.List; import java.util.ServiceLoader; @@ -126,6 +128,22 @@ void testCreateApplicableInterceptorsWithBackwardsCompatibilityDisabled() { } } + @ParameterizedTest + @MethodSource("basicCredentialsInput") + void testBasicCredentials(String username, String password, String authentication) { + String result = HttpClientUtils.basicCredentials(username, password); + assertThat(result).isEqualTo(authentication); + String decoded = new String( + Base64.getDecoder().decode(result.substring("Basic ".length())), StandardCharsets.UTF_8); + assertThat(decoded).isEqualTo(username + ":" + password); + } + + static Stream basicCredentialsInput() { + return Stream.of( + arguments("username", "password", "Basic dXNlcm5hbWU6cGFzc3dvcmQ="), + arguments("username", "Þaßßword£", "Basic dXNlcm5hbWU6w55hw5/Dn3dvcmTCow==")); + } + @Nested @DisplayName("getProxyUrl") @TestInstance(PER_CLASS) From 39b557f872f709beaa5b47dd42dbb465ec9e4013 Mon Sep 17 00:00:00 2001 From: Jimmy Praet Date: Mon, 11 Mar 2024 09:13:08 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 53dab7ddde6..73ca93f1eb8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Fix #5729: ensure that kind is set for generic resource lists * Fix #3032: JUnit5 Kubernetes Extension works with Nested tests * Fix #5759: Don't annotate KubeSchema and ValidationSchema classes +* Fix #5781: Use UTF-8 for basic authentication #### Improvements * Fix #5701: Owner reference validity check regarding scope and namespace