From 6673eddd945ec12e40ba72601cae9082f4f99473 Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 16 Sep 2015 20:15:12 -0400 Subject: [PATCH] Bug 1198394 - Part 2: Add a test for interception of HSTS upgraded connections; r=jdm --- .../serviceworkers/fetch/hsts/embedder.html | 7 ++ .../serviceworkers/fetch/hsts/hsts_test.js | 11 +++ .../serviceworkers/fetch/hsts/image-20px.png | Bin 0 -> 87 bytes .../serviceworkers/fetch/hsts/image-40px.png | Bin 0 -> 123 bytes .../test/serviceworkers/fetch/hsts/image.html | 13 ++++ .../serviceworkers/fetch/hsts/realindex.html | 4 ++ .../serviceworkers/fetch/hsts/register.html | 14 ++++ .../fetch/hsts/register.html^headers^ | 2 + .../serviceworkers/fetch/hsts/unregister.html | 12 ++++ dom/workers/test/serviceworkers/mochitest.ini | 11 +++ .../test_hsts_upgrade_intercept.html | 66 ++++++++++++++++++ 11 files changed, 140 insertions(+) create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/embedder.html create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/hsts_test.js create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/image-20px.png create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/image-40px.png create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/image.html create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/realindex.html create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/register.html create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/register.html^headers^ create mode 100644 dom/workers/test/serviceworkers/fetch/hsts/unregister.html create mode 100644 dom/workers/test/serviceworkers/test_hsts_upgrade_intercept.html diff --git a/dom/workers/test/serviceworkers/fetch/hsts/embedder.html b/dom/workers/test/serviceworkers/fetch/hsts/embedder.html new file mode 100644 index 000000000000..c985554234e4 --- /dev/null +++ b/dom/workers/test/serviceworkers/fetch/hsts/embedder.html @@ -0,0 +1,7 @@ + + + diff --git a/dom/workers/test/serviceworkers/fetch/hsts/hsts_test.js b/dom/workers/test/serviceworkers/fetch/hsts/hsts_test.js new file mode 100644 index 000000000000..ab54164ed242 --- /dev/null +++ b/dom/workers/test/serviceworkers/fetch/hsts/hsts_test.js @@ -0,0 +1,11 @@ +self.addEventListener("fetch", function(event) { + if (event.request.url.indexOf("index.html") >= 0) { + event.respondWith(fetch("realindex.html")); + } else if (event.request.url.indexOf("image-20px.png") >= 0) { + if (event.request.url.indexOf("https://") == 0) { + event.respondWith(fetch("image-40px.png")); + } else { + event.respondWith(Response.error()); + } + } +}); diff --git a/dom/workers/test/serviceworkers/fetch/hsts/image-20px.png b/dom/workers/test/serviceworkers/fetch/hsts/image-20px.png new file mode 100644 index 0000000000000000000000000000000000000000..ae6a8a6b88403959c75efce931b0bf4293efc956 GIT binary patch literal 87 zcmeAS@N?(olHy`uVBq!ia0vp^A|TAc1|)ksWqE;=oTrOph(&MmkMjpU%%3$Q@ydZf kW_Mm0(}F7pCT1xxd^;`67yW*X5Ktw9r>mdKI;Vst0D!m{_W%F@ literal 0 HcmV?d00001 diff --git a/dom/workers/test/serviceworkers/fetch/hsts/image-40px.png b/dom/workers/test/serviceworkers/fetch/hsts/image-40px.png new file mode 100644 index 0000000000000000000000000000000000000000..fe391dc8a2d797360651fe8cf77161a3fc891194 GIT binary patch literal 123 zcmeAS@N?(olHy`uVBq!ia0vp^8X(NU1|)m_?Z^dEPM$7~ArY-_&utWBP~c%$*z@jL z8rOSWjTbX5i}z1sXJLKaupmKJKx7SbQ&Xu!zy>}Ju4{~r2dxw|BEXUllDQ? + diff --git a/dom/workers/test/serviceworkers/fetch/hsts/realindex.html b/dom/workers/test/serviceworkers/fetch/hsts/realindex.html new file mode 100644 index 000000000000..aaa255aad370 --- /dev/null +++ b/dom/workers/test/serviceworkers/fetch/hsts/realindex.html @@ -0,0 +1,4 @@ + + diff --git a/dom/workers/test/serviceworkers/fetch/hsts/register.html b/dom/workers/test/serviceworkers/fetch/hsts/register.html new file mode 100644 index 000000000000..bcdc146aeca5 --- /dev/null +++ b/dom/workers/test/serviceworkers/fetch/hsts/register.html @@ -0,0 +1,14 @@ + + diff --git a/dom/workers/test/serviceworkers/fetch/hsts/register.html^headers^ b/dom/workers/test/serviceworkers/fetch/hsts/register.html^headers^ new file mode 100644 index 000000000000..a46bf65bd989 --- /dev/null +++ b/dom/workers/test/serviceworkers/fetch/hsts/register.html^headers^ @@ -0,0 +1,2 @@ +Cache-Control: no-cache +Strict-Transport-Security: max-age=60 diff --git a/dom/workers/test/serviceworkers/fetch/hsts/unregister.html b/dom/workers/test/serviceworkers/fetch/hsts/unregister.html new file mode 100644 index 000000000000..1f13508fa700 --- /dev/null +++ b/dom/workers/test/serviceworkers/fetch/hsts/unregister.html @@ -0,0 +1,12 @@ + + diff --git a/dom/workers/test/serviceworkers/mochitest.ini b/dom/workers/test/serviceworkers/mochitest.ini index e62c37078b62..39b5f320a3bf 100644 --- a/dom/workers/test/serviceworkers/mochitest.ini +++ b/dom/workers/test/serviceworkers/mochitest.ini @@ -42,6 +42,15 @@ support-files = fetch/context/sharedworker.js fetch/context/parentsharedworker.js fetch/context/xml.xml + fetch/hsts/hsts_test.js + fetch/hsts/embedder.html + fetch/hsts/image.html + fetch/hsts/image-20px.png + fetch/hsts/image-40px.png + fetch/hsts/realindex.html + fetch/hsts/register.html + fetch/hsts/register.html^headers^ + fetch/hsts/unregister.html fetch/https/index.html fetch/https/register.html fetch/https/unregister.html @@ -259,3 +268,5 @@ skip-if = toolkit == "android" || toolkit == "gonk" [test_not_intercept_plugin.html] [test_file_blob_upload.html] [test_unresolved_fetch_interception.html] +[test_hsts_upgrade_intercept.html] +skip-if = e10s # Bug 1214305 diff --git a/dom/workers/test/serviceworkers/test_hsts_upgrade_intercept.html b/dom/workers/test/serviceworkers/test_hsts_upgrade_intercept.html new file mode 100644 index 000000000000..ea2c1fe8ef68 --- /dev/null +++ b/dom/workers/test/serviceworkers/test_hsts_upgrade_intercept.html @@ -0,0 +1,66 @@ + + + + + Test that an HSTS upgraded request can be intercepted by a service worker + + + + +

+
+ +
+

+
+
+
+