Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@

class HttpClientDynamicCredentials implements org.apache.hc.client5.http.auth.CredentialsProvider {

private final ProxyRuntimeProvider _proxyRuntimeProvider;
private final ProxyCredentialsProvider _proxyCredentialsProvider;

public HttpClientDynamicCredentials (ProxyRuntimeProvider proxyRuntimeProvider) {
_proxyRuntimeProvider = proxyRuntimeProvider;
public HttpClientDynamicCredentials (ProxyCredentialsProvider proxyCredentialsProvider) {
_proxyCredentialsProvider = proxyCredentialsProvider;
}

@Override
public Credentials getCredentials(AuthScope authScope, HttpContext context) {

// This Provider is invoked every time a request is made.
// This should invoke a user-custom provider responsible for:
return new BearerToken(_proxyRuntimeProvider.getJwtToken());
return new BearerToken(_proxyCredentialsProvider.getJwtToken());
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.split.client;

public interface ProxyRuntimeProvider
public interface ProxyCredentialsProvider
{
/**
* Get the additional headers needed for all http operations
Expand Down
26 changes: 13 additions & 13 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public static class HttpScheme {
private final HttpHost _proxy;
private final String _proxyUsername;
private final String _proxyPassword;
private final ProxyRuntimeProvider _proxyRuntimeProvider;
private final ProxyCredentialsProvider _proxyCredentialsProvider;
private final ProxyMTLSAuth _proxyMtlsAuth;

// To be set during startup
Expand Down Expand Up @@ -126,7 +126,7 @@ private SplitClientConfig(String endpoint,
HttpHost proxy,
String proxyUsername,
String proxyPassword,
ProxyRuntimeProvider proxyRuntimeProvider,
ProxyCredentialsProvider proxyCredentialsProvider,
ProxyMTLSAuth proxyMtlsAuth,
int eventsQueueSize,
long eventSendIntervalInMillis,
Expand Down Expand Up @@ -181,7 +181,7 @@ private SplitClientConfig(String endpoint,
_proxy = proxy;
_proxyUsername = proxyUsername;
_proxyPassword = proxyPassword;
_proxyRuntimeProvider = proxyRuntimeProvider;
_proxyCredentialsProvider = proxyCredentialsProvider;
_proxyMtlsAuth = proxyMtlsAuth;
_eventsQueueSize = eventsQueueSize;
_eventSendIntervalInMillis = eventSendIntervalInMillis;
Expand Down Expand Up @@ -314,8 +314,8 @@ public String proxyPassword() {
return _proxyPassword;
}

public ProxyRuntimeProvider proxyRuntimeStorage() {
return _proxyRuntimeProvider;
public ProxyCredentialsProvider proxyCredentialsProvider() {
return _proxyCredentialsProvider;
}

public ProxyMTLSAuth proxyMTLSAuth() {
Expand Down Expand Up @@ -463,7 +463,7 @@ public static final class Builder {
private String _proxyScheme = HttpScheme.HTTP;
private String _proxyUsername;
private String _proxyPassword;
private ProxyRuntimeProvider _proxyRuntimeProvider;
private ProxyCredentialsProvider _proxyCredentialsProvider;
private ProxyMTLSAuth _proxyMtlsAuth;
private int _eventsQueueSize = 500;
private long _eventSendIntervalInMillis = 30 * (long)1000;
Expand Down Expand Up @@ -813,11 +813,11 @@ public Builder proxyPassword(String proxyPassword) {
/**
* Set the token for authentication against the proxy (if proxy settings are enabled). (Optional).
*
* @param proxyRuntimeProvider
* @param proxyCredentialsProvider
* @return this builder
*/
public Builder proxyRuntimeStorage(ProxyRuntimeProvider proxyRuntimeProvider) {
_proxyRuntimeProvider = proxyRuntimeProvider;
public Builder proxyCredentialsProvider(ProxyCredentialsProvider proxyCredentialsProvider) {
_proxyCredentialsProvider = proxyCredentialsProvider;
return this;
}

Expand Down Expand Up @@ -1161,19 +1161,19 @@ private void verifyProxy() {
throw new IllegalArgumentException("Proxy scheme must be either http or https.");
}

if (_proxyUsername == null && _proxyRuntimeProvider == null && _proxyMtlsAuth == null) {
if (_proxyUsername == null && _proxyCredentialsProvider == null && _proxyMtlsAuth == null) {
return;
}

if (_proxyUsername != null && _proxyRuntimeProvider != null) {
if (_proxyUsername != null && _proxyCredentialsProvider != null) {
throw new IllegalArgumentException("Proxy user and Proxy token params are updated, set only one param.");
}

if (_proxyUsername != null && _proxyMtlsAuth != null) {
throw new IllegalArgumentException("Proxy user and Proxy mTLS params are updated, set only one param.");
}

if (_proxyRuntimeProvider != null && _proxyMtlsAuth != null) {
if (_proxyCredentialsProvider != null && _proxyMtlsAuth != null) {
throw new IllegalArgumentException("Proxy token and Proxy mTLS params are updated, set only one param.");
}

Expand Down Expand Up @@ -1223,7 +1223,7 @@ public SplitClientConfig build() {
proxy(),
_proxyUsername,
_proxyPassword,
_proxyRuntimeProvider,
_proxyCredentialsProvider,
_proxyMtlsAuth,
_eventsQueueSize,
_eventSendIntervalInMillis,
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/java/io/split/client/SplitFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ private static HttpClientBuilder setupProxy(HttpClientBuilder httpClientbuilder,
httpClientbuilder.setDefaultCredentialsProvider(credsProvider);
}

if (config.proxyRuntimeStorage() != null) {
if (config.proxyCredentialsProvider() != null) {
_log.debug("Proxy setup using token");
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(config.proxyRuntimeStorage()));
httpClientbuilder.setDefaultCredentialsProvider(new HttpClientDynamicCredentials(config.proxyCredentialsProvider()));
}

return httpClientbuilder;
Expand Down
14 changes: 7 additions & 7 deletions client/src/test/java/io/split/client/SplitClientConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ public void checkProxyParams() {
Assert.assertEquals("user", config.proxyUsername());
Assert.assertEquals("pass", config.proxyPassword());

ProxyRuntimeProvider proxyRuntimeProvider = new ProxyRuntimeProvider() {
ProxyCredentialsProvider proxyCredentialsProvider = new ProxyCredentialsProvider() {
@Override
public String getJwtToken() {
return "my-token";
Expand All @@ -283,9 +283,9 @@ public String getJwtToken() {
config = SplitClientConfig.builder()
.proxyHost("proxy-host")
.proxyPort(8888)
.proxyRuntimeStorage(proxyRuntimeProvider)
.proxyCredentialsProvider(proxyCredentialsProvider)
.build();
Assert.assertEquals(proxyRuntimeProvider, config.proxyRuntimeStorage());
Assert.assertEquals(proxyCredentialsProvider, config.proxyCredentialsProvider());

config = SplitClientConfig.builder()
.proxyHost("proxy-host")
Expand All @@ -307,7 +307,7 @@ public void cannotUseInvalidHttpScheme() {

@Test(expected = IllegalArgumentException.class)
public void cannotUseProxyTokenAndProxyUsername() {
ProxyRuntimeProvider proxyRuntimeProvider = new ProxyRuntimeProvider() {
ProxyCredentialsProvider proxyCredentialsProvider = new ProxyCredentialsProvider() {
@Override
public String getJwtToken() {
return "my-token";
Expand All @@ -319,7 +319,7 @@ public String getJwtToken() {
.proxyPort(8888)
.proxyUsername("user")
.proxyPassword("pass")
.proxyRuntimeStorage(proxyRuntimeProvider)
.proxyCredentialsProvider(proxyCredentialsProvider)
.build();
}

Expand All @@ -336,7 +336,7 @@ public void cannotUseProxyUserAndProxyMtls() {

@Test(expected = IllegalArgumentException.class)
public void cannotUseProxyTokenAndProxyMtls() {
ProxyRuntimeProvider proxyRuntimeProvider = new ProxyRuntimeProvider() {
ProxyCredentialsProvider proxyCredentialsProvider = new ProxyCredentialsProvider() {
@Override
public String getJwtToken() {
return "my-token";
Expand All @@ -346,7 +346,7 @@ public String getJwtToken() {
SplitClientConfig.builder()
.proxyHost("proxy-host")
.proxyPort(8888)
.proxyRuntimeStorage(proxyRuntimeProvider)
.proxyCredentialsProvider(proxyCredentialsProvider)
.proxyMtlsAuth(new ProxyMTLSAuth.Builder().proxyP12File("path/to/file").proxyP12FilePassKey("pass-key").build())
.build();
}
Expand Down
20 changes: 9 additions & 11 deletions client/src/test/java/io/split/client/SplitFactoryImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.split.telemetry.synchronizer.TelemetrySynchronizer;
import junit.framework.TestCase;
import org.apache.hc.client5.http.auth.AuthScope;
import org.apache.hc.client5.http.auth.BearerToken;
import org.apache.hc.client5.http.auth.UsernamePasswordCredentials;
import org.apache.hc.client5.http.impl.auth.BasicCredentialsProvider;
import org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator;
Expand All @@ -21,7 +20,6 @@
import org.apache.hc.core5.http.config.Registry;
import org.awaitility.Awaitility;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -151,10 +149,10 @@ public void testFactoryInstantiationWithProxyCredentials() throws Exception {

splitFactory.destroy();
}
/*

@Test
public void testFactoryInstantiationWithProxyToken() throws Exception {
class MyProxyRuntimeStorage implements ProxyRuntimeStorage {
class MyProxyCredentialsProvider implements ProxyCredentialsProvider {
@Override
public String getJwtToken() {
return "123456789";
Expand All @@ -170,7 +168,7 @@ public String getJwtToken() {
.authServiceURL(AUTH_SERVICE)
.setBlockUntilReadyTimeout(1000)
.proxyPort(6060)
.proxyRuntimeStorage(new MyProxyRuntimeStorage())
.proxyCredentialsProvider(new MyProxyCredentialsProvider())
.proxyHost(ENDPOINT)
.build();
SplitFactoryImpl splitFactory2 = new SplitFactoryImpl(API_KEY, splitClientConfig);
Expand All @@ -187,17 +185,17 @@ public String getJwtToken() {

Field credentialsProviderField2 = InternalHttp2.getDeclaredField("credentialsProvider");
credentialsProviderField2.setAccessible(true);
BasicCredentialsProvider credentialsProvider2 = (BasicCredentialsProvider) credentialsProviderField2.get(InternalHttp2.cast(httpClientField2.get(client2)));
HttpClientDynamicCredentials credentialsProvider2 = (HttpClientDynamicCredentials) credentialsProviderField2.get(InternalHttp2.cast(httpClientField2.get(client2)));

Field credMapField2 = BasicCredentialsProvider.class.getDeclaredField("credMap");
credMapField2.setAccessible(true);
ConcurrentHashMap<AuthScope, BearerToken> credMap2 = (ConcurrentHashMap) credMapField2.get(credentialsProvider2);
Field proxyRuntimeField = HttpClientDynamicCredentials.class.getDeclaredField("_proxyCredentialsProvider");
proxyRuntimeField.setAccessible(true);
MyProxyCredentialsProvider proxyRuntime = (MyProxyCredentialsProvider) proxyRuntimeField.get(credentialsProvider2);

Assert.assertEquals("123456789", credMap2.entrySet().stream().iterator().next().getValue().getToken());
assertNotNull("123456789", proxyRuntime.getJwtToken());

splitFactory2.destroy();
}
*/

@Test
public void testFactoryInstantiationWithProxyMtls() throws Exception {
SplitClientConfig splitClientConfig = SplitClientConfig.builder()
Expand Down
1 change: 1 addition & 0 deletions testing/.github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @splitio/sdk
9 changes: 9 additions & 0 deletions testing/.github/linter/checkstyle-suppressions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0"?>

<!DOCTYPE suppressions PUBLIC
"-//Checkstyle//DTD SuppressionFilter Configuration 1.2//EN"
"https://checkstyle.org/dtds/suppressions_1_2.dtd">

<suppressions>
<suppress checks="LineLength" files=".*(test|it)[\\/]"/>
</suppressions>
Loading