Search in sources :

Example 36 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Example 37 with AbstractConfiguration

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());
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) HttpResponse(com.netflix.client.http.HttpResponse) URI(java.net.URI)

Example 38 with AbstractConfiguration

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);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) URI(java.net.URI) Test(org.junit.Test)

Example 39 with AbstractConfiguration

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);
    }
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) HttpRequest(com.netflix.client.http.HttpRequest) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) MultivaluedMapImpl(com.sun.jersey.core.util.MultivaluedMapImpl) URI(java.net.URI) Test(org.junit.Test)

Example 40 with AbstractConfiguration

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);
}
Also used : AbstractConfiguration(org.apache.commons.configuration.AbstractConfiguration) FileOutputStream(java.io.FileOutputStream) File(java.io.File) KeyStore(java.security.KeyStore) Certificate(java.security.cert.Certificate) Test(org.junit.Test)

Aggregations

AbstractConfiguration (org.apache.commons.configuration.AbstractConfiguration)80 Test (org.junit.Test)29 ConcurrentCompositeConfiguration (com.netflix.config.ConcurrentCompositeConfiguration)18 BeforeClass (org.junit.BeforeClass)10 Configuration (org.apache.commons.configuration.Configuration)9 URI (java.net.URI)6 BaseConfiguration (org.apache.commons.configuration.BaseConfiguration)6 HttpRequest (com.netflix.client.http.HttpRequest)5 ArrayList (java.util.ArrayList)5 DynamicConfiguration (com.netflix.config.DynamicConfiguration)4 EnvironmentConfiguration (org.apache.commons.configuration.EnvironmentConfiguration)4 SystemConfiguration (org.apache.commons.configuration.SystemConfiguration)4 HttpResponse (com.netflix.client.http.HttpResponse)3 ConcurrentMapConfiguration (com.netflix.config.ConcurrentMapConfiguration)3 ExpandedConfigurationListenerAdapter (com.netflix.config.ExpandedConfigurationListenerAdapter)3 LinkedHashMap (java.util.LinkedHashMap)3 Properties (java.util.Properties)3 AggregatedConfiguration (com.netflix.config.AggregatedConfiguration)2 ConfigurationManager (com.netflix.config.ConfigurationManager)2 DynamicURLConfiguration (com.netflix.config.DynamicURLConfiguration)2