2727package org .apache .hc .client5 .testing .compatibility .sync ;
2828
2929
30+ import static org .junit .jupiter .api .Assumptions .assumeFalse ;
31+
32+ import javax .security .auth .Subject ;
33+
3034import org .apache .hc .client5 .http .ContextBuilder ;
3135import org .apache .hc .client5 .http .auth .AuthScope ;
3236import org .apache .hc .client5 .http .auth .Credentials ;
4145import org .apache .hc .client5 .testing .compatibility .spnego .SpnegoAuthenticationStrategy ;
4246import org .apache .hc .client5 .testing .compatibility .spnego .SpnegoTestUtil ;
4347import org .apache .hc .client5 .testing .extension .sync .HttpClientResource ;
48+ import org .apache .hc .client5 .testing .util .SecurityUtils ;
4449import org .apache .hc .core5 .http .ClassicHttpRequest ;
4550import org .apache .hc .core5 .http .ClassicHttpResponse ;
4651import org .apache .hc .core5 .http .HttpHeaders ;
@@ -59,16 +64,18 @@ public abstract class HttpClientCompatibilityTest {
5964 private final HttpClientResource clientResource ;
6065 private final CredentialsStore credentialsProvider ;
6166 private final Credentials targetCreds ;
67+ private Subject callAs ;
6268 private String secretPath = "/private/big-secret.txt" ;
6369
64- public HttpClientCompatibilityTest (final HttpHost target , final Credentials targetCreds , final HttpHost proxy , final Credentials proxyCreds ) throws Exception {
70+ public HttpClientCompatibilityTest (final HttpHost target , final Credentials targetCreds , final HttpHost proxy , final Credentials proxyCreds , final Subject callAs ) throws Exception {
6571 this .target = target ;
6672 this .targetCreds = targetCreds ;
73+ this .callAs = callAs ;
6774 this .credentialsProvider = new BasicCredentialsProvider ();
6875 this .clientResource = new HttpClientResource ();
69- if (targetCreds != null ) {
76+ if (targetCreds != null || callAs != null ) {
7077 //this.setCredentials(new AuthScope(target), targetCreds);
71- if (targetCreds instanceof GssCredentials ) {
78+ if (targetCreds instanceof GssCredentials || callAs != null ) {
7279 secretPath = "/private_spnego/big-secret.txt" ;
7380 this .clientResource .configure (builder -> builder
7481 .setTargetAuthenticationStrategy (new SpnegoAuthenticationStrategy ())
@@ -183,6 +190,19 @@ void test_wrong_target_credentials() throws Exception {
183190 void test_correct_target_credentials () throws Exception {
184191 setCredentials (
185192 new AuthScope (target ), targetCreds );
193+ test_correct_target_credentials_int ();
194+ }
195+
196+ @ Test
197+ void test_correct_target_credentials_call_as () throws Exception {
198+ assumeFalse (callAs == null );
199+ SecurityUtils .callAs (callAs , () -> {
200+ test_correct_target_credentials_int ();
201+ return 0 ;
202+ });
203+ }
204+
205+ private void test_correct_target_credentials_int () throws Exception {
186206 final CloseableHttpClient client = client ();
187207 final HttpClientContext context = context ();
188208
@@ -197,6 +217,19 @@ void test_correct_target_credentials() throws Exception {
197217 void test_correct_target_credentials_no_keep_alive () throws Exception {
198218 setCredentials (
199219 new AuthScope (target ), targetCreds );
220+ test_correct_target_credentials_no_keep_alive_int ();
221+ }
222+
223+ @ Test
224+ void test_correct_target_credentials_no_keep_alive_call_as () throws Exception {
225+ assumeFalse (callAs == null );
226+ SecurityUtils .callAs (callAs , () -> {
227+ test_correct_target_credentials_int ();
228+ return 0 ;
229+ });
230+ }
231+
232+ private void test_correct_target_credentials_no_keep_alive_int () throws Exception {
200233 final CloseableHttpClient client = client ();
201234 final HttpClientContext context = context ();
202235
@@ -208,5 +241,4 @@ void test_correct_target_credentials_no_keep_alive() throws Exception {
208241 EntityUtils .consume (response .getEntity ());
209242 }
210243 }
211-
212244}
0 commit comments