use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class SecureAcceptAllGetTest method testNegativeAcceptAllSSLSocketFactory.
@Test
public void testNegativeAcceptAllSSLSocketFactory() throws Exception {
// test exception is thrown connecting to a random SSL endpoint without explicitly setting factory to allow all
String name = "GetPostSecureTest" + ".testNegativeAcceptAllSSLSocketFactory";
// don't set any interesting properties -- really we're just setting the defaults
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
TEST_SERVER.accept();
URI getUri = new URI(TEST_SERVICE_URI + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
boolean foundCause = false;
try {
rc.execute(request);
} catch (Throwable t) {
while (t != null && !foundCause) {
if (t instanceof SSLPeerUnverifiedException && t.getMessage().startsWith("peer not authenticated")) {
foundCause = true;
break;
}
t = t.getCause();
}
}
assertTrue(foundCause);
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class SecureGetTest method testClientRejectsWrongServer.
@Test
public void testClientRejectsWrongServer() throws Exception {
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testClientRejectsWrongServer";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT2));
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "false");
// <--
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
testServer2.accept();
URI getUri = new URI(SERVICE_URI2 + "test/");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
try {
rc.execute(request);
fail("expecting ssl hostname validation error");
} catch (ClientHandlerException che) {
assertTrue(che.getMessage().indexOf("peer not authenticated") > -1);
}
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class SecureGetTest method testFailsWithHostNameValidationOn.
@Test
public void testFailsWithHostNameValidationOn() throws Exception {
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest" + ".testFailsWithHostNameValidationOn";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.SecurePort, Integer.toString(PORT1));
// <--
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsHostnameValidationRequired, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsClientAuthRequired, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, FILE_KS1.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, PASSWORD);
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStore, FILE_TS1.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.TrustStorePassword, PASSWORD);
RestClient rc = (RestClient) ClientFactory.getNamedClient(name);
testServer1.accept();
URI getUri = new URI(SERVICE_URI1 + "test/");
MultivaluedMapImpl params = new MultivaluedMapImpl();
params.add("name", "test");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
try {
rc.execute(request);
fail("expecting ssl hostname validation error");
} catch (ClientHandlerException che) {
assertTrue(che.getMessage().indexOf("hostname in certificate didn't match") > -1);
}
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class FollowRedirectTest method testRedirectFollowed.
@Test
public void testRedirectFollowed() throws Exception {
IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues("myclient2").set(IClientConfigKey.Keys.FollowRedirects, Boolean.TRUE);
ClientFactory.registerClientFromProperties("myclient2", config);
com.netflix.niws.client.http.RestClient client = (com.netflix.niws.client.http.RestClient) ClientFactory.getNamedClient("myclient2");
HttpRequest request = HttpRequest.newBuilder().uri(new URI("http://localhost:" + redirectingServer.getPort())).build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
}
use of com.netflix.client.http.HttpRequest in project ribbon by Netflix.
the class GetPostTest method testGet.
@Test
public void testGet() throws Exception {
URI getUri = new URI(SERVICE_URI + "test/getObject");
MultivaluedMapImpl params = new MultivaluedMapImpl();
params.add("name", "test");
HttpRequest request = HttpRequest.newBuilder().uri(getUri).queryParams("name", "test").build();
HttpResponse response = client.execute(request);
assertEquals(200, response.getStatus());
assertTrue(response.getEntity(TestObject.class).name.equals("test"));
}
Aggregations