same-origin-report-credentials.https.sub.html (1645B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Test that reports are sent with credentials to same-origin endpoints</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 = '320db941-960a-4529-8c4a-24aeb6739309'; 14 15 promise_test(async t => { 16 // Set credentials, and set up test to clear them afterwards. 17 await fetch('/cookies/resources/set-cookie.py?name=report&path=%2F', {mode: 'no-cors', credentials: 'include', cache: 'no-store'}); 18 t.add_cleanup(() => fetch("/cookies/resources/set.py?report=; path=%2F; expires=Thu, 01 Jan 1970 00:00:01 GMT")); 19 20 // Trigger a CSP error. 21 await new Promise(resolve => { 22 const img = document.createElement('img'); 23 img.src = "/reporting/resources/fail.png"; 24 img.addEventListener('error', resolve); 25 document.body.appendChild(img); 26 }); 27 28 // Wait for report to be received. 29 const reports = await pollReports(endpoint, id); 30 checkReportExists(reports, 'csp-violation', location.href); 31 32 // Validate that credentials were sent to same-origin endpoint. 33 const cookies = await pollCookies(endpoint, id); 34 assert_true('report' in cookies, "Credentials were present in report"); 35 assert_equals(cookies.report, "[report=1]", "Credential value was correct"); 36 }, "Reporting endpoints received credentials."); 37 </script> 38 </body> 39 </html>