Skip to content

Commit

Permalink
[#775] Ensure session cookies are kept across FunctionalTest requests
Browse files Browse the repository at this point in the history
Two fixes

1. Keep cookies with no Max-Age set across FunctionalTest requests
No Max-Age means keep for the browser session. Without this fix
using FunctionalTest without a maxAge in config file will lose
session cookies on every request.

2. Add timestamp to new session even if we had no old session.
The timestamp was never set the first time the session cookie
was created, so the first session cookie always got discarded.
  • Loading branch information
havocp authored and mbknor committed May 10, 2011
1 parent dcf6401 commit 164001d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions framework/src/play/mvc/Scope.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,13 @@ static Session restore() {
// Just restored. Nothing changed. No cookie-expire.
session.changed = false;
}
} else {
// no previous cookie to restore; but we may have to set the timestamp in the new cookie
if (COOKIE_EXPIRE != null) {
session.put(TS_KEY, System.currentTimeMillis() + (Time.parseDuration(COOKIE_EXPIRE) * 1000));
}
}

return session;
} catch (Exception e) {
throw new UnexpectedException("Corrupted HTTP session from " + Http.Request.current().remoteAddress, e);
Expand Down
4 changes: 3 additions & 1 deletion framework/src/play/test/FunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ public InvocationContext getInvocationContext() {
savedCookies = new HashMap<String, Http.Cookie>();
}
for(Map.Entry<String,Http.Cookie> e : response.cookies.entrySet()) {
if(e.getValue().maxAge != null && e.getValue().maxAge > 0) {
// If Max-Age is unset, browsers discard on exit; if
// 0, they discard immediately.
if(e.getValue().maxAge == null || e.getValue().maxAge > 0) {
savedCookies.put(e.getKey(), e.getValue());
}
}
Expand Down

0 comments on commit 164001d

Please sign in to comment.