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