forked from web-platform-tests/wpt
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrefresh-replaces-config.https.html
More file actions
109 lines (92 loc) · 5.45 KB
/
Copy pathrefresh-replaces-config.https.html
File metadata and controls
109 lines (92 loc) · 5.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<!DOCTYPE html>
<meta charset="utf-8">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="helper.js" type="module"></script>
<script type="module">
import { expireCookie, waitForCookie, addCookieAndSessionCleanup, configureServer, setupShardedServerState, documentHasCookie } from "./helper.js";
promise_test(async t => {
await setupShardedServerState();
const expectedCookieAndValue1 = "auth_cookie=abcdef0123";
const expectedCookieAndAttributes1 = `${expectedCookieAndValue1};Domain=${location.hostname};Path=/device-bound-session-credentials`;
const expectedCookieAndValue2 = "other_cookie=ghijkl4567";
const expectedCookieAndAttributes2 = `${expectedCookieAndValue2};Domain=${location.hostname};Path=/device-bound-session-credentials`;
addCookieAndSessionCleanup(t);
// Prompt starting a session, and wait until registration completes.
const loginResponse = await fetch('login.py');
assert_equals(loginResponse.status, 200);
await waitForCookie(expectedCookieAndValue1, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const authResponse = await fetch('verify_authenticated.py');
assert_equals(authResponse.status, 200);
// Confirm that a request does not have alternate cookie set.
const alternateAuthResponse = await fetch('verify_authenticated.py', {
method: 'POST',
body: expectedCookieAndValue2
});
assert_equals(alternateAuthResponse.status, 403);
// Configure server to change the cookie in the session config on next refresh.
await configureServer({ cookieDetails: [{ nameAndValue: expectedCookieAndValue2 }] });
// Expire the first cookie and send a request, which triggers the refresh with the new session config.
expireCookie(expectedCookieAndAttributes1);
assert_false(documentHasCookie(expectedCookieAndValue1));
const authResponseAfterExpiry1 = await fetch('verify_authenticated.py');
assert_equals(authResponseAfterExpiry1.status, 403);
assert_false(documentHasCookie(expectedCookieAndValue1));
// Confirm the alternate cookie is set and included in requests. This should
// not trigger refresh. Note that because a session can only refresh a
// request once, if the refresh endpoint is correctly setting cookies for
// the new config, but the browser rejects the config, it won't be visible
// from the cookie state. Terminating the session if it refreshes when it
// shouldn't creates a state change we can see.
await configureServer({ shouldRefreshEndSession: true });
assert_true(documentHasCookie(expectedCookieAndValue2));
const alternateAuthResponseAfterExpiry1 = await fetch('verify_authenticated.py', {
method: 'POST',
body: expectedCookieAndValue2
});
assert_equals(alternateAuthResponseAfterExpiry1.status, 200);
// Restore the server configuration so we can test that the new config does
// refresh when expected.
await configureServer({ shouldRefreshEndSession: false });
// Expire the second cookie. Confirm the second cookie is refreshed, and not the first.
expireCookie(expectedCookieAndAttributes2);
assert_false(documentHasCookie(expectedCookieAndValue2));
const alternateAuthResponseAfterExpiry2 = await fetch('verify_authenticated.py', {
method: 'POST',
body: expectedCookieAndValue2
});
assert_equals(alternateAuthResponseAfterExpiry2.status, 200);
assert_true(documentHasCookie(expectedCookieAndValue2));
assert_false(documentHasCookie(expectedCookieAndValue1));
}, "Refresh can replace session config");
promise_test(async t => {
await setupShardedServerState();
const expectedCookieAndValue = "auth_cookie=abcdef0123";
const expectedCookieAndAttributes = `${expectedCookieAndValue};Domain=${location.hostname};Path=/device-bound-session-credentials`;
addCookieAndSessionCleanup(t);
// Prompt starting a session, and wait until registration completes.
const loginResponse = await fetch('login.py');
assert_equals(loginResponse.status, 200);
await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true);
// Confirm that a request has the cookie set.
const authResponse = await fetch('verify_authenticated.py');
assert_equals(authResponse.status, 200);
// Configure server to change the session identifier in the session config on next refresh.
await configureServer({ responseSessionIdOverride: 12345 });
// Expire the first cookie and send a request, which triggers the refresh with the new session config.
expireCookie(expectedCookieAndAttributes);
assert_false(documentHasCookie(expectedCookieAndValue));
const authResponseAfterExpiry = await fetch('verify_authenticated.py');
// The first refresh request will give us a new cookie, but will also cause the session to be terminated.
assert_true(documentHasCookie(expectedCookieAndValue));
assert_equals(authResponseAfterExpiry.status, 200);
// Now that the session is terminated, refresh should not give us a new cookie.
expireCookie(expectedCookieAndAttributes);
assert_false(documentHasCookie(expectedCookieAndValue));
const authResponseAfterTermination = await fetch('verify_authenticated.py');
assert_equals(authResponseAfterTermination.status, 403);
// Because refresh failed, we still do not have the cookie
assert_false(documentHasCookie(expectedCookieAndValue));
}, "Refresh cannot replace session identifier");
</script>