set-scope-origin.https.html (2075B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="helper.js" type="module"></script> 6 7 <script type="module"> 8 import { expireCookie, documentHasCookie, waitForCookie, addCookieAndSessionCleanup, setupShardedServerState, configureServer} from "./helper.js"; 9 10 async function runTest(t, scopeOrigin, expectRefresh) { 11 await setupShardedServerState(); 12 const expectedCookieAndValue = "auth_cookie=abcdef0123"; 13 const expectedCookieAndAttributes = `${expectedCookieAndValue};Domain=${location.hostname};Path=/device-bound-session-credentials`; 14 addCookieAndSessionCleanup(t); 15 16 await configureServer({ scopeOrigin }); 17 18 // Prompt starting a session, and wait until registration completes. 19 const loginResponse = await fetch('login.py'); 20 assert_equals(loginResponse.status, 200); 21 await waitForCookie(expectedCookieAndValue, /*expectCookie=*/true); 22 23 // Confirm that a request has the cookie set. 24 const authResponse = await fetch('verify_authenticated.py'); 25 assert_equals(authResponse.status, 200); 26 27 // Expire the cookie, which leads to a request with the cookie set (refresh occurs) only when the scope origin matches. 28 expireCookie(expectedCookieAndAttributes); 29 assert_false(documentHasCookie(expectedCookieAndValue)); 30 const authResponseAfterExpiry = await fetch('verify_authenticated.py'); 31 assert_equals(authResponseAfterExpiry.status, expectRefresh ? 200 : 403); 32 assert_equals(documentHasCookie(expectedCookieAndValue), expectRefresh); 33 } 34 35 promise_test(async t => { 36 // Use the same scope origin as the upcoming request. 37 await runTest(t, location.origin, /*expectRefresh=*/true); 38 }, "A request within the scope origin refreshes"); 39 40 promise_test(async t => { 41 // Use a scope origin that does not match the upcoming request. 42 await runTest(t, `${location.protocol}//www1.${location.host}`, /*expectRefresh=*/false); 43 }, "A request outside the scope origin does not refresh"); 44 </script>