From e4fdfc41f575d16949caf4e679efd77a570ba761 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Daoust?= Date: Thu, 30 Mar 2017 16:18:39 +0200 Subject: [PATCH] Make HTTPS tests fail if they are loaded over HTTP Test files that contain ".https." trigger a check on the current protocol. If the current protocol is not "https:", all tests in this test file fail with a "Test page must be loaded over HTTPS" message. --- testharness.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testharness.js b/testharness.js index afd794d..42ef851 100644 --- a/testharness.js +++ b/testharness.js @@ -504,6 +504,18 @@ policies and contribution forms [3]. return 'ServiceWorker' in self && worker instanceof ServiceWorker; } + function enforce_https() { + var pos = 0; + if (location && location.pathname) { + pos = location.pathname.indexOf(".https."); + if ((pos !== -1) && (location.protocol !== "https:")) { + assert(false, "enforce_https", "Test page must be loaded over HTTPS.", + "Protocol is ${protocol}", {protocol:location.protocol}); + } + } + } + + /* * API functions */ @@ -513,6 +525,7 @@ policies and contribution forms [3]. var test_name = name ? name : test_environment.next_default_test_name(); properties = properties ? properties : {}; var test_obj = new Test(test_name, properties); + test_obj.step(enforce_https, test_obj, test_obj); test_obj.step(func, test_obj, test_obj); if (test_obj.phase === test_obj.phases.STARTED) { test_obj.done(); @@ -529,6 +542,7 @@ policies and contribution forms [3]. var test_name = name ? name : test_environment.next_default_test_name(); properties = properties ? properties : {}; var test_obj = new Test(test_name, properties); + test_obj.step(enforce_https, test_obj, test_obj); if (func) { test_obj.step(func, test_obj, test_obj); }