security/manager/ssl/tests/mochitest/bugs/test_bug413909.html

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 <!DOCTYPE HTML>
michael@0 2 <html>
michael@0 3 <head>
michael@0 4 <title>Test bug 413909</title>
michael@0 5 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 6 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
michael@0 7 </head>
michael@0 8 <body onload="onWindowLoad()">
michael@0 9
michael@0 10 <script class="testbody" type="text/javascript">
michael@0 11
michael@0 12 var certOverrideService = Components.classes["@mozilla.org/security/certoverride;1"]
michael@0 13 .getService(Components.interfaces.nsICertOverrideService);
michael@0 14 var cert = null;
michael@0 15 var certListener = null;
michael@0 16
michael@0 17 SimpleTest.waitForExplicitFinish();
michael@0 18
michael@0 19 function badCertListener()
michael@0 20 {
michael@0 21 }
michael@0 22
michael@0 23 badCertListener.prototype = {
michael@0 24 exceptionAdded: false,
michael@0 25
michael@0 26 getInterface: function (aIID) {
michael@0 27 return this.QueryInterface(aIID);
michael@0 28 },
michael@0 29
michael@0 30 QueryInterface: function(aIID) {
michael@0 31 if (aIID.equals(Components.interfaces.nsIBadCertListener2) ||
michael@0 32 aIID.equals(Components.interfaces.nsIInterfaceRequestor) ||
michael@0 33 aIID.equals(Components.interfaces.nsISupports))
michael@0 34 return this;
michael@0 35
michael@0 36 throw Components.results.NS_ERROR_NO_INTERFACE;
michael@0 37 },
michael@0 38
michael@0 39 notifyCertProblem: function MSR_notifyCertProblem(socketInfo, sslStatus, targetHost) {
michael@0 40 cert = sslStatus.QueryInterface(Components.interfaces.nsISSLStatus)
michael@0 41 .serverCert;
michael@0 42
michael@0 43 certOverrideService.rememberValidityOverride(
michael@0 44 "bug413909.xn--hxajbheg2az3al.xn--jxalpdlp",
michael@0 45 -1,
michael@0 46 cert,
michael@0 47 certOverrideService.ERROR_UNTRUSTED,
michael@0 48 false);
michael@0 49
michael@0 50 this.exceptionAdded = true;
michael@0 51 return true;
michael@0 52 }
michael@0 53 }
michael@0 54
michael@0 55 function apiTest(expected)
michael@0 56 {
michael@0 57 var has;
michael@0 58 var bits = {}, temp = {};
michael@0 59
michael@0 60 has = certOverrideService.hasMatchingOverride(
michael@0 61 "bug413909.xn--hxajbheg2az3al.xn--jxalpdlp",
michael@0 62 -1, cert, bits, temp);
michael@0 63 is(has, expected, "hasMatchingOverride "+expected+" for default port value");
michael@0 64
michael@0 65 has = certOverrideService.hasMatchingOverride(
michael@0 66 "bug413909.xn--hxajbheg2az3al.xn--jxalpdlp",
michael@0 67 443, cert, bits, temp);
michael@0 68 is(has, expected, "hasMatchingOverride "+expected+" for explicit port value");
michael@0 69
michael@0 70 has = certOverrideService.hasMatchingOverride(
michael@0 71 "bug413909.xn--hxajbheg2az3al.xn--jxalpdlp",
michael@0 72 563, cert, bits, temp);
michael@0 73 ok(!has, "hasMatchingOverride false for invalid port value");
michael@0 74
michael@0 75 has = certOverrideService.hasMatchingOverride(
michael@0 76 window.frame1.location.hostname,
michael@0 77 -1, cert, bits, temp);
michael@0 78 ok(!has, "hasMatchingOverride false for default port value and non-ascii host");
michael@0 79
michael@0 80 has = certOverrideService.hasMatchingOverride(
michael@0 81 window.frame1.location.hostname,
michael@0 82 443, cert, bits, temp);
michael@0 83 ok(!has, "hasMatchingOverride false for explicit port value and non-ascii host");
michael@0 84
michael@0 85 has = certOverrideService.hasMatchingOverride(
michael@0 86 window.frame1.location.hostname,
michael@0 87 563, cert, bits, temp);
michael@0 88 ok(!has, "hasMatchingOverride false for invalid port value and non-ascii host");
michael@0 89 }
michael@0 90
michael@0 91 function onFrameLoad()
michael@0 92 {
michael@0 93 ok(certListener.exceptionAdded, "Secure page loaded after exception was added and not sooner");
michael@0 94 if (!certListener.exceptionAdded)
michael@0 95 return;
michael@0 96
michael@0 97 apiTest(true);
michael@0 98 certOverrideService.clearValidityOverride(
michael@0 99 "bug413909.xn--hxajbheg2az3al.xn--jxalpdlp", -1);
michael@0 100 apiTest(false);
michael@0 101
michael@0 102 SimpleTest.finish();
michael@0 103 }
michael@0 104
michael@0 105 function onWindowLoad()
michael@0 106 {
michael@0 107 var req = new XMLHttpRequest();
michael@0 108 try
michael@0 109 {
michael@0 110 certListener = new badCertListener();
michael@0 111
michael@0 112 req.open("GET", "https://bug413909.xn--hxajbheg2az3al.xn--jxalpdlp/", false);
michael@0 113 req.channel.notificationCallbacks = certListener;
michael@0 114 req.send(null);
michael@0 115 }
michael@0 116 catch(ex)
michael@0 117 {
michael@0 118 // ignore
michael@0 119 }
michael@0 120
michael@0 121 window.frame1.location.reload();
michael@0 122 }
michael@0 123
michael@0 124 </script>
michael@0 125 <iframe name="frame1" src="https://bug413909.xn--hxajbheg2az3al.xn--jxalpdlp/" onload="onFrameLoad()"></iframe>
michael@0 126 </body>
michael@0 127 </html>

mercurial