Search in sources :

Example 86 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class HttpsBrowserProxyAcceptanceTest method canTrustSpecificTargetHosts.

@Test
public void canTrustSpecificTargetHosts() {
    WireMockServer scepticalProxy = new WireMockServer(wireMockConfig().dynamicPort().enableBrowserProxying(true).trustedProxyTargets("localhost"));
    try {
        scepticalProxy.start();
        target.stubFor(get(urlEqualTo("/whatever")).willReturn(aResponse().withBody("Got it")));
        WireMockResponse response = testClient.getViaProxy(target.url("/whatever"), scepticalProxy.port());
        assertThat(response.statusCode(), is(200));
        assertThat(response.content(), is("Got it"));
    } finally {
        scepticalProxy.stop();
    }
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 87 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class HttpsBrowserProxyAcceptanceTest method certificateAuthorityCertCanBeDownloaded.

@Test
@DisabledForJreRange(min = JRE.JAVA_17, disabledReason = "does not support generating certificates at runtime")
public void certificateAuthorityCertCanBeDownloaded() throws Exception {
    WireMockTestClient proxyTestClient = new WireMockTestClient(proxy.getPort());
    WireMockResponse certResponse = proxyTestClient.get("/__admin/certs/wiremock-ca.crt");
    assertEquals(200, certResponse.statusCode());
    assertEquals("application/x-pem-file", certResponse.firstHeader("Content-Type"));
    Certificate cert = decode(certResponse.content());
    X509KeyStore keyStore = new X509KeyStore(HttpsAcceptanceTest.readKeyStore(NO_PREEXISTING_KEYSTORE_PATH, "password"), "password".toCharArray());
    assertEquals(keyStore.getCertificateAuthority().certificateChain()[0], cert);
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) WireMockTestClient(com.github.tomakehurst.wiremock.testsupport.WireMockTestClient) X509KeyStore(com.github.tomakehurst.wiremock.http.ssl.X509KeyStore) Certificate(java.security.cert.Certificate) Test(org.junit.jupiter.api.Test) DisabledForJreRange(org.junit.jupiter.api.condition.DisabledForJreRange)

Example 88 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class MappingsAcceptanceTest method mappingWithStatusOnlyResponseIsCreatedAndReturned.

@Test
public void mappingWithStatusOnlyResponseIsCreatedAndReturned() {
    testClient.addResponse(MappingJsonSamples.STATUS_ONLY_MAPPING_REQUEST);
    WireMockResponse response = testClient.put("/status/only");
    assertThat(response.statusCode(), is(204));
    assertNull(response.content());
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 89 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class MappingsAcceptanceTest method resetToDefaultRestoresOldMeaningOfDefault.

@Test
public void resetToDefaultRestoresOldMeaningOfDefault() {
    add200ResponseFor("/testmapping");
    WireMockResponse response1 = testClient.get("/testmapping");
    assertThat(response1.content(), is(""));
    testClient.resetDefaultMappings();
    WireMockResponse response2 = testClient.get("/testmapping");
    assertThat(response2.content(), is("default test mapping"));
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Example 90 with WireMockResponse

use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.

the class MappingsAcceptanceTest method responseContainsContentLengthAndChunkedEncodingHeadersIfItIsDefinedInTheMapping.

@Test
public void responseContainsContentLengthAndChunkedEncodingHeadersIfItIsDefinedInTheMapping() throws Exception {
    testClient.addResponse("{ 													\n" + "	\"request\": {									\n" + "		\"method\": \"GET\",						\n" + "		\"url\": \"/with/body\"						\n" + "	},												\n" + "	\"response\": {									\n" + "		\"status\": 200,							\n" + "		\"headers\": {								\n" + "			\"Content-Length\": \"12\"		        \n" + "		},											\n" + "		\"body\": \"Some content\"					\n" + "	}												\n" + "}													");
    WireMockResponse response = testClient.get("/with/body");
    assertThat(response.firstHeader("Content-Length"), is("12"));
    assertFalse(response.headers().containsKey("Transfer-Encoding"), "expected Transfer-Encoding head to be absent");
}
Also used : WireMockResponse(com.github.tomakehurst.wiremock.testsupport.WireMockResponse) Test(org.junit.jupiter.api.Test)

Aggregations

WireMockResponse (com.github.tomakehurst.wiremock.testsupport.WireMockResponse)172 Test (org.junit.jupiter.api.Test)168 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 Errors (com.github.tomakehurst.wiremock.common.Errors)11 WireMockTestClient (com.github.tomakehurst.wiremock.testsupport.WireMockTestClient)9 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)7 UUID (java.util.UUID)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Stopwatch (com.google.common.base.Stopwatch)3 ByteArrayEntity (org.apache.hc.core5.http.io.entity.ByteArrayEntity)3 StringEntity (org.apache.hc.core5.http.io.entity.StringEntity)3 ConsoleNotifier (com.github.tomakehurst.wiremock.common.ConsoleNotifier)2 Request (com.github.tomakehurst.wiremock.http.Request)2 JsonVerifiable (com.toomuchcoding.jsonassert.JsonVerifiable)2 IOException (java.io.IOException)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 FileSource (com.github.tomakehurst.wiremock.common.FileSource)1 SingleRootFileSource (com.github.tomakehurst.wiremock.common.SingleRootFileSource)1 Admin (com.github.tomakehurst.wiremock.core.Admin)1