same-origin-same-site-credentials.https.sub.html (2852B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test that credentials are sent properly in a same-origin and also same-site nested context</title> 5 <script src='/resources/testharness.js'></script> 6 <script src='/resources/testharnessreport.js'></script> 7 <script src='resources/report-helper.js'></script> 8 </head> 9 <body> 10 <script> 11 const base_url = `${location.protocol}//${location.host}`; 12 const endpoint = `${base_url}/reporting/resources/report.py`; 13 const id = '54ba9bc5-c2f2-5a7d-96ab-331842a51499'; 14 15 promise_test(async t => { 16 // If this is not run from the expected origin, then the A->A->A frame embedding will not be correct, 17 // and the cookies set in the top-level page will never be returned with the reports. 18 assert_true(location.href.startsWith("https://{{hosts[][]}}:{{ports[https][0]}}/"), 19 "Test running on unexpected origin; subsequent assertions will fail."); 20 21 // Set credentials, and set up test to clear them afterwards. 22 await fetch('/cookies/resources/setSameSite.py?reporting', {mode: 'no-cors', credentials: 'include', cache: 'no-store'}); 23 t.add_cleanup(() => fetch("/cookies/resources/dropSameSite.py", {mode: 'no-cors', credentials: 'include', cache: 'no-store'})); 24 25 // Insert a same-origin frame which will then frame this origin to 26 // trigger a CSP error. 27 const frame = document.createElement('iframe'); 28 frame.src = `https://{{hosts[][]}}:{{ports[https][0]}}/reporting/resources/middle-frame.https.sub.html?reportID=${id}`; 29 document.body.appendChild(frame); 30 31 // Wait for the inner frame to signal that the report has been generated. 32 await new Promise(resolve => { 33 window.addEventListener('message', ev => { 34 if (ev.data === "done") 35 resolve(ev.data); 36 }); 37 document.body.appendChild(frame); 38 }); 39 40 const reports = await pollReports(endpoint, id); 41 checkReportExists(reports, 'csp-violation', 42 `https://{{hosts[][]}}:{{ports[https][0]}}/reporting/resources/same-origin-report.https.sub.html?reportID=${id}`); 43 44 // All credentials set at the top-level should be received. 45 const cookies = await pollCookies(endpoint, id); 46 assert_equals(cookies.samesite_none, "[samesite_none=reporting]", "Credential value was correct"); 47 assert_equals(cookies.samesite_unspecified, "[samesite_unspecified=reporting]", "Credential value was correct"); 48 assert_equals(cookies.samesite_lax, "[samesite_lax=reporting]", "Credential value was correct"); 49 assert_equals(cookies.samesite_strict, "[samesite_strict=reporting]", "Credential value was correct"); 50 assert_equals(Object.keys(cookies).length, 4, "No additional cookies were received"); 51 }, "Reporting endpoints received credentials."); 52 </script> 53 </body> 54 </html>