Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use UTF-8 for basic authentication #5789

Merged
merged 3 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
* Fix #5508: (crd-generator) Ensure deterministic ordering of CustomResourceDefinitionVersions

#### Improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public static Map<String, io.fabric8.kubernetes.client.http.Interceptor> 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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Arguments> basicCredentialsInput() {
return Stream.of(
arguments("username", "password", "Basic dXNlcm5hbWU6cGFzc3dvcmQ="),
arguments("username", "Þaßßword£", "Basic dXNlcm5hbWU6w55hw5/Dn3dvcmTCow=="));
}

@Nested
@DisplayName("getProxyUrl")
@TestInstance(PER_CLASS)
Expand Down