Search in sources :

Example 51 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class ProtocolMetricsTest method recordsServerSideHttp.

@Test
public void recordsServerSideHttp() {
    styxServer = new StyxServer.Builder().addRoute("/", origin.port()).start();
    HttpResponse response = doGet("/");
    assertThat(response.status(), is(OK));
    assertThat(styxServer.metrics().meter("styx.server.http.requests").getCount(), is(1L));
    assertThat(styxServer.metrics().meter("styx.server.https.requests").getCount(), is(0L));
    assertThat(styxServer.metrics().meter("styx.server.http.responses.200").getCount(), is(1L));
    assertThat(styxServer.metrics().meter("styx.server.https.responses.200").getCount(), is(0L));
}
Also used : StyxServer(com.hotels.styx.testapi.StyxServer) HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test)

Example 52 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class StyxMetrics method downloadJsonString.

private static String downloadJsonString(String host, int port) {
    StyxHttpClient client = new StyxHttpClient.Builder().build();
    HttpResponse response = await(client.sendRequest(get(format("http://%s:%d/admin/metrics", host, port)).build()));
    return response.bodyAs(UTF_8);
}
Also used : StyxHttpClient(com.hotels.styx.client.StyxHttpClient) HttpResponse(com.hotels.styx.api.HttpResponse)

Example 53 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class ClassPathResourceHandlerTest method removesDuplicatePathSeparators.

@Test
void removesDuplicatePathSeparators() {
    HttpResponse response = Mono.from(new ClassPathResourceHandler("/a/prefix/", "/admin/dashboard").handle(get("/a/prefix/expected.txt").build(), requestContext())).block();
    assertThat(response.status(), is(OK));
    assertThat(body(response), is("Foo\nBar\n"));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 54 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class ClassPathResourceHandlerTest method returnsForbiddenIfPrefixedRequestAttemptsToAccessResourcesOutsidePermittedRoot.

@ParameterizedTest
@MethodSource("forbiddenPaths")
void returnsForbiddenIfPrefixedRequestAttemptsToAccessResourcesOutsidePermittedRoot(String path) {
    HttpResponse response = Mono.from(new ClassPathResourceHandler("/admin/dashboard", "/admin/dashboard").handle(get(path).build(), requestContext())).block();
    assertThat(response.status(), is(FORBIDDEN));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 55 with HttpResponse

use of com.hotels.styx.api.HttpResponse in project styx by ExpediaGroup.

the class ClassPathResourceHandlerTest method returns403IfTryingToAccessResourcesOutsidePermittedRoot.

@ParameterizedTest
@MethodSource("forbiddenPaths")
void returns403IfTryingToAccessResourcesOutsidePermittedRoot(String path) {
    HttpResponse response = Mono.from(new ClassPathResourceHandler("/admin/dashboard").handle(get(path).build(), requestContext())).block();
    assertThat(response.status(), is(FORBIDDEN));
}
Also used : HttpResponse(com.hotels.styx.api.HttpResponse) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

HttpResponse (com.hotels.styx.api.HttpResponse)107 Test (org.junit.jupiter.api.Test)99 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)30 HttpRequest (com.hotels.styx.api.HttpRequest)18 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Eventual (com.hotels.styx.api.Eventual)10 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)9 StyxHttpClient (com.hotels.styx.client.StyxHttpClient)8 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)8 TlsSettings (com.hotels.styx.api.extension.service.TlsSettings)7 StyxObjectRecord (com.hotels.styx.StyxObjectRecord)6 HttpHandler (com.hotels.styx.api.HttpHandler)6 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)6 OK (com.hotels.styx.api.HttpResponseStatus.OK)5 HttpClient (com.hotels.styx.client.HttpClient)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 HttpInterceptor (com.hotels.styx.api.HttpInterceptor)4 Plugin (com.hotels.styx.api.plugins.spi.Plugin)4 PluginFactory (com.hotels.styx.api.plugins.spi.PluginFactory)4 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)3