|
| 1 | +<!DOCTYPE HTML> |
| 2 | +<html> |
| 3 | +<head> |
| 4 | + <title>Bug 1665062 - HTTPS-Only: Do not cancel channel if auth is in progress</title> |
| 5 | + <script src="/tests/SimpleTest/SimpleTest.js"></script> |
| 6 | + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
| 7 | +</head> |
| 8 | +<body> |
| 9 | + |
| 10 | +<script class="testbody" type="text/javascript"> |
| 11 | + |
| 12 | +/* |
| 13 | + * Description of the test: |
| 14 | + * We send a top-level request which results in a '401 - Unauthorized' and ensure that the |
| 15 | + * http background request does not accidentally treat that request as a potential timeout. |
| 16 | + * We make sure that ther HTTPS-Only Mode Error Page does *NOT* show up. |
| 17 | + */ |
| 18 | + |
| 19 | +const {AppConstants} = SpecialPowers.Cu.import("resource://gre/modules/AppConstants.jsm", {}); |
| 20 | + |
| 21 | +SimpleTest.waitForExplicitFinish(); |
| 22 | +SimpleTest.requestFlakyTimeout("When Auth is in progress, HTTPS-Only page should not show up"); |
| 23 | +SimpleTest.requestLongerTimeout(10); |
| 24 | + |
| 25 | +const EXPECTED_KICK_OFF_REQUEST = |
| 26 | + "http://test1.example.com/tests/dom/security/test/https-only/file_http_background_auth_request.sjs?foo"; |
| 27 | +const EXPECTED_UPGRADE_REQUEST = EXPECTED_KICK_OFF_REQUEST.replace("http://", "https://"); |
| 28 | +let EXPECTED_BG_REQUEST = "http://test1.example.com/"; |
| 29 | +let requestCounter = 0; |
| 30 | + |
| 31 | +function examiner() { |
| 32 | + SpecialPowers.addObserver(this, "specialpowers-http-notify-request"); |
| 33 | +} |
| 34 | +examiner.prototype = { |
| 35 | + observe(subject, topic, data) { |
| 36 | + if (topic !== "specialpowers-http-notify-request") { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + // On Android we have other requests appear here as well. Let's make |
| 41 | + // sure we only evaluate requests triggered by the test. |
| 42 | + if (!data.startsWith("http://test1.example.com") && |
| 43 | + !data.startsWith("https://test1.example.com")) { |
| 44 | + return; |
| 45 | + } |
| 46 | + ++requestCounter; |
| 47 | + if (requestCounter == 1) { |
| 48 | + is(data, EXPECTED_KICK_OFF_REQUEST, "kick off request needs to be http"); |
| 49 | + return; |
| 50 | + } |
| 51 | + if (requestCounter == 2) { |
| 52 | + is(data, EXPECTED_UPGRADE_REQUEST, "upgraded request needs to be https"); |
| 53 | + return; |
| 54 | + } |
| 55 | + if (requestCounter == 3) { |
| 56 | + is(data, EXPECTED_BG_REQUEST, "background request needs to be http and no sensitive info"); |
| 57 | + return; |
| 58 | + } |
| 59 | + ok(false, "we should never get here, but just in case"); |
| 60 | + }, |
| 61 | + remove() { |
| 62 | + SpecialPowers.removeObserver(this, "specialpowers-http-notify-request"); |
| 63 | + } |
| 64 | +} |
| 65 | +window.AuthBackgroundRequestExaminer = new examiner(); |
| 66 | + |
| 67 | +// https-only top-level background request occurs after 3 seconds, hence |
| 68 | +// we use 4 seconds to make sure the background request did not happen. |
| 69 | +function resolveAfter4Seconds() { |
| 70 | + return new Promise(resolve => { |
| 71 | + setTimeout(() => { |
| 72 | + resolve(); |
| 73 | + }, 4000); |
| 74 | + }); |
| 75 | +} |
| 76 | + |
| 77 | +async function runTests() { |
| 78 | + await SpecialPowers.pushPrefEnv({ set: [ |
| 79 | + ["dom.security.https_only_mode", true], |
| 80 | + ["dom.security.https_only_mode_send_http_background_request", true], |
| 81 | + ]}); |
| 82 | + |
| 83 | + let testWin = window.open(EXPECTED_KICK_OFF_REQUEST, "_blank"); |
| 84 | + |
| 85 | + // Give the Auth Process and background request some time before moving on. |
| 86 | + await resolveAfter4Seconds(); |
| 87 | + |
| 88 | + if (AppConstants.platform !== "android") { |
| 89 | + is(requestCounter, 3, "three requests total (kickoff, upgraded, background)"); |
| 90 | + } else { |
| 91 | + // On Android, the auth request resolves and hence the background request |
| 92 | + // is not even kicked off - nevertheless, the error page should not appear! |
| 93 | + is(requestCounter, 2, "two requests total (kickoff, upgraded)"); |
| 94 | + } |
| 95 | + |
| 96 | + let wrappedWin = SpecialPowers.wrap(testWin); |
| 97 | + is(wrappedWin.document.body.innerHTML, "", "exception page should not be displayed"); |
| 98 | + |
| 99 | + testWin.close(); |
| 100 | + |
| 101 | + window.AuthBackgroundRequestExaminer.remove(); |
| 102 | + SimpleTest.finish(); |
| 103 | +} |
| 104 | + |
| 105 | +runTests(); |
| 106 | + |
| 107 | +</script> |
| 108 | +</body> |
| 109 | +</html> |
0 commit comments