Skip to content

Commit

Permalink
added coverage for kerberos in factory class
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilal Al committed Sep 5, 2024
1 parent eb98607 commit 32adc6d
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion client/src/test/java/io/split/client/SplitFactoryImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URISyntaxException;
import java.util.HashMap;
Expand All @@ -38,6 +39,7 @@
import okhttp3.Authenticator;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import okhttp3.Interceptor;

import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -367,7 +369,7 @@ public void testLocalhosJsonInputStreamNullAndFileTypeNull() throws URISyntaxExc
}

@Test
public void testFactoryKerberosInstance() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException, URISyntaxException, IOException {
public void testBuildKerberosClientParams() throws URISyntaxException, IOException {
PowerMockito.mockStatic(SplitFactoryImpl.class);

ArgumentCaptor<Proxy> proxyCaptor = ArgumentCaptor.forClass(Proxy.class);
Expand Down Expand Up @@ -410,4 +412,51 @@ public void testFactoryKerberosInstance() throws NoSuchMethodException, Invocati
Assert.assertEquals("HTTP @ https://sdk.split-stage.io:6060", proxyCaptor.getValue().toString());
Assert.assertTrue(logCaptor.getValue() instanceof okhttp3.logging.HttpLoggingInterceptor);
}

@Test
public void testFactoryKerberosInstance() throws URISyntaxException, IOException {
OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
PowerMockito.stub(PowerMockito.method(SplitFactoryImpl.class, "buildOkHttpClient")).toReturn(okHttpClient);
PowerMockito.stub(PowerMockito.method(SplitFactoryImpl.class, "getProxyAuthenticator")).toReturn(null);

SplitClientConfig splitClientConfig = SplitClientConfig.builder()
.setBlockUntilReadyTimeout(10000)
.authScheme(HttpAuthScheme.KERBEROS)
.kerberosPrincipalName("bilal@localhost")
.proxyPort(6060)
.proxyHost(ENDPOINT)
.build();

Map<String, String> kerberosOptions = new HashMap<String, String>();
kerberosOptions.put("com.sun.security.auth.module.Krb5LoginModule", "required");
kerberosOptions.put("refreshKrb5Config", "false");
kerberosOptions.put("doNotPrompt", "false");
kerberosOptions.put("useTicketCache", "true");

RequestDecorator requestDecorator = new RequestDecorator(null);
SDKMetadata sdkmeta = new SDKMetadata("java-1.2.3", "1.2.3.4", "someIP");
SplitHttpClient splitHttpClient = SplitFactoryImpl.buildSplitHttpClient("qwer",
splitClientConfig,
sdkmeta,
requestDecorator);
Assert.assertTrue(splitHttpClient instanceof SplitHttpClientKerberosImpl);
}

@Test
public void testBuildOkHttpClient() {
SplitClientConfig splitClientConfig = SplitClientConfig.builder()
.setBlockUntilReadyTimeout(10000)
.authScheme(HttpAuthScheme.KERBEROS)
.kerberosPrincipalName("bilal@localhost")
.proxyPort(6060)
.proxyHost(ENDPOINT)
.build();
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("host", 8080));
OkHttpClient okHttpClient = SplitFactoryImpl.buildOkHttpClient(proxy,
splitClientConfig, loggingInterceptor, Authenticator.NONE);
assertEquals(Authenticator.NONE, okHttpClient.authenticator());
assertEquals(proxy, okHttpClient.proxy());
assertEquals(loggingInterceptor, okHttpClient.interceptors().get(0));
}
}

0 comments on commit 32adc6d

Please sign in to comment.