Skip to content

Commit

Permalink
Accept cookies that have an expiration date (#1667)
Browse files Browse the repository at this point in the history
Fixes #1430
  • Loading branch information
FroMage committed Jun 16, 2023
1 parent 930610c commit a68bcc5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@
import io.restassured.specification.FilterableRequestSpecification;
import io.restassured.specification.FilterableResponseSpecification;
import org.apache.http.Header;
import org.apache.http.client.CookieStore;
import org.apache.http.cookie.Cookie;
import org.apache.http.cookie.CookieOrigin;
import org.apache.http.cookie.CookieSpec;
import org.apache.http.cookie.MalformedCookieException;
import org.apache.http.impl.client.BasicCookieStore;
import org.apache.http.impl.cookie.DefaultCookieSpec;
import org.apache.http.impl.cookie.RFC6265StrictSpec;
import org.apache.http.message.BasicHeader;

import java.net.MalformedURLException;
Expand Down Expand Up @@ -83,7 +85,7 @@ public CookieFilter() {
*/
public CookieFilter(boolean allowMultipleCookiesWithTheSameName) {
this.allowMultipleCookiesWithTheSameName = allowMultipleCookiesWithTheSameName;
this.cookieSpec = new DefaultCookieSpec();
this.cookieSpec = new RFC6265StrictSpec();
this.cookieStore = new BasicCookieStore();
}

Expand Down Expand Up @@ -131,4 +133,8 @@ private CookieOrigin cookieOriginFromUri(String uri) {
throw new IllegalArgumentException(e);
}
}

public CookieStore getCookieStore() {
return cookieStore;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ public Response send(RequestSender requestSender) {
public Response next(FilterableRequestSpecification request, FilterableResponseSpecification response) {
RestAssuredResponseImpl restAssuredResponse = new RestAssuredResponseImpl();
Header setCookieHeader1 =
new Header("Set-Cookie", "cookieName1=cookieValue1; Domain=somedomain.com; Path=/somepath; Secure; HttpOnly");
new Header("Set-Cookie", "cookieName1=cookieValue1; Domain=somedomain.com; Path=/somepath; Secure; HttpOnly; Expires=Wed, 21 Oct 3015 07:28:00 GMT");
Header setCookieHeader2 =
new Header("Set-Cookie", "cookieName2=cookieValue2; Domain=somedomain.com; Path=/somepath; Secure; HttpOnly");
new Header("Set-Cookie", "cookieName2=cookieValue2; Domain=somedomain.com; Path=/somepath; Secure; HttpOnly; Expires=Wed, 21 Oct 3015 07:28:00 GMT");
restAssuredResponse.setResponseHeaders(Headers.headers(setCookieHeader1, setCookieHeader2));
return restAssuredResponse;
}
Expand Down

0 comments on commit a68bcc5

Please sign in to comment.