use of io.restassured.http.Cookie in project rest-assured by rest-assured.
the class RequestPrinter method addCookies.
private static void addCookies(FilterableRequestSpecification requestSpec, StringBuilder builder) {
builder.append("Cookies:");
final Cookies cookies = requestSpec.getCookies();
if (!cookies.exist()) {
appendTwoTabs(builder).append(NONE).append(NEW_LINE);
}
int i = 0;
for (Cookie cookie : cookies) {
if (i++ == 0) {
appendTwoTabs(builder);
} else {
appendFourTabs(builder);
}
builder.append(cookie).append(NEW_LINE);
}
}
use of io.restassured.http.Cookie in project rest-assured by rest-assured.
the class CookieFilterTest method addCookiesToMatchingUrlRequest.
@Test
public void addCookiesToMatchingUrlRequest() {
cookieFilter.filter(reqOriginDomain, response, testFilterContext);
cookieFilter.filter(reqOriginDomain, response, testFilterContext);
assertThat(reqOriginDomain.getCookies().size(), Matchers.is(1));
for (Cookie cookie : reqOriginDomain.getCookies()) {
assertThat(cookie.getName(), Matchers.is("cookieName"));
assertThat(cookie.getValue(), Matchers.is("cookieValue"));
}
}
use of io.restassured.http.Cookie in project rest-assured by rest-assured.
the class MockMvcRequestSpecificationMergingTest method cookies_are_merged_when_defined_in_specification.
@Test
public void cookies_are_merged_when_defined_in_specification() {
// Given
Cookie otherCookie = new Cookie.Builder("cookie1", "value1").build();
Cookie thisCookie = new Cookie.Builder("cookie2", "value2").build();
MockMvcRequestSpecification specToMerge = new MockMvcRequestSpecBuilder().addCookie(otherCookie).build();
// When
MockMvcRequestSpecification spec = RestAssuredMockMvc.given().cookie(thisCookie).spec(specToMerge);
// Then
Assertions.assertThat(implOf(spec).getCookies()).containsOnly(thisCookie, otherCookie);
}
use of io.restassured.http.Cookie in project rest-assured by rest-assured.
the class CookieMatcherTest method testSetVersion.
@Test
public void testSetVersion() throws ParseException {
String[] cookies = new String[] { "DEVICE_ID=123; Domain=.test.com; Expires=Thu, 12-Oct-2023 09:34:31 GMT; Path=/; Secure; HttpOnly;", "SPRING_SECURITY_REMEMBER_ME_COOKIE=12345;Version=0;Domain=.test.com;Path=/;Max-Age=1209600", "COOKIE_WITH_ZERO_MAX_AGE=1234;Version=0;Domain=.test.com;Path=/;Max-Age=0", "COOKIE_WITH_NEGATIVE_MAX_AGE=123456;Version=0;Domain=.test.com;Path=/;Max-Age=-1" };
Cookies result = CookieMatcher.getCookies(cookies);
assertEquals(4, result.size());
Cookie sprintCookie = result.get("SPRING_SECURITY_REMEMBER_ME_COOKIE");
assertEquals(0, sprintCookie.getVersion());
assertEquals("12345", sprintCookie.getValue());
assertEquals(".test.com", sprintCookie.getDomain());
assertEquals("/", sprintCookie.getPath());
assertEquals(1209600, sprintCookie.getMaxAge());
assertEquals(false, sprintCookie.isSecured());
assertEquals(false, sprintCookie.isHttpOnly());
Cookie cookieWithZeroMaxAge = result.get("COOKIE_WITH_ZERO_MAX_AGE");
assertEquals(0, cookieWithZeroMaxAge.getVersion());
assertEquals("1234", cookieWithZeroMaxAge.getValue());
assertEquals(".test.com", cookieWithZeroMaxAge.getDomain());
assertEquals("/", cookieWithZeroMaxAge.getPath());
assertEquals(0, cookieWithZeroMaxAge.getMaxAge());
assertEquals(false, cookieWithZeroMaxAge.isSecured());
assertEquals(false, cookieWithZeroMaxAge.isHttpOnly());
Cookie cookieWithNegativeMaxAge = result.get("COOKIE_WITH_NEGATIVE_MAX_AGE");
assertEquals(0, cookieWithNegativeMaxAge.getVersion());
assertEquals("123456", cookieWithNegativeMaxAge.getValue());
assertEquals(".test.com", cookieWithNegativeMaxAge.getDomain());
assertEquals("/", cookieWithNegativeMaxAge.getPath());
assertEquals(-1, cookieWithNegativeMaxAge.getMaxAge());
assertEquals(false, cookieWithNegativeMaxAge.isSecured());
assertEquals(false, cookieWithNegativeMaxAge.isHttpOnly());
Cookie deviceCookie = result.get("DEVICE_ID");
assertEquals(-1, deviceCookie.getVersion());
assertEquals("123", deviceCookie.getValue());
assertEquals(".test.com", deviceCookie.getDomain());
assertEquals("/", deviceCookie.getPath());
assertEquals(new SimpleDateFormat("EEE, d-MMM-yyyy HH:mm:ss Z", Locale.ENGLISH).parse("Thu, 12-Oct-2023 09:34:31 GMT"), deviceCookie.getExpiryDate());
assertEquals(true, deviceCookie.isSecured());
assertEquals(true, deviceCookie.isHttpOnly());
}
use of io.restassured.http.Cookie in project rest-assured by rest-assured.
the class CookieFilterTest method preserveCookies.
@Test
public void preserveCookies() {
reqOriginDomain.cookie("cookieName", "cookieInitialValue");
cookieFilter.filter((FilterableRequestSpecification) given(), response, testFilterContext);
cookieFilter.filter(reqOriginDomain, response, testFilterContext);
assertThat(reqOriginDomain.getCookies().size(), Matchers.is(1));
for (Cookie cookie : reqOriginDomain.getCookies()) {
assertThat(cookie.getName(), Matchers.is("cookieName"));
assertThat(cookie.getValue(), Matchers.is("cookieInitialValue"));
}
}
Aggregations