use of org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class ArchaiusPropertyResolverTest method mapFromPrefixedKeys.
@Test
public void mapFromPrefixedKeys() {
final String prefix = "client.ribbon." + testName.getMethodName();
final AbstractConfiguration config = ConfigurationManager.getConfigInstance();
config.setProperty(prefix + ".a", "1");
config.setProperty(prefix + ".b", "2");
config.setProperty(prefix + ".c", "3");
final ArchaiusPropertyResolver resolver = ArchaiusPropertyResolver.INSTANCE;
final Map<String, String> map = new TreeMap<>();
resolver.forEach(prefix, map::put);
final Map<String, String> expected = new TreeMap<>();
expected.put("a", "1");
expected.put("b", "2");
expected.put("c", "3");
Assert.assertEquals(expected, map);
}
use of org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class SecureAcceptAllGetTest method testPositiveAcceptAllSSLSocketFactory.
@Test
public void testPositiveAcceptAllSSLSocketFactory() throws Exception {
// test connection succeeds connecting to a random SSL endpoint with allow all SSL factory
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = "GetPostSecureTest." + testName.getMethodName();
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.CustomSSLSocketFactoryClassName, "com.netflix.http4.ssl.AcceptAllSocketFactory");
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();
HttpResponse response = rc.execute(request);
assertEquals(200, response.getStatus());
}
use of org.apache.commons.configuration.AbstractConfiguration 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(testServer2.getPort()));
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 org.apache.commons.configuration.AbstractConfiguration 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(testServer2.getPort()));
// <--
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 org.apache.commons.configuration.AbstractConfiguration in project ribbon by Netflix.
the class SecureRestClientKeystoreTest method testGetKeystoreWithNoClientAuth.
@Test
public void testGetKeystoreWithNoClientAuth() throws Exception {
// jks format
byte[] dummyTruststore = Base64.decode(SecureGetTest.TEST_TS1);
byte[] dummyKeystore = Base64.decode(SecureGetTest.TEST_KS1);
File tempKeystore = File.createTempFile(this.getClass().getName(), ".keystore");
File tempTruststore = File.createTempFile(this.getClass().getName(), ".truststore");
FileOutputStream keystoreFileOut = new FileOutputStream(tempKeystore);
try {
keystoreFileOut.write(dummyKeystore);
} finally {
keystoreFileOut.close();
}
FileOutputStream truststoreFileOut = new FileOutputStream(tempTruststore);
try {
truststoreFileOut.write(dummyTruststore);
} finally {
truststoreFileOut.close();
}
AbstractConfiguration cm = ConfigurationManager.getConfigInstance();
String name = this.getClass().getName() + ".test2";
String configPrefix = name + "." + "ribbon";
cm.setProperty(configPrefix + "." + CommonClientConfigKey.IsSecure, "true");
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStore, tempKeystore.getAbsolutePath());
cm.setProperty(configPrefix + "." + CommonClientConfigKey.KeyStorePassword, "changeit");
RestClient client = (RestClient) ClientFactory.getNamedClient(name);
KeyStore keyStore = client.getKeyStore();
Certificate cert = keyStore.getCertificate("ribbon_key");
assertNotNull(cert);
}
Aggregations