summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/content-security-policy/connect-src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/content-security-policy/connect-src
parentInitial commit. (diff)
downloadthunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz
thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/content-security-policy/connect-src')
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-allowed.sub.html39
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-blocked.sub.html39
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-redirect-to-blocked.sub.html36
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-allowed.sub.html36
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-blocked.sub.html39
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-redirect-to-blocked.sub.html40
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-allowed.sub.html36
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-blocked.sub.html36
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-self.sub.html47
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-allowed.sub.html32
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-blocked.sub.html38
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-redirect-to-blocked.sub.html46
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream1
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream.headers1
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-allowed.sub.html39
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-blocked.sub.html44
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-allowed.sub.js23
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js23
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js.sub.headers1
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js21
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js.sub.headers1
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr.sub.js21
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-allowed.sub.html34
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-blocked.sub.html38
-rw-r--r--testing/web-platform/tests/content-security-policy/connect-src/worker-from-guid.sub.html64
25 files changed, 775 insertions, 0 deletions
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-allowed.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-allowed.sub.html
new file mode 100644
index 0000000000..de032a9f47
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-allowed.sub.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self' http://{{host}}:{{ports[http][0]}}; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-beacon-allowed</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["Pass"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+ <!-- enforcing policy:
+connect-src 'self' http://{{host}}:{{ports[http][0]}}; script-src 'self' 'unsafe-inline';
+-->
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("FAIL");
+ });
+
+ if (typeof navigator.sendBeacon != 'function') {
+ t_log.set_status(t_log.NOTRUN, "No navigator.sendBeacon, cannot run test.");
+ t_log.phase = t_log.phases.HAS_RESULT;
+ t_log.done();
+ } else {
+ try {
+ var es = navigator.sendBeacon("http://{{host}}:{{ports[http][0]}}/cors/resources/status.py");
+ log("Pass");
+ } catch (e) {
+ log("Fail");
+ }
+ }
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-blocked.sub.html
new file mode 100644
index 0000000000..025a720184
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-blocked.sub.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-beacon-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["Pass", "violated-directive=connect-src"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+ <!-- enforcing policy:
+connect-src 'self' http://{{host}}:{{ports[http][0]}}; script-src 'self' 'unsafe-inline';
+-->
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ if (typeof navigator.sendBeacon != 'function') {
+ t_log.set_status(t_log.NOTRUN, "No navigator.sendBeacon, cannot run test.");
+ t_log.phase = t_log.phases.HAS_RESULT;
+ t_log.done();
+ } else {
+ try {
+ var es = navigator.sendBeacon("http://www1.{{host}}:{{ports[http][0]}}/security/contentSecurityPolicy/echo-report.php");
+ log("Pass");
+ } catch (e) {
+ log("Fail");
+ }
+ }
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-redirect-to-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-redirect-to-blocked.sub.html
new file mode 100644
index 0000000000..b0cbea51f5
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-beacon-redirect-to-blocked.sub.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-beacon-redirect-to-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["violated-directive=connect-src"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+ <script></script>
+</head>
+
+<body>
+ <p>The beacon should not follow the redirect to http://www1.{{host}}:{{ports[http][0]}}/content-security-policy/support/fail.png and send a CSP violation report.</p>
+ <p>Verify that a CSP connect-src directive blocks redirects.</p>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ if (typeof navigator.sendBeacon != 'function') {
+ t_log.set_status(t_log.NOTRUN, "No navigator.sendBeacon, cannot run test.");
+ t_log.phase = t_log.phases.HAS_RESULT;
+ t_log.done();
+ } else {
+ navigator.sendBeacon(
+ "/common/redirect.py?location=http://www1.{{host}}:{{ports[http][0]}}/content-security-policy/support/fail.png",
+ "ping");
+ }
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-allowed.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-allowed.sub.html
new file mode 100644
index 0000000000..1edaf319dc
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-allowed.sub.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self' http://{{host}}:{{ports[http][0]}}; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-eventsource-allowed</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["allowed"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("blocked");
+ });
+
+ try {
+ var es = new EventSource("http://{{host}}:{{ports[http][0]}}/content-security-policy/connect-src/resources/simple-event-stream");
+ // Firefox and Chrome don't throw an exception.
+ es.onopen = function () {
+ log("allowed");
+ };
+ es.onerror = function () {
+ log("blocked");
+ };
+ } catch (e) {
+ log("blocked");
+ }
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-blocked.sub.html
new file mode 100644
index 0000000000..df8a9a1e3d
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-blocked.sub.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-eventsource-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["blocked","violated-directive=connect-src"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ try {
+ var es = new EventSource("http://{{domains[www1]}}:{{ports[http][0]}}/content-security-policy/connect-src/resources/simple-event-stream");
+ // Firefox and Chrome don't throw an exception and takes some time to close async
+ if (es.readyState == EventSource.CONNECTING) {
+ setTimeout( function() {
+ es.readyState != EventSource.CLOSED ? log("allowed") : log("blocked");
+ }, 1000);
+ } else if (es.readyState == EventSource.CLOSED) {
+ log("blocked");
+ } else {
+ log("allowed");
+ }
+ } catch (e) {
+ log("blocked");
+ }
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-redirect-to-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-redirect-to-blocked.sub.html
new file mode 100644
index 0000000000..32709cd2d4
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-eventsource-redirect-to-blocked.sub.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self' http://{{host}}:{{ports[http][0]}}/security/contentSecurityPolicy/resources/redir.php; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-eventsource-redirect-to-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["PASS EventSource() did not follow the disallowed redirect.","TEST COMPLETE", "violated-directive=connect-src"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+ <script></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ var es;
+ try {
+ es = new EventSource("/common/redirect.py?location= http://www.{{host}}:{{ports[http][0]}}/content-security-policy/connect-src/resources/simple-event-stream");
+ } catch (e) {
+ log("FAIL " + "EventSource() should not throw an exception.");
+ }
+ es.onload = function() {
+ log("FAIL " + "EventSource() should fail to follow the disallowed redirect.");
+ log("TEST COMPLETE");
+ };
+ es.onerror = function() {
+ log("PASS " + "EventSource() did not follow the disallowed redirect.");
+ log("TEST COMPLETE");
+ };
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-allowed.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-allowed.sub.html
new file mode 100644
index 0000000000..4263d97fe2
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-allowed.sub.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncraciws.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self' ws://{{domains[www1]}}:{{ports[http][0]}}/echo; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-websocket-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["allowed"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ try {
+ var ws = new WebSocket("ws://{{domains[www1]}}:{{ports[http][0]}}/echo");
+
+ if (ws.readyState == WebSocket.CLOSING || ws.readyState == WebSocket.CLOSED) {
+ log("blocked");
+ } else {
+ log("allowed");
+ }
+ } catch (e) {
+ log("blocked");
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-blocked.sub.html
new file mode 100644
index 0000000000..02c52837bb
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-blocked.sub.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncraciws.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-websocket-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["blocked","violated-directive=connect-src"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ try {
+ var ws = new WebSocket("ws://{{domains[www1]}}:{{ports[http][0]}}/echo");
+
+ if (ws.readyState == WebSocket.CLOSING || ws.readyState == WebSocket.CLOSED) {
+ log("blocked");
+ } else {
+ log("allowed");
+ }
+ } catch (e) {
+ log("blocked");
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-self.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-self.sub.html
new file mode 100644
index 0000000000..6db324ea0e
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-websocket-self.sub.html
@@ -0,0 +1,47 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-websocket-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["allowed", "allowed"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ try {
+ var ws = new WebSocket("ws://{{host}}:{{location[port]}}/echo");
+
+ if (ws.readyState == WebSocket.CLOSING || ws.readyState == WebSocket.CLOSED) {
+ log("blocked");
+ } else {
+ log("allowed");
+ }
+ } catch (e) {
+ log("blocked");
+ }
+
+ try {
+ var wss = new WebSocket("wss://{{host}}:{{location[port]}}/echo");
+
+ if (wss.readyState == WebSocket.CLOSING || wss.readyState == WebSocket.CLOSED) {
+ log("blocked");
+ } else {
+ log("allowed");
+ }
+ } catch (e) {
+ log("blocked");
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-allowed.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-allowed.sub.html
new file mode 100644
index 0000000000..bde5eeea10
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-allowed.sub.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self' http://{{host}}:{{ports[http][0]}}; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-xmlhttprequest-allowed</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["Pass"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("Fail");
+ });
+
+ try {
+ var xhr = new XMLHttpRequest;
+ xhr.open("GET", "http://{{host}}:{{ports[http][0]}}/xmlhttprequest/resources/get.txt", true);
+ log("Pass");
+ } catch (e) {
+ log("Fail");
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-blocked.sub.html
new file mode 100644
index 0000000000..f4215909d9
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-blocked.sub.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-xmlhttprequest-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["Pass","violated-directive=connect-src"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ try {
+ var xhr = new XMLHttpRequest;
+ xhr.open("GET", "http://www1.{{host}}:{{ports[http][0]}}/content-security-policy/support/fail.png", true);
+ xhr.send();
+ xhr.onload = function() {
+ log("Fail");
+ }
+ xhr.onerror = function() {
+ log("Pass");
+ }
+ } catch (e) {
+ log("Pass");
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-redirect-to-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-redirect-to-blocked.sub.html
new file mode 100644
index 0000000000..429e463c53
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/connect-src-xmlhttprequest-redirect-to-blocked.sub.html
@@ -0,0 +1,46 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>connect-src-xmlhttprequest-redirect-to-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["PASS XMLHttpRequest.send() did not follow the disallowed redirect.","TEST COMPLETE","violated-directive=connect-src"]'></script>
+ <script src="../support/alertAssert.sub.js?alerts=[]"></script>
+ <script id="inject_here"></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ var xhr = new XMLHttpRequest;
+ try {
+ xhr.open("GET", "/common/redirect.py?location=http://www1.{{host}}:{{ports[http][0]}}/content-security-policy/support/fail.asis", true);
+ } catch (e) {
+ log("FAIL " + "XMLHttpRequest.open() should not throw an exception.");
+ }
+ xhr.onload = function() {
+ //cons/**/ole.log(xhr.responseText);
+ if(xhr.responseText == "FAIL") {
+ log("FAIL " + "XMLHttpRequest.send() should fail to follow the disallowed redirect.");
+ } else {
+ log("PASS " + "XMLHttpRequest.send() did not follow the disallowed redirect.");
+ }
+ log("TEST COMPLETE");
+ };
+ xhr.onerror = function() {
+ log("PASS " + "XMLHttpRequest.send() did not follow the disallowed redirect.");
+ log("TEST COMPLETE");
+ };
+ xhr.send();
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream b/testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream
new file mode 100644
index 0000000000..bdd2d486c2
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream
@@ -0,0 +1 @@
+data: hello \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream.headers b/testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream.headers
new file mode 100644
index 0000000000..450c9f2d23
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/resources/simple-event-stream.headers
@@ -0,0 +1 @@
+Content-Type: text/event-stream \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-allowed.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-allowed.sub.html
new file mode 100644
index 0000000000..f772b2402a
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-allowed.sub.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self' http://{{domains[www1]}}:{{ports[http][0]}}; script-src 'self' 'unsafe-inline';">
+ <title>shared-worker-connect-src-allowed</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["xhr allowed","TEST COMPLETE"]'></script>
+ <script src='../support/alertAssert.sub.js?alerts=[]'></script>
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("violated-directive=" + e.violatedDirective);
+ });
+
+ if(typeof SharedWorker != 'function') {
+ t_log.set_status(t_alert.NOTRUN, "No SharedWorker, cannot run test.");
+ t_log.phase = t_alert.phases.HAS_RESULT;
+ t_log.done();
+ } else {
+ try {
+ var worker = new SharedWorker('/content-security-policy/connect-src/support/shared-worker-make-xhr-allowed.sub.js');
+ worker.port.onmessage = function(event) {
+ log(event.data);
+ };
+ } catch (e) {
+ log(e);
+ }
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-blocked.sub.html
new file mode 100644
index 0000000000..f229d561dc
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/shared-worker-connect-src-blocked.sub.html
@@ -0,0 +1,44 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src *; script-src 'self' 'unsafe-inline';">
+ <title>shared-worker-connect-src-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["xhr blocked","TEST COMPLETE"]'></script>
+ <script src='../support/alertAssert.sub.js?alerts=[]'></script>
+</head>
+
+<body>
+ <p>This test loads a shared worker, delivered with its own
+ policy. The worker should be blocked from making an XHR
+ as that policy specifies a connect-src 'none', though
+ this resource's policy is connect-src *. No report
+ should be sent since the worker's policy doesn't specify
+ a report-uri.</p>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log("Fail");
+ });
+
+ if(typeof SharedWorker != 'function') {
+ t_log.set_status(t_log.NOTRUN, "No SharedWorker, cannot run test.");
+ t_log.phase = t_log.phases.HAS_RESULT;
+ t_log.done();
+ } else {
+ try {
+ var worker = new SharedWorker('/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js');
+ worker.port.onmessage = function(event) {
+ log(event.data);
+ };
+ } catch (e) {
+ log(e);
+ }
+ }
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-allowed.sub.js b/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-allowed.sub.js
new file mode 100644
index 0000000000..1e9700832d
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-allowed.sub.js
@@ -0,0 +1,23 @@
+onconnect = function (event) {
+ var port = event.ports[0];
+ var xhr = new XMLHttpRequest;
+ xhr.onerror = function () {
+ port.postMessage("xhr blocked");
+ port.postMessage("TEST COMPLETE");
+ };
+ xhr.onload = function () {
+ if (xhr.responseText == "FAIL") {
+ port.postMessage("xhr allowed");
+ } else {
+ port.postMessage("xhr blocked");
+ }
+ port.postMessage("TEST COMPLETE");
+ };
+ try {
+ xhr.open("GET", "http://{{domains[www1]}}:{{ports[http][0]}}/content-security-policy/support/fail.asis", true);
+ xhr.send();
+ } catch (e) {
+ port.postMessage("xhr blocked");
+ port.postMessage("TEST COMPLETE");
+ }
+} \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js b/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js
new file mode 100644
index 0000000000..1e9700832d
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js
@@ -0,0 +1,23 @@
+onconnect = function (event) {
+ var port = event.ports[0];
+ var xhr = new XMLHttpRequest;
+ xhr.onerror = function () {
+ port.postMessage("xhr blocked");
+ port.postMessage("TEST COMPLETE");
+ };
+ xhr.onload = function () {
+ if (xhr.responseText == "FAIL") {
+ port.postMessage("xhr allowed");
+ } else {
+ port.postMessage("xhr blocked");
+ }
+ port.postMessage("TEST COMPLETE");
+ };
+ try {
+ xhr.open("GET", "http://{{domains[www1]}}:{{ports[http][0]}}/content-security-policy/support/fail.asis", true);
+ xhr.send();
+ } catch (e) {
+ port.postMessage("xhr blocked");
+ port.postMessage("TEST COMPLETE");
+ }
+} \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js.sub.headers b/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js.sub.headers
new file mode 100644
index 0000000000..ac7368c32e
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/support/shared-worker-make-xhr-blocked.sub.js.sub.headers
@@ -0,0 +1 @@
+Content-Security-Policy: connect-src 'none' \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js b/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js
new file mode 100644
index 0000000000..22819d57a2
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js
@@ -0,0 +1,21 @@
+var xhr = new XMLHttpRequest;
+xhr.onerror = function () {
+ postMessage("xhr blocked");
+ postMessage("TEST COMPLETE");
+};
+xhr.onload = function () {
+ //cons/**/ole.log(xhr.responseText);
+ if (xhr.responseText == "FAIL") {
+ postMessage("xhr allowed");
+ } else {
+ postMessage("xhr blocked");
+ }
+ postMessage("TEST COMPLETE");
+};
+try {
+ xhr.open("GET", "/common/redirect.py?location=http://www1.{{host}}:{{ports[http][0]}}/content-security-policy/support/fail.asis", true);
+ xhr.send();
+} catch (e) {
+ postMessage("xhr blocked");
+ postMessage("TEST COMPLETE");
+} \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js.sub.headers b/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js.sub.headers
new file mode 100644
index 0000000000..ac7368c32e
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js.sub.headers
@@ -0,0 +1 @@
+Content-Security-Policy: connect-src 'none' \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr.sub.js b/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr.sub.js
new file mode 100644
index 0000000000..73359a39ea
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/support/worker-make-xhr.sub.js
@@ -0,0 +1,21 @@
+var xhr = new XMLHttpRequest;
+xhr.onerror = function () {
+ postMessage("xhr blocked");
+ postMessage("TEST COMPLETE");
+};
+xhr.onload = function () {
+ //cons/**/ole.log(xhr.responseText);
+ if (xhr.responseText == "FAIL") {
+ postMessage("xhr allowed");
+ } else {
+ postMessage("xhr blocked");
+ }
+ postMessage("TEST COMPLETE");
+};
+try {
+ xhr.open("GET", "/common/redirect.py?location=http://{{host}}:{{ports[http][0]}}/content-security-policy/support/fail.asis", true);
+ xhr.send();
+} catch (e) {
+ postMessage("xhr blocked");
+ postMessage("TEST COMPLETE");
+} \ No newline at end of file
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-allowed.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-allowed.sub.html
new file mode 100644
index 0000000000..4ce5c99573
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-allowed.sub.html
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline';">
+ <title>worker-connect-src-allowed</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["xhr allowed"]'></script>
+ <script src='../support/alertAssert.sub.js?alerts=[]'></script>
+
+</head>
+
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log('Fail');
+ });
+
+ try {
+ var worker = new Worker('/content-security-policy/connect-src/support/worker-make-xhr.sub.js');
+ worker.onmessage = function(event) {
+ log(event.data);
+ };
+ } catch (e) {
+ log(e);
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-blocked.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-blocked.sub.html
new file mode 100644
index 0000000000..d375771542
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/worker-connect-src-blocked.sub.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src *; script-src 'self' 'unsafe-inline';">
+ <title>worker-connect-src-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["xhr blocked","TEST COMPLETE"]'></script>
+ <script src='../support/alertAssert.sub.js?alerts=[]'></script>
+</head>
+<p>This test loads a worker, which is delivered with its own
+ policy. The worker should be blocked from making an XHR
+ as that policy specifies a connect-src 'none', though
+ this resource's policy is connect-src *. No report
+ should be sent since the worker's policy doesn't specify
+ a report-uri.</p>
+<body>
+ <script>
+ window.addEventListener('securitypolicyviolation', function(e) {
+ log('Fail');
+ });
+
+ try {
+ var worker = new Worker('/content-security-policy/connect-src/support/worker-make-xhr-blocked.sub.js');
+ worker.onmessage = function(event) {
+ log(event.data);
+ };
+ } catch (e) {
+ log(e);
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>
diff --git a/testing/web-platform/tests/content-security-policy/connect-src/worker-from-guid.sub.html b/testing/web-platform/tests/content-security-policy/connect-src/worker-from-guid.sub.html
new file mode 100644
index 0000000000..045afb8082
--- /dev/null
+++ b/testing/web-platform/tests/content-security-policy/connect-src/worker-from-guid.sub.html
@@ -0,0 +1,64 @@
+<!DOCTYPE html>
+<html>
+
+<head>
+ <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.-->
+ <meta http-equiv="Content-Security-Policy" content="connect-src 'self'; script-src 'self' 'unsafe-inline' blob:;">
+ <title>worker-connect-src-blocked</title>
+ <script src="/resources/testharness.js"></script>
+ <script src="/resources/testharnessreport.js"></script>
+ <script src='../support/logTest.sub.js?logs=["violated-directive=connect-src","xhr blocked","TEST COMPLETE"]'></script>
+ <script src='../support/alertAssert.sub.js?alerts=[]'></script>
+</head>
+<p>This test loads a worker, from a guid.
+ The worker should be blocked from making an XHR
+ to www1 as this resource's policy is connect-src 'self
+ and a guid Worker should inherit is parent's policy.
+ A report should be sent to the report-uri specified
+ with this resource.</p>
+<body>
+ <script>
+ try {
+ var blob = new Blob([
+ "self.addEventListener('securitypolicyviolation', e => {" +
+ " postMessage('violated-directive=' + e.violatedDirective);" +
+ "});" +
+ "var xhr = new XMLHttpRequest;" +
+ "xhr.onerror = function () {" +
+ " postMessage('xhr blocked');" +
+ " postMessage('TEST COMPLETE');" +
+ "};" +
+ "xhr.onload = function () {" +
+ " if (xhr.responseText == 'FAIL') {" +
+ " postMessage('xhr allowed');" +
+ " } else {" +
+ " postMessage('xhr blocked');" +
+ " }" +
+ " postMessage('TEST COMPLETE');" +
+ "};" +
+ "try { " +
+ " xhr.open(" +
+ " 'GET'," +
+ " 'http:///content-security-policy/support/fail.asis'," +
+ " true" +
+ " );" +
+ " xhr.send();" +
+ "} catch (e) {" +
+ " postMessage('xhr blocked');" +
+ " postMessage('TEST COMPLETE');" +
+ "}"],
+ {type : 'application/javascript'});
+ var url = URL.createObjectURL(blob);
+ var worker = new Worker(url);
+ worker.onmessage = function(event) {
+ log(event.data);
+ };
+ } catch (e) {
+ log(e);
+ }
+
+ </script>
+ <div id="log"></div>
+</body>
+
+</html>