dom/media/tests/identity/test_idpproxy.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial