use of io.restassured.http.Cookies 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.Cookies in project rest-assured by rest-assured.
the class ResponsePrinter method print.
/**
* Prints the response to the print stream
*
* @return A string of representing the response
*/
public static String print(ResponseOptions responseOptions, ResponseBody responseBody, PrintStream stream, LogDetail logDetail, boolean shouldPrettyPrint) {
final StringBuilder builder = new StringBuilder();
if (logDetail == ALL || logDetail == STATUS) {
builder.append(responseOptions.statusLine());
}
if (logDetail == ALL || logDetail == HEADERS) {
final Headers headers = responseOptions.headers();
if (headers.exist()) {
appendNewLineIfAll(logDetail, builder).append(toString(headers));
}
} else if (logDetail == COOKIES) {
final Cookies cookies = responseOptions.detailedCookies();
if (cookies.exist()) {
appendNewLineIfAll(logDetail, builder).append(cookies.toString());
}
}
if (logDetail == ALL || logDetail == BODY) {
String responseBodyToAppend;
if (shouldPrettyPrint) {
responseBodyToAppend = new Prettifier().getPrettifiedBodyIfPossible(responseOptions, responseBody);
} else {
responseBodyToAppend = responseBody.asString();
}
if (logDetail == ALL && !isBlank(responseBodyToAppend)) {
builder.append("\n\n");
}
builder.append(responseBodyToAppend);
}
String response = builder.toString();
stream.println(response);
return response;
}
use of io.restassured.http.Cookies in project rest-assured by rest-assured.
the class CookieITest method removesDoubleQuotesFromCookieWithExpiresDate.
@Test
public void removesDoubleQuotesFromCookieWithExpiresDate() throws Exception {
Cookies cookies = when().get("/cookieWithDoubleQuoteExpiresDate").then().extract().detailedCookies();
assertThat(cookies.asList(), hasSize(1));
Cookie cookie = cookies.get("name");
assertThat(cookie.getExpiryDate(), equalTo(DateUtils.parseDate("Sat, 02 May 2009 23:38:25 GMT")));
}
use of io.restassured.http.Cookies in project rest-assured by rest-assured.
the class CookieITest method detailedCookiesAllowsToGetMultiValues.
@Test
public void detailedCookiesAllowsToGetMultiValues() throws Exception {
final Cookies cookies = get("/multiCookie").detailedCookies();
assertThat(cookies.getValues("cookie1"), hasItems("cookieValue1", "cookieValue2"));
}
use of io.restassured.http.Cookies in project rest-assured by rest-assured.
the class CookieITest method setsExpiresPropertyToNullWhenCookieHasInvalidExpiresDate.
@Test
public void setsExpiresPropertyToNullWhenCookieHasInvalidExpiresDate() throws Exception {
Cookies cookies = when().get("/cookieWithInvalidExpiresDate").then().extract().detailedCookies();
assertThat(cookies.asList(), hasSize(1));
Cookie cookie = cookies.get("name");
assertThat(cookie.getExpiryDate(), nullValue());
}
Aggregations