Skip to content

Commit 068cd9a

Browse files
committed
Add tests for Classic client using the Subject from the Security Context
1 parent 4b626b1 commit 068cd9a

File tree

2 files changed

+48
-8
lines changed

2 files changed

+48
-8
lines changed

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/compatibility/ApacheHTTPDSquidCompatibilityIT.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public ClassicDirectHttpPw() throws Exception {
135135
super(targetContainerHost(),
136136
new UsernamePasswordCredentials("testuser", "nopassword".toCharArray()),
137137
null,
138+
null,
138139
null);
139140
}
140141

@@ -148,7 +149,8 @@ public ClassicDirectHttpSpnego() throws Exception {
148149
super(targetContainerHost(),
149150
SpnegoTestUtil.createCredentials(spnegoSubject),
150151
null,
151-
null);
152+
null,
153+
spnegoSubject);
152154
}
153155

154156
}
@@ -161,6 +163,7 @@ public ClassicViaProxyHttp() throws Exception {
161163
super(targetInternalHost(),
162164
new UsernamePasswordCredentials("testuser", "nopassword".toCharArray()),
163165
proxyContainerHost(),
166+
null,
164167
null);
165168
}
166169

@@ -174,6 +177,7 @@ public ClassicDirectHttpTlsPw() throws Exception {
174177
super(targetContainerTlsHost(),
175178
new UsernamePasswordCredentials("testuser", "nopassword".toCharArray()),
176179
null,
180+
null,
177181
null);
178182
}
179183

@@ -187,7 +191,8 @@ public ClassicDirectHttpTlsSpnego() throws Exception {
187191
super(targetContainerTlsHost(),
188192
SpnegoTestUtil.createCredentials(spnegoSubject),
189193
null,
190-
null);
194+
null,
195+
spnegoSubject);
191196
}
192197

193198
}
@@ -200,6 +205,7 @@ public ClassicViaProxyHttpTls() throws Exception {
200205
super(targetInternalTlsHost(),
201206
new UsernamePasswordCredentials("testuser", "nopassword".toCharArray()),
202207
proxyContainerHost(),
208+
null,
203209
null);
204210
}
205211

@@ -213,7 +219,8 @@ public ClassicViaPwProtectedProxyHttpTls() throws Exception {
213219
super(targetInternalTlsHost(),
214220
new UsernamePasswordCredentials("testuser", "nopassword".toCharArray()),
215221
proxyAuthenticatedContainerHost(),
216-
new UsernamePasswordCredentials("squid", "nopassword".toCharArray()));
222+
new UsernamePasswordCredentials("squid", "nopassword".toCharArray()),
223+
null);
217224
}
218225

219226
}
@@ -226,7 +233,8 @@ public ClassicViaSpnegoProtectedProxyHttpTls() throws Exception {
226233
super(targetInternalTlsHost(),
227234
new UsernamePasswordCredentials("testuser", "nopassword".toCharArray()),
228235
proxyAuthenticatedContainerHost(),
229-
SpnegoTestUtil.createCredentials(spnegoSubject));
236+
SpnegoTestUtil.createCredentials(spnegoSubject),
237+
null);
230238
}
231239

232240
}

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/compatibility/sync/HttpClientCompatibilityTest.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
package 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+
3034
import org.apache.hc.client5.http.ContextBuilder;
3135
import org.apache.hc.client5.http.auth.AuthScope;
3236
import org.apache.hc.client5.http.auth.Credentials;
@@ -41,6 +45,7 @@
4145
import org.apache.hc.client5.testing.compatibility.spnego.SpnegoAuthenticationStrategy;
4246
import org.apache.hc.client5.testing.compatibility.spnego.SpnegoTestUtil;
4347
import org.apache.hc.client5.testing.extension.sync.HttpClientResource;
48+
import org.apache.hc.client5.testing.util.SecurityUtils;
4449
import org.apache.hc.core5.http.ClassicHttpRequest;
4550
import org.apache.hc.core5.http.ClassicHttpResponse;
4651
import 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

Comments
 (0)