Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
1 <html>
2 <head>
3 <meta charset="utf-8" />
4 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
5 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6 </head>
7 <body>
8 <script class="testbody" type="application/javascript">
9 "use strict";
10 var Cu = SpecialPowers.Cu;
11 var rtcid = Cu.import("resource://gre/modules/media/IdpProxy.jsm");
12 var IdpProxy = rtcid.IdpProxy;
13 var request = {
14 type: "SIGN",
15 message: "foo"
16 };
18 function test_domain_sandbox(done) {
19 var diabolical = {
20 toString : function() {
21 return "example.com/path";
22 }
23 };
24 var domains = [ "ex/foo", "user@ex", "user:pass@ex", "ex#foo", "ex?foo",
25 "", 12, null, diabolical, true ];
26 domains.forEach(function(domain) {
27 try {
28 var idp = new IdpProxy(domain);
29 ok(false, "IdpProxy didn't catch bad domain: " + domain);
30 } catch (e) {
31 var str = (typeof domain === "string") ? domain : typeof domain;
32 ok(true, "Evil domain '" + str + "' raises exception");
33 }
34 });
35 done();
36 }
38 function test_protocol_sandbox(done) {
39 var protos = [ "../evil/proto", "..%2Fevil%2Fproto",
40 "\\evil", "%5cevil", 12, true, {} ];
41 protos.forEach(function(proto) {
42 try {
43 var idp = new IdpProxy("example.com", proto);
44 ok(false, "IdpProxy didn't catch bad protocol: " + proto);
45 } catch (e) {
46 var str = (typeof proto === "string") ? proto : typeof proto;
47 ok(true, "Evil protocol '" + proto + "' raises exception");
48 }
49 });
50 done();
51 }
53 function handleFailure(done) {
54 function failure(error) {
55 ok(false, "IdP error" + error);
56 done();
57 }
58 return failure;
59 }
61 function test_success_response(done) {
62 var idp;
63 var failure = handleFailure(done);
65 function handleResponse(response) {
66 is(SpecialPowers.wrap(response).type, "SUCCESS", "IdP responds with SUCCESS");
67 idp.close();
68 done();
69 }
71 idp = new IdpProxy("example.com", "idp.html");
72 idp.start(failure);
73 idp.send(request, handleResponse);
74 }
76 function test_error_response(done) {
77 var idp;
78 var failure = handleFailure(done);
80 function handleResponse(response) {
81 is(SpecialPowers.wrap(response).type, "ERROR", "IdP should produce ERROR");
82 idp.close();
83 done();
84 }
86 idp = new IdpProxy("example.com", "idp.html#error");
87 idp.start(failure);
88 idp.send(request, handleResponse);
89 }
91 function test_delayed_response(done) {
92 var idp;
93 var failure = handleFailure(done);
95 function handleResponse(response) {
96 is(SpecialPowers.wrap(response).type, "SUCCESS",
97 "IdP should handle delayed response");
98 idp.close();
99 done();
100 }
102 idp = new IdpProxy("example.com", "idp.html#delay100");
103 idp.start(failure);
104 idp.send(request, handleResponse);
105 }
107 var TESTS = [ test_domain_sandbox, test_protocol_sandbox,
108 test_success_response, test_error_response,
109 test_delayed_response ];
111 function run_next_test() {
112 if (TESTS.length) {
113 var test = TESTS.shift();
114 test(run_next_test);
115 } else {
116 SimpleTest.finish();
117 }
118 }
120 SimpleTest.waitForExplicitFinish();
121 SpecialPowers.pushPrefEnv({
122 "set" : [ [ "dom.messageChannel.enabled", true ] ]
123 }, run_next_test);
124 </script>
125 </body>
126 </html>