Search in sources :

Example 1 with Cookie

use of com.github.tomakehurst.wiremock.http.Cookie in project common-java-modules by navikt.

the class CsrfIntegrationTest method smoketest.

@Test
public void smoketest() {
    givenThat(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withBody("ok!")));
    RestUtils.withClient(c -> c.target("http://localhost:" + wireMockRule.port()).request().cookie(REGULAR_COOKIE, "someValue").get(String.class));
    List<LoggedRequest> requests = wireMockRule.findRequestsMatching(everything()).getRequests();
    assertThat(requests).hasSize(1);
    LoggedRequest loggedRequest = requests.get(0);
    Cookie csrfCookie = loggedRequest.getCookies().get(CSRF_COOKIE_NAVN);
    assertThat(csrfCookie).isNotNull();
    assertThat(loggedRequest.getHeader(CSRF_COOKIE_NAVN)).isEqualTo(csrfCookie.getValue());
    Cookie regularCookie = loggedRequest.getCookies().get(REGULAR_COOKIE);
    assertThat(regularCookie).isNotNull();
    assertThat(regularCookie.getValue()).isNotNull();
}
Also used : Cookie(com.github.tomakehurst.wiremock.http.Cookie) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Test(org.junit.Test)

Example 2 with Cookie

use of com.github.tomakehurst.wiremock.http.Cookie in project common-java-modules by navikt.

the class CookieIntegrationTest method assertCookies.

private void assertCookies() {
    List<LoggedRequest> requests = wireMockRule.findRequestsMatching(everything()).getRequests();
    assertThat(requests).hasSize(1);
    LoggedRequest loggedRequest = requests.get(0);
    String header = loggedRequest.getHeader(COOKIE);
    assertThat(header).isEqualTo("test-cookie-1=test-value; test-cookie-2=test-value; NAV_CSRF_PROTECTION=csrf-token");
    Cookie cookie1 = loggedRequest.getCookies().get(TEST_COOKIE_1);
    assertThat(cookie1).isNotNull();
    assertThat(cookie1.getValue()).isEqualTo(TEST_COOKIE_VALUE);
    Cookie cookie2 = loggedRequest.getCookies().get(TEST_COOKIE_2);
    assertThat(cookie2).isNotNull();
    assertThat(cookie2.getValue()).isEqualTo(TEST_COOKIE_VALUE);
}
Also used : Cookie(com.github.tomakehurst.wiremock.http.Cookie) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest)

Example 3 with Cookie

use of com.github.tomakehurst.wiremock.http.Cookie in project wiremock by wiremock.

the class WireMockHttpServletRequestAdapter method getCookies.

@Override
public Map<String, Cookie> getCookies() {
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.builder();
    javax.servlet.http.Cookie[] cookies = firstNonNull(request.getCookies(), new javax.servlet.http.Cookie[0]);
    for (javax.servlet.http.Cookie cookie : cookies) {
        builder.put(cookie.getName(), cookie.getValue());
    }
    return Maps.transformValues(builder.build().asMap(), input -> new Cookie(null, ImmutableList.copyOf(input)));
}
Also used : Cookie(com.github.tomakehurst.wiremock.http.Cookie)

Example 4 with Cookie

use of com.github.tomakehurst.wiremock.http.Cookie in project spring-cloud-netflix by spring-cloud.

the class WireMockRestAssuredRequestAdapter method getCookies.

@Override
public Map<String, Cookie> getCookies() {
    Map<String, Cookie> map = new LinkedHashMap<>();
    for (io.restassured.http.Cookie cookie : request.getCookies()) {
        Cookie value = new Cookie(cookie.getValue());
        map.put(cookie.getName(), value);
    }
    return map;
}
Also used : Cookie(com.github.tomakehurst.wiremock.http.Cookie) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with Cookie

use of com.github.tomakehurst.wiremock.http.Cookie in project wiremock by wiremock.

the class LoggedRequestTest method jsonRepresentation.

@Test
public void jsonRepresentation() throws Exception {
    HttpHeaders headers = new HttpHeaders(httpHeader("Accept-Language", "en-us,en;q=0.5"));
    Map<String, Cookie> cookies = ImmutableMap.of("first_cookie", new Cookie("yum"), "monster_cookie", new Cookie("COOKIIIEESS"));
    Date loggedDate = Dates.parse(DATE);
    LoggedRequest loggedRequest = new LoggedRequest("/my/url", "http://mydomain.com/my/url", RequestMethod.GET, "25.10.18.11", headers, cookies, true, loggedDate, REQUEST_BODY_AS_BASE64, null, null);
    String expectedJson = String.format(JSON_EXAMPLE, loggedDate.getTime());
    JSONAssert.assertEquals(expectedJson, Json.write(loggedRequest), false);
}
Also used : Cookie(com.github.tomakehurst.wiremock.http.Cookie) HttpHeaders(com.github.tomakehurst.wiremock.http.HttpHeaders) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

Cookie (com.github.tomakehurst.wiremock.http.Cookie)6 HttpHeaders (com.github.tomakehurst.wiremock.http.HttpHeaders)2 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)2 ResponseDefinitionBuilder (com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder)1 Body (com.github.tomakehurst.wiremock.http.Body)1 ContentTypeHeader (com.github.tomakehurst.wiremock.http.ContentTypeHeader)1 HttpHeader (com.github.tomakehurst.wiremock.http.HttpHeader)1 QueryParameter (com.github.tomakehurst.wiremock.http.QueryParameter)1 Request (com.github.tomakehurst.wiremock.http.Request)1 RequestMethod (com.github.tomakehurst.wiremock.http.RequestMethod)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1