Search in sources :

Example 1 with TlsSettings

use of com.hotels.styx.api.extension.service.TlsSettings in project styx by ExpediaGroup.

the class StyxHttpClientTest method overridesTlsSettingsWithSecureBooleanFalse.

/*
     * StyxHttpClientTransaction
     * - secure(false) disables TLS protection
     */
@Test
public void overridesTlsSettingsWithSecureBooleanFalse() throws ExecutionException, InterruptedException {
    StyxHttpClient client = new StyxHttpClient.Builder().tlsSettings(new TlsSettings.Builder().build()).build();
    HttpResponse response = client.secure(false).send(httpRequest).get();
    assertThat(response.status(), is(OK));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test)

Example 2 with TlsSettings

use of com.hotels.styx.api.extension.service.TlsSettings in project styx by ExpediaGroup.

the class StyxServerTest method proxiesToOriginViaHttps.

@Test
public void proxiesToOriginViaHttps() {
    BackendService backendService = new BackendService().ssl().addOrigin(secureOriginServer.httpsPort());
    styxServer = new StyxServer.Builder().addRoute("/", backendService).start();
    StyxHttpClient tlsClient = new StyxHttpClient.Builder().tlsSettings(new TlsSettings.Builder().build()).build();
    HttpResponse response = await(tlsClient.sendRequest(get(format("https://localhost:%d/", styxServer.proxyHttpsPort())).build()));
    assertThat(response.status(), is(OK));
    configureFor(secureOriginServer.port());
    WireMock.verify(getRequestedFor(urlPathEqualTo("/")));
}
Also used : StyxHttpClient(com.hotels.styx.client.StyxHttpClient) HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test)

Example 3 with TlsSettings

use of com.hotels.styx.api.extension.service.TlsSettings in project styx by ExpediaGroup.

the class TlsSettingsTest method obtainsTrustStorePathFromSystemProperty.

@Test
public void obtainsTrustStorePathFromSystemProperty() throws Exception {
    System.setProperty("javax.net.ssl.trustStore", "/path/to/myTruststore");
    System.setProperty("javax.net.ssl.trustStorePassword", "myPassword");
    TlsSettings tlsSettings = new TlsSettings.Builder().build();
    assertThat(tlsSettings.trustStorePath(), is("/path/to/myTruststore"));
    assertThat(tlsSettings.trustStorePassword(), is("myPassword".toCharArray()));
}
Also used : TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test)

Example 4 with TlsSettings

use of com.hotels.styx.api.extension.service.TlsSettings in project styx by ExpediaGroup.

the class TlsSettingsTest method hashCodeConsidersProtocols.

@Test
public void hashCodeConsidersProtocols() throws Exception {
    TlsSettings tlsSettings1 = new TlsSettings.Builder().protocols(List.of("TLSv1", "TLSv1.1")).build();
    TlsSettings tlsSettings2 = new TlsSettings.Builder().build();
    assertThat(tlsSettings1.hashCode() == tlsSettings2.hashCode(), is(false));
    tlsSettings1 = new TlsSettings.Builder().protocols(List.of("TLSv1", "TLSv1.1")).build();
    tlsSettings2 = new TlsSettings.Builder().protocols(List.of("TLSv1", "TLSv1.1")).build();
    assertThat(tlsSettings1.hashCode() == tlsSettings2.hashCode(), is(true));
}
Also used : TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test)

Example 5 with TlsSettings

use of com.hotels.styx.api.extension.service.TlsSettings in project styx by ExpediaGroup.

the class TlsSettingsTest method isImmutable.

@Test
public void isImmutable() throws Exception {
    List<String> protocols = new ArrayList<String>() {

        {
            add("TLSv1");
        }
    };
    List<String> cipherSuites = new ArrayList<String>() {

        {
            add("x");
        }
    };
    Certificate[] certificates = new Certificate[] { certificate("x", "x") };
    TlsSettings tlsSettings = new TlsSettings.Builder().additionalCerts(certificates).protocols(protocols).cipherSuites(cipherSuites).build();
    protocols.add("TLSv1.2");
    cipherSuites.add("y");
    certificates[0] = certificate("y", "y");
    assertThat(tlsSettings.protocols(), equalTo(List.of("TLSv1")));
    assertThat(tlsSettings.cipherSuites(), equalTo(List.of("x")));
    assertThat(tlsSettings.additionalCerts(), equalTo(Set.of(certificate("x", "x"))));
}
Also used : ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) Certificate(com.hotels.styx.api.extension.service.Certificate) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test)

Aggregations

TlsSettings (com.hotels.styx.api.extension.service.TlsSettings)14 Test (org.junit.jupiter.api.Test)14 HttpResponse (com.hotels.styx.api.HttpResponse)4 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)4 Matchers.containsString (org.hamcrest.Matchers.containsString)3 StyxHttpClient (com.hotels.styx.client.StyxHttpClient)2 Certificate (com.hotels.styx.api.extension.service.Certificate)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1