Skip to content

Commit 9e105cb

Browse files
shawkinsmanusa
authored andcommitted
fix: support for proxy authentication from proxy URL user info
closes: #6247 Signed-off-by: Steve Hawkins <[email protected]> Signed-off-by: Marc Nuri <[email protected]>
1 parent a1e7a4a commit 9e105cb

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
## CHANGELOG
22

3+
### 6.13.4 (2024-09-25)
4+
5+
#### Bugs
6+
* Fix #6247: Support for proxy authentication from proxy URL user info
7+
8+
39
### 6.13.3 (2024-08-13)
410

511
#### Bugs

kubernetes-client-api/src/main/java/io/fabric8/kubernetes/client/utils/HttpClientUtils.java

+10-2
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,15 @@ public static Map<String, io.fabric8.kubernetes.client.http.Interceptor> createA
123123
return interceptors;
124124
}
125125

126-
public static String basicCredentials(String username, String password) {
127-
String usernameAndPassword = username + ":" + password;
126+
public static String basicCredentials(String usernameAndPassword) {
128127
String encoded = Base64.getEncoder().encodeToString(usernameAndPassword.getBytes(StandardCharsets.UTF_8));
129128
return "Basic " + encoded;
130129
}
131130

131+
public static String basicCredentials(String username, String password) {
132+
return basicCredentials(username + ":" + password);
133+
}
134+
132135
/**
133136
* @deprecated you should not need to call this method directly. Please create your own HttpClient.Factory
134137
* should you need to customize your clients.
@@ -229,6 +232,11 @@ static void configureProxy(Config config, HttpClient.Builder builder)
229232
builder.proxyAuthorization(basicCredentials(config.getProxyUsername(), config.getProxyPassword()));
230233
}
231234

235+
String userInfo = proxyUri.getUserInfo();
236+
if (userInfo != null) {
237+
builder.proxyAuthorization(basicCredentials(userInfo));
238+
}
239+
232240
builder.proxyType(toProxyType(proxyUri.getScheme()));
233241
}
234242
}

kubernetes-client-api/src/test/java/io/fabric8/kubernetes/client/utils/HttpClientUtilsTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,18 @@ void testConfigureSocksProxy() throws Exception {
9090
Mockito.verify(builder).proxyAddress(new InetSocketAddress("192.168.0.1", 8080));
9191
}
9292

93+
@Test
94+
void testConfigureProxyAuth() throws Exception {
95+
Config config = new ConfigBuilder().withMasterUrl("http://localhost").withHttpProxy("http://user:[email protected]:8080")
96+
.build();
97+
Builder builder = Mockito.mock(HttpClient.Builder.class, Mockito.RETURNS_SELF);
98+
99+
HttpClientUtils.configureProxy(config, builder);
100+
101+
Mockito.verify(builder).proxyType(HttpClient.ProxyType.HTTP);
102+
Mockito.verify(builder).proxyAuthorization("Basic dXNlcjpwYXNzd29yZA==");
103+
}
104+
93105
@Test
94106
void testCreateApplicableInterceptors() {
95107
// Given

0 commit comments

Comments
 (0)