Skip to content

Instantly share code, notes, and snippets.

@jugglinmike
Created May 19, 2017 20:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jugglinmike/9bca41099cc6f7a5435550f84e1c2fa5 to your computer and use it in GitHub Desktop.
Save jugglinmike/9bca41099cc6f7a5435550f84e1c2fa5 to your computer and use it in GitHub Desktop.
sw-migration-csp
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/service-worker-csp-connect.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/service-worker-csp-connect.https.html
index a5139eb..226f4a4 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/service-worker-csp-connect.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/service-worker-csp-connect.https.html
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<title>Service Worker: CSP connect directive for ServiceWorker script</title>
-<script src="../resources/testharness.js"></script>
-<script src="../resources/testharnessreport.js"></script>
-<script src="resources/test-helpers.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js?pipe=sub"></script>
<script>
service_worker_test(
- 'resources/service-worker-csp-worker.php?directive=connect',
+ 'resources/service-worker-csp-worker.py?directive=connect',
'CSP test for connect-src in ServiceWorkerGlobalScope');
</script>
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/service-worker-csp-default.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/service-worker-csp-default.https.html
index 2b23c21..1d4e762 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/service-worker-csp-default.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/service-worker-csp-default.https.html
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<title>Service Worker: CSP default directive for ServiceWorker script</title>
-<script src="../resources/testharness.js"></script>
-<script src="../resources/testharnessreport.js"></script>
-<script src="resources/test-helpers.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js?pipe=sub"></script>
<script>
service_worker_test(
- 'resources/service-worker-csp-worker.php?directive=default',
+ 'resources/service-worker-csp-worker.py?directive=default',
'CSP test for default-src in ServiceWorkerGlobalScope');
</script>
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/service-worker-csp-script.html b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/service-worker-csp-script.https.html
index b0f6e22..14c2eb7 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/service-worker-csp-script.html
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/service-worker-csp-script.https.html
@@ -1,10 +1,10 @@
<!DOCTYPE html>
<title>Service Worker: CSP script directive for ServiceWorker script</title>
-<script src="../resources/testharness.js"></script>
-<script src="../resources/testharnessreport.js"></script>
-<script src="resources/test-helpers.js"></script>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="resources/test-helpers.sub.js?pipe=sub"></script>
<script>
service_worker_test(
- 'resources/service-worker-csp-worker.php?directive=script',
+ 'resources/service-worker-csp-worker.py?directive=script',
'CSP test for script-src in ServiceWorkerGlobalScope');
</script>
diff --git a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/service-worker-csp-worker.php b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/service-worker-csp-worker.py
index 89cd382..5f06454 100644
--- a/third_party/WebKit/LayoutTests/http/tests/serviceworker/resources/service-worker-csp-worker.php
+++ b/third_party/WebKit/LayoutTests/external/wpt/service-workers/service-worker/resources/service-worker-csp-worker.py
@@ -1,22 +1,15 @@
-<?php
-header('Content-Type: application/javascript');
-$directive = $_GET['directive'];
-
-if ($directive == 'default') {
- header('Content-Security-Policy: default-src \'self\'');
-
-?>
+bodyDefault = '''
importScripts('worker-testharness.js');
-importScripts('test-helpers.js');
-importScripts('../../resources/get-host-info.js');
+importScripts('test-helpers.sub.js');
+importScripts('/common/get-host-info.sub.js');
var host_info = get_host_info();
test(function() {
var import_script_failed = false;
try {
- importScripts(host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/empty.js');
+ importScripts(host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'empty.js');
} catch(e) {
import_script_failed = true;
}
@@ -25,8 +18,8 @@ test(function() {
}, 'importScripts test for default-src');
async_test(function(t) {
- fetch(host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*',
+ fetch(host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'fetch-access-control.py?ACAOrigin=*',
{mode: 'cors'})
.then(function(response){
assert_unreached('fetch should fail.');
@@ -37,10 +30,10 @@ async_test(function(t) {
}, 'Fetch test for default-src');
async_test(function(t) {
- var REDIRECT_URL = host_info.HTTP_ORIGIN +
- '/serviceworker/resources/redirect.php?Redirect=';
- var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/fetch-access-control.php?'
+ var REDIRECT_URL = host_info.HTTPS_ORIGIN +
+ base_path() + 'redirect.py?Redirect=';
+ var OTHER_BASE_URL = host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'fetch-access-control.py?'
fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
{mode: 'cors'})
.then(function(response){
@@ -49,25 +42,20 @@ async_test(function(t) {
t.done();
})
.catch(unreached_rejection(t));
- }, 'Redirected fetch test for default-src');
-
-<?php
-
-} else if ($directive == 'script') {
- header('Content-Security-Policy: script-src \'self\'');
+ }, 'Redirected fetch test for default-src');'''
-?>
+bodyScript = '''
importScripts('worker-testharness.js');
-importScripts('test-helpers.js');
-importScripts('../../resources/get-host-info.js');
+importScripts('test-helpers.sub.js');
+importScripts('/common/get-host-info.sub.js');
var host_info = get_host_info();
test(function() {
var import_script_failed = false;
try {
- importScripts(host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/empty.js');
+ importScripts(host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'empty.js');
} catch(e) {
import_script_failed = true;
}
@@ -76,8 +64,8 @@ test(function() {
}, 'importScripts test for script-src');
async_test(function(t) {
- fetch(host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*',
+ fetch(host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'fetch-access-control.py?ACAOrigin=*',
{mode: 'cors'})
.then(function(response){
t.done();
@@ -88,10 +76,10 @@ async_test(function(t) {
}, 'Fetch test for script-src');
async_test(function(t) {
- var REDIRECT_URL = host_info.HTTP_ORIGIN +
- '/serviceworker/resources/redirect.php?Redirect=';
- var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/fetch-access-control.php?'
+ var REDIRECT_URL = host_info.HTTPS_ORIGIN +
+ base_path() + 'redirect.py?Redirect=';
+ var OTHER_BASE_URL = host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'fetch-access-control.py?'
fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
{mode: 'cors'})
.then(function(response){
@@ -100,25 +88,20 @@ async_test(function(t) {
assert_unreached('Redirected fetch should not fail.');
})
.catch(unreached_rejection(t));
- }, 'Redirected fetch test for script-src');
+ }, 'Redirected fetch test for script-src');'''
-<?php
-
-} else if ($directive == 'connect') {
- header('Content-Security-Policy: connect-src \'self\'');
-
-?>
+bodyConnect = '''
importScripts('worker-testharness.js');
-importScripts('test-helpers.js');
-importScripts('../../resources/get-host-info.js');
+importScripts('test-helpers.sub.js');
+importScripts('/common/get-host-info.sub.js');
var host_info = get_host_info();
test(function() {
var import_script_failed = false;
try {
- importScripts(host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/empty.js');
+ importScripts(host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'empty.js');
} catch(e) {
import_script_failed = true;
}
@@ -127,8 +110,8 @@ test(function() {
}, 'importScripts test for connect-src');
async_test(function(t) {
- fetch(host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/fetch-access-control.php?ACAOrigin=*',
+ fetch(host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'fetch-access-control.py?ACAOrigin=*',
{mode: 'cors'})
.then(function(response){
assert_unreached('fetch should fail.');
@@ -139,10 +122,10 @@ async_test(function(t) {
}, 'Fetch test for connect-src');
async_test(function(t) {
- var REDIRECT_URL = host_info.HTTP_ORIGIN +
- '/serviceworker/resources/redirect.php?Redirect=';
- var OTHER_BASE_URL = host_info.HTTP_REMOTE_ORIGIN +
- '/serviceworker/resources/fetch-access-control.php?'
+ var REDIRECT_URL = host_info.HTTPS_ORIGIN +
+ base_path() + 'redirect.py?Redirect=';
+ var OTHER_BASE_URL = host_info.HTTPS_REMOTE_ORIGIN +
+ base_path() + 'fetch-access-control.py?'
fetch(REDIRECT_URL + encodeURIComponent(OTHER_BASE_URL + 'ACAOrigin=*'),
{mode: 'cors'})
.then(function(response){
@@ -151,8 +134,20 @@ async_test(function(t) {
t.done();
})
.catch(unreached_rejection(t));
- }, 'Redirected fetch test for connect-src');
-
-<?php
-}
-?>
+ }, 'Redirected fetch test for connect-src');'''
+
+def main(request, response):
+ headers = []
+ headers.append(('Content-Type', 'application/javascript'))
+ directive = request.GET['directive']
+ body = 'ERROR: Unknown directive'
+ if directive == 'default':
+ headers.append(('Content-Security-Policy', "default-src 'self'"))
+ body = bodyDefault
+ elif directive == 'script':
+ headers.append(('Content-Security-Policy', "script-src 'self'"))
+ body = bodyScript
+ elif directive == 'connect':
+ headers.append(('Content-Security-Policy', "connect-src 'self'"))
+ body = bodyConnect
+ return headers, body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment