use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class SimpleSSLTestCase method simpleSSLTestCase.
@Test
public void simpleSSLTestCase() throws IOException, GeneralSecurityException {
DefaultServer.setRootHandler(new HttpHandler() {
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
exchange.getResponseHeaders().put(HttpString.tryFromString("scheme"), exchange.getRequestScheme());
exchange.endExchange();
}
});
DefaultServer.startSSLServer();
TestHttpClient client = new TestHttpClient();
client.setSSLContext(DefaultServer.getClientSSLContext());
try {
HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
HttpResponse result = client.execute(get);
Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Header[] header = result.getHeaders("scheme");
Assert.assertEquals("https", header[0].getValue());
} finally {
client.getConnectionManager().shutdown();
DefaultServer.stopSSLServer();
}
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class BasicAuthenticationTestCase method _testBadUserName.
static void _testBadUserName() throws Exception {
TestHttpClient client = new TestHttpClient();
HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL());
HttpResponse result = client.execute(get);
assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode());
Header[] values = result.getHeaders(WWW_AUTHENTICATE.toString());
String header = getAuthHeader(BASIC, values);
assertEquals(BASIC + " realm=\"Test Realm\"", header);
HttpClientUtils.readResponse(result);
get = new HttpGet(DefaultServer.getDefaultServerURL());
get.addHeader(AUTHORIZATION.toString(), BASIC + " " + FlexBase64.encodeString("badUser:passwordOne".getBytes(), false));
result = client.execute(get);
assertEquals(StatusCodes.UNAUTHORIZED, result.getStatusLine().getStatusCode());
HttpClientUtils.readResponse(result);
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ClientCertRenegotiationTestCase method testClientCertSuccessWithLargePostBody.
@Test
public void testClientCertSuccessWithLargePostBody() throws Exception {
PooledByteBuffer buf = DefaultServer.getBufferPool().allocate();
int requestSize = buf.getBuffer().limit() - 1;
buf.close();
final StringBuilder messageBuilder = new StringBuilder(requestSize);
for (int i = 0; i < requestSize; ++i) {
messageBuilder.append("*");
}
TestHttpClient client = new TestHttpClient();
client.setSSLContext(clientSSLContext);
HttpPost post = new HttpPost(DefaultServer.getDefaultServerSSLAddress());
post.setEntity(new StringEntity(messageBuilder.toString()));
HttpResponse result = client.execute(post);
assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Header[] values = result.getHeaders("ProcessedBy");
assertEquals("ProcessedBy Headers", 1, values.length);
assertEquals("ResponseHandler", values[0].getValue());
values = result.getHeaders("AuthenticatedUser");
assertEquals("AuthenticatedUser Headers", 1, values.length);
assertEquals("CN=Test Client,OU=OU,O=Org,L=City,ST=State,C=GB", values[0].getValue());
HttpClientUtils.readResponse(result);
assertSingleNotificationType(EventType.AUTHENTICATED);
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ClientCertRenegotiationTestCase method testClientCertSuccess.
@Test
public void testClientCertSuccess() throws Exception {
TestHttpClient client = new TestHttpClient();
client.setSSLContext(clientSSLContext);
HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
HttpResponse result = client.execute(get);
assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Header[] values = result.getHeaders("ProcessedBy");
assertEquals("ProcessedBy Headers", 1, values.length);
assertEquals("ResponseHandler", values[0].getValue());
values = result.getHeaders("AuthenticatedUser");
assertEquals("AuthenticatedUser Headers", 1, values.length);
assertEquals("CN=Test Client,OU=OU,O=Org,L=City,ST=State,C=GB", values[0].getValue());
HttpClientUtils.readResponse(result);
assertSingleNotificationType(EventType.AUTHENTICATED);
}
use of io.undertow.testutils.TestHttpClient in project undertow by undertow-io.
the class ClientCertTestCase method testClientCertSuccess.
@Test
public void testClientCertSuccess() throws Exception {
TestHttpClient client = new TestHttpClient();
client.setSSLContext(clientSSLContext);
HttpGet get = new HttpGet(DefaultServer.getDefaultServerSSLAddress());
HttpResponse result = client.execute(get);
assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
Header[] values = result.getHeaders("ProcessedBy");
assertEquals("ProcessedBy Headers", 1, values.length);
assertEquals("ResponseHandler", values[0].getValue());
values = result.getHeaders("AuthenticatedUser");
assertEquals("AuthenticatedUser Headers", 1, values.length);
assertEquals("CN=Test Client,OU=OU,O=Org,L=City,ST=State,C=GB", values[0].getValue());
HttpClientUtils.readResponse(result);
assertSingleNotificationType(EventType.AUTHENTICATED);
}
Aggregations