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();
}
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);
}
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)));
}
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;
}
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);
}
Aggregations