Skip to content

Commit

Permalink
fix: support for proxy authentication from proxy URL user info
Browse files Browse the repository at this point in the history
closes: #6247

Signed-off-by: Steve Hawkins <[email protected]>
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
shawkins authored and manusa committed Sep 25, 2024
1 parent a1e7a4a commit 9e105cb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
## CHANGELOG

### 6.13.4 (2024-09-25)

#### Bugs
* Fix #6247: Support for proxy authentication from proxy URL user info


### 6.13.3 (2024-08-13)

#### Bugs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,15 @@ public static Map<String, io.fabric8.kubernetes.client.http.Interceptor> createA
return interceptors;
}

public static String basicCredentials(String username, String password) {
String usernameAndPassword = username + ":" + password;
public static String basicCredentials(String usernameAndPassword) {
String encoded = Base64.getEncoder().encodeToString(usernameAndPassword.getBytes(StandardCharsets.UTF_8));
return "Basic " + encoded;
}

public static String basicCredentials(String username, String password) {
return basicCredentials(username + ":" + password);
}

/**
* @deprecated you should not need to call this method directly. Please create your own HttpClient.Factory
* should you need to customize your clients.
Expand Down Expand Up @@ -229,6 +232,11 @@ static void configureProxy(Config config, HttpClient.Builder builder)
builder.proxyAuthorization(basicCredentials(config.getProxyUsername(), config.getProxyPassword()));
}

String userInfo = proxyUri.getUserInfo();
if (userInfo != null) {
builder.proxyAuthorization(basicCredentials(userInfo));
}

builder.proxyType(toProxyType(proxyUri.getScheme()));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ void testConfigureSocksProxy() throws Exception {
Mockito.verify(builder).proxyAddress(new InetSocketAddress("192.168.0.1", 8080));
}

@Test
void testConfigureProxyAuth() throws Exception {
Config config = new ConfigBuilder().withMasterUrl("http://localhost").withHttpProxy("http://user:[email protected]:8080")
.build();
Builder builder = Mockito.mock(HttpClient.Builder.class, Mockito.RETURNS_SELF);

HttpClientUtils.configureProxy(config, builder);

Mockito.verify(builder).proxyType(HttpClient.ProxyType.HTTP);
Mockito.verify(builder).proxyAuthorization("Basic dXNlcjpwYXNzd29yZA==");
}

@Test
void testCreateApplicableInterceptors() {
// Given
Expand Down

0 comments on commit 9e105cb

Please sign in to comment.