44import io .split .client .impressions .ImpressionsManager ;
55import io .split .client .utils .FileTypeEnum ;
66import io .split .integrations .IntegrationsConfig ;
7+ import io .split .service .SplitHttpClientImpl ;
78import io .split .storages .enums .OperationMode ;
89import io .split .storages .pluggable .domain .UserStorageWrapper ;
910import io .split .telemetry .storage .TelemetryStorage ;
1011import io .split .telemetry .synchronizer .TelemetrySynchronizer ;
1112import junit .framework .TestCase ;
13+ import org .apache .hc .client5 .http .auth .AuthScope ;
14+ import org .apache .hc .client5 .http .auth .BearerToken ;
15+ import org .apache .hc .client5 .http .auth .UsernamePasswordCredentials ;
16+ import org .apache .hc .client5 .http .impl .auth .BasicCredentialsProvider ;
17+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpClient ;
18+ import org .apache .hc .client5 .http .impl .classic .CloseableHttpResponse ;
19+ import org .apache .hc .client5 .http .impl .classic .MinimalHttpClient ;
20+ import org .apache .hc .client5 .http .impl .routing .DefaultProxyRoutePlanner ;
21+ import org .apache .hc .core5 .http .HttpHost ;
1222import org .awaitility .Awaitility ;
1323import org .junit .Assert ;
1424import org .junit .Test ;
2434import java .lang .reflect .Method ;
2535import java .lang .reflect .Modifier ;
2636import java .net .URISyntaxException ;
37+ import java .util .concurrent .ConcurrentHashMap ;
2738import java .util .concurrent .TimeUnit ;
2839
2940
@@ -105,6 +116,37 @@ public void testFactoryInstantiationWithProxy() throws Exception {
105116 assertNotNull (splitFactory .client ());
106117 assertNotNull (splitFactory .manager ());
107118
119+ Field splitHttpClientField = SplitFactoryImpl .class .getDeclaredField ("_splitHttpClient" );
120+ splitHttpClientField .setAccessible (true );
121+ SplitHttpClientImpl client = (SplitHttpClientImpl ) splitHttpClientField .get (splitFactory );
122+
123+ Field httpClientField = SplitHttpClientImpl .class .getDeclaredField ("_client" );
124+ httpClientField .setAccessible (true );
125+ Class <?> InternalHttp = Class .forName ("org.apache.hc.client5.http.impl.classic.InternalHttpClient" );
126+
127+ Field routePlannerField = InternalHttp .getDeclaredField ("routePlanner" );
128+ routePlannerField .setAccessible (true );
129+ DefaultProxyRoutePlanner routePlanner = (DefaultProxyRoutePlanner ) routePlannerField .get (InternalHttp .cast (httpClientField .get (client )));
130+
131+ Field proxyField = DefaultProxyRoutePlanner .class .getDeclaredField ("proxy" );
132+ proxyField .setAccessible (true );
133+ HttpHost proxy = (HttpHost ) proxyField .get (routePlanner );
134+
135+ Assert .assertEquals ("http" , proxy .getSchemeName ());
136+ Assert .assertEquals (ENDPOINT , proxy .getHostName ());
137+ Assert .assertEquals (6060 , proxy .getPort ());
138+
139+ Field credentialsProviderField = InternalHttp .getDeclaredField ("credentialsProvider" );
140+ credentialsProviderField .setAccessible (true );
141+ BasicCredentialsProvider credentialsProvider = (BasicCredentialsProvider ) credentialsProviderField .get (InternalHttp .cast (httpClientField .get (client )));
142+
143+ Field credMapField = BasicCredentialsProvider .class .getDeclaredField ("credMap" );
144+ credMapField .setAccessible (true );
145+ ConcurrentHashMap <AuthScope , UsernamePasswordCredentials > credMap = (ConcurrentHashMap ) credMapField .get (credentialsProvider );
146+
147+ Assert .assertEquals ("test" , credMap .entrySet ().stream ().iterator ().next ().getValue ().getUserName ());
148+ assertNotNull (credMap .entrySet ().stream ().iterator ().next ().getValue ().getUserPassword ());
149+
108150 splitClientConfig = SplitClientConfig .builder ()
109151 .enableDebug ()
110152 .impressionsMode (ImpressionsManager .Mode .DEBUG )
@@ -114,13 +156,31 @@ public void testFactoryInstantiationWithProxy() throws Exception {
114156 .authServiceURL (AUTH_SERVICE )
115157 .setBlockUntilReadyTimeout (1000 )
116158 .proxyPort (6060 )
117- .proxyToken ("12345 " )
159+ .proxyToken ("123456789 " )
118160 .proxyHost (ENDPOINT )
119161 .build ();
120162 SplitFactoryImpl splitFactory2 = new SplitFactoryImpl (API_KEY , splitClientConfig );
121163 assertNotNull (splitFactory2 .client ());
122164 assertNotNull (splitFactory2 .manager ());
123165
166+ Field splitHttpClientField2 = SplitFactoryImpl .class .getDeclaredField ("_splitHttpClient" );
167+ splitHttpClientField2 .setAccessible (true );
168+ SplitHttpClientImpl client2 = (SplitHttpClientImpl ) splitHttpClientField2 .get (splitFactory2 );
169+
170+ Field httpClientField2 = SplitHttpClientImpl .class .getDeclaredField ("_client" );
171+ httpClientField2 .setAccessible (true );
172+ Class <?> InternalHttp2 = Class .forName ("org.apache.hc.client5.http.impl.classic.InternalHttpClient" );
173+
174+ Field credentialsProviderField2 = InternalHttp .getDeclaredField ("credentialsProvider" );
175+ credentialsProviderField2 .setAccessible (true );
176+ BasicCredentialsProvider credentialsProvider2 = (BasicCredentialsProvider ) credentialsProviderField2 .get (InternalHttp2 .cast (httpClientField2 .get (client2 )));
177+
178+ Field credMapField2 = BasicCredentialsProvider .class .getDeclaredField ("credMap" );
179+ credMapField2 .setAccessible (true );
180+ ConcurrentHashMap <AuthScope , BearerToken > credMap2 = (ConcurrentHashMap ) credMapField2 .get (credentialsProvider2 );
181+
182+ Assert .assertEquals ("123456789" , credMap2 .entrySet ().stream ().iterator ().next ().getValue ().getToken ());
183+
124184 splitClientConfig = SplitClientConfig .builder ()
125185 .enableDebug ()
126186 .impressionsMode (ImpressionsManager .Mode .DEBUG )
0 commit comments