Wed, 31 Dec 2014 07:16:47 +0100
Revert simplistic fix pending revisit of Mozilla integration attempt.
michael@0 | 1 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 4 | |
michael@0 | 5 | <!DOCTYPE HTML> |
michael@0 | 6 | <html> |
michael@0 | 7 | <head> |
michael@0 | 8 | <title>opens additional content that should be converted to https</title> |
michael@0 | 9 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 11 | |
michael@0 | 12 | <script class="testbody" type="text/javascript"> |
michael@0 | 13 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 14 | |
michael@0 | 15 | const STSPATH = "/tests/security/manager/ssl/tests/mochitest/stricttransportsecurity"; |
michael@0 | 16 | |
michael@0 | 17 | // initialized manually here |
michael@0 | 18 | var testsleft = {'plain': 4, 'subdom': 4}; |
michael@0 | 19 | var roundsLeft = 2; |
michael@0 | 20 | |
michael@0 | 21 | var testframes = { |
michael@0 | 22 | 'samedom': |
michael@0 | 23 | {'url': "http://example.com" + STSPATH + "/verify.sjs", |
michael@0 | 24 | 'expected': {'plain': 'SECURE', 'subdom': 'SECURE'}}, |
michael@0 | 25 | 'subdom': |
michael@0 | 26 | {'url': "http://test1.example.com" + STSPATH + "/verify.sjs", |
michael@0 | 27 | 'expected': {'plain': 'INSECURE', 'subdom': 'SECURE'}}, |
michael@0 | 28 | 'otherdom': |
michael@0 | 29 | {'url': "http://example.org" + STSPATH + "/verify.sjs", |
michael@0 | 30 | 'expected': {'plain': 'INSECURE', 'subdom': 'INSECURE'}}, |
michael@0 | 31 | 'alreadysecure': |
michael@0 | 32 | {'url': "https://test2.example.com" + STSPATH + "/verify.sjs", |
michael@0 | 33 | 'expected': {'plain': 'SECURE', 'subdom': 'SECURE'}}, |
michael@0 | 34 | }; |
michael@0 | 35 | |
michael@0 | 36 | function startRound(round) { |
michael@0 | 37 | var frame = document.createElement("iframe"); |
michael@0 | 38 | frame.setAttribute('id', 'ifr_bootstrap'); |
michael@0 | 39 | frame.setAttribute('src', "https://example.com" + STSPATH + "/" + round + "_bootstrap.html"); |
michael@0 | 40 | document.body.appendChild(frame); |
michael@0 | 41 | } |
michael@0 | 42 | |
michael@0 | 43 | function endRound(round) { |
michael@0 | 44 | // remove all the iframes in the document |
michael@0 | 45 | document.body.removeChild(document.getElementById('ifr_bootstrap')); |
michael@0 | 46 | for (var test in testframes) |
michael@0 | 47 | document.body.removeChild(document.getElementById('ifr_' + test)); |
michael@0 | 48 | |
michael@0 | 49 | // clean up the STS state |
michael@0 | 50 | const Cc = SpecialPowers.Cc; |
michael@0 | 51 | const Ci = SpecialPowers.Ci; |
michael@0 | 52 | var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService); |
michael@0 | 53 | var thehost = ios.newURI("http://example.com", null, null); |
michael@0 | 54 | |
michael@0 | 55 | var sss = Cc["@mozilla.org/ssservice;1"].getService(Ci.nsISiteSecurityService); |
michael@0 | 56 | sss.removeState(Ci.nsISiteSecurityService.HEADER_HSTS, thehost, 0); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function loadVerifyFrames(round) { |
michael@0 | 60 | for (var test in testframes) { |
michael@0 | 61 | var frame = document.createElement("iframe"); |
michael@0 | 62 | frame.setAttribute('id', 'ifr_' + test); |
michael@0 | 63 | frame.setAttribute('src', testframes[test].url + '?id=' + test); |
michael@0 | 64 | document.body.appendChild(frame); |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | /* Messages received are in this format: |
michael@0 | 69 | * (BOOTSTRAP|SECURE|INSECURE) testid |
michael@0 | 70 | * For example: "BOOTSTRAP plain" |
michael@0 | 71 | * or: "INSECURE otherdom" |
michael@0 | 72 | */ |
michael@0 | 73 | function onMessageReceived(event) { |
michael@0 | 74 | |
michael@0 | 75 | // otherwise, it's a test result |
michael@0 | 76 | var result = event.data.split(/\s+/); |
michael@0 | 77 | if (result.length != 2) { |
michael@0 | 78 | SimpleTest.ok(false, event.data); |
michael@0 | 79 | return; |
michael@0 | 80 | } |
michael@0 | 81 | |
michael@0 | 82 | // figure out which round of tests we're in |
michael@0 | 83 | var round = (roundsLeft == 2) ? 'plain' : 'subdom'; |
michael@0 | 84 | |
michael@0 | 85 | if (result[0] === "BOOTSTRAP") { |
michael@0 | 86 | loadVerifyFrames(round); |
michael@0 | 87 | return; |
michael@0 | 88 | } |
michael@0 | 89 | |
michael@0 | 90 | // check if the result (SECURE/INSECURE) is expected for this round/test combo |
michael@0 | 91 | SimpleTest.is(result[0], testframes[result[1]].expected[round], |
michael@0 | 92 | "in ROUND " + round + ", test " + result[1]); |
michael@0 | 93 | testsleft[round]--; |
michael@0 | 94 | |
michael@0 | 95 | // check if there are more tests to run. |
michael@0 | 96 | if (testsleft[round] < 1) { |
michael@0 | 97 | // if not, advance to next round |
michael@0 | 98 | endRound(round); |
michael@0 | 99 | roundsLeft--; |
michael@0 | 100 | |
michael@0 | 101 | // defer this so it doesn't muck with the stack too much. |
michael@0 | 102 | if (roundsLeft == 1) |
michael@0 | 103 | setTimeout(function () { |
michael@0 | 104 | startRound('subdom'); |
michael@0 | 105 | }, 0); |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | if (roundsLeft < 1) { |
michael@0 | 109 | SimpleTest.finish(); |
michael@0 | 110 | } |
michael@0 | 111 | } |
michael@0 | 112 | |
michael@0 | 113 | // listen for calls back from the sts-setting iframe and then |
michael@0 | 114 | // the verification frames. |
michael@0 | 115 | window.addEventListener("message", onMessageReceived, false); |
michael@0 | 116 | window.addEventListener('load', function() {startRound('plain');}, false); |
michael@0 | 117 | </script> |
michael@0 | 118 | </head> |
michael@0 | 119 | |
michael@0 | 120 | <body> |
michael@0 | 121 | This test will load some iframes and do some tests. |
michael@0 | 122 | |
michael@0 | 123 | </body> |
michael@0 | 124 | </html> |