dom/media/tests/identity/test_idpproxy.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/media/tests/identity/test_idpproxy.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,126 @@
     1.4 +<html>
     1.5 +<head>
     1.6 +<meta charset="utf-8" />
     1.7 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
     1.8 +<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
     1.9 +</head>
    1.10 +<body>
    1.11 +  <script class="testbody" type="application/javascript">
    1.12 +"use strict";
    1.13 +var Cu = SpecialPowers.Cu;
    1.14 +var rtcid = Cu.import("resource://gre/modules/media/IdpProxy.jsm");
    1.15 +var IdpProxy = rtcid.IdpProxy;
    1.16 +var request = {
    1.17 +  type: "SIGN",
    1.18 +  message: "foo"
    1.19 +};
    1.20 +
    1.21 +function test_domain_sandbox(done) {
    1.22 +  var diabolical = {
    1.23 +    toString : function() {
    1.24 +      return "example.com/path";
    1.25 +    }
    1.26 +  };
    1.27 +  var domains = [ "ex/foo", "user@ex", "user:pass@ex", "ex#foo", "ex?foo",
    1.28 +                  "", 12, null, diabolical, true ];
    1.29 +  domains.forEach(function(domain) {
    1.30 +    try {
    1.31 +      var idp = new IdpProxy(domain);
    1.32 +      ok(false, "IdpProxy didn't catch bad domain: " + domain);
    1.33 +    } catch (e) {
    1.34 +      var str = (typeof domain === "string") ? domain : typeof domain;
    1.35 +      ok(true, "Evil domain '" + str + "' raises exception");
    1.36 +    }
    1.37 +  });
    1.38 +  done();
    1.39 +}
    1.40 +
    1.41 +function test_protocol_sandbox(done) {
    1.42 +  var protos = [ "../evil/proto", "..%2Fevil%2Fproto",
    1.43 +                 "\\evil", "%5cevil", 12, true, {} ];
    1.44 +  protos.forEach(function(proto) {
    1.45 +    try {
    1.46 +      var idp = new IdpProxy("example.com", proto);
    1.47 +      ok(false, "IdpProxy didn't catch bad protocol: " + proto);
    1.48 +    } catch (e) {
    1.49 +      var str = (typeof proto === "string") ? proto : typeof proto;
    1.50 +      ok(true, "Evil protocol '" + proto + "' raises exception");
    1.51 +    }
    1.52 +  });
    1.53 +  done();
    1.54 +}
    1.55 +
    1.56 +function handleFailure(done) {
    1.57 +  function failure(error) {
    1.58 +    ok(false, "IdP error" + error);
    1.59 +    done();
    1.60 +  }
    1.61 +  return failure;
    1.62 +}
    1.63 +
    1.64 +function test_success_response(done) {
    1.65 +  var idp;
    1.66 +  var failure = handleFailure(done);
    1.67 +
    1.68 +  function handleResponse(response) {
    1.69 +    is(SpecialPowers.wrap(response).type, "SUCCESS", "IdP responds with SUCCESS");
    1.70 +    idp.close();
    1.71 +    done();
    1.72 +  }
    1.73 +
    1.74 +  idp = new IdpProxy("example.com", "idp.html");
    1.75 +  idp.start(failure);
    1.76 +  idp.send(request, handleResponse);
    1.77 +}
    1.78 +
    1.79 +function test_error_response(done) {
    1.80 +  var idp;
    1.81 +  var failure = handleFailure(done);
    1.82 +
    1.83 +  function handleResponse(response) {
    1.84 +    is(SpecialPowers.wrap(response).type, "ERROR", "IdP should produce ERROR");
    1.85 +    idp.close();
    1.86 +    done();
    1.87 +  }
    1.88 +
    1.89 +  idp = new IdpProxy("example.com", "idp.html#error");
    1.90 +  idp.start(failure);
    1.91 +  idp.send(request, handleResponse);
    1.92 +}
    1.93 +
    1.94 +function test_delayed_response(done) {
    1.95 +  var idp;
    1.96 +  var failure = handleFailure(done);
    1.97 +
    1.98 +  function handleResponse(response) {
    1.99 +    is(SpecialPowers.wrap(response).type, "SUCCESS",
   1.100 +       "IdP should handle delayed response");
   1.101 +    idp.close();
   1.102 +    done();
   1.103 +  }
   1.104 +
   1.105 +  idp = new IdpProxy("example.com", "idp.html#delay100");
   1.106 +  idp.start(failure);
   1.107 +  idp.send(request, handleResponse);
   1.108 +}
   1.109 +
   1.110 +var TESTS = [ test_domain_sandbox, test_protocol_sandbox,
   1.111 +              test_success_response, test_error_response,
   1.112 +              test_delayed_response ];
   1.113 +
   1.114 +function run_next_test() {
   1.115 +  if (TESTS.length) {
   1.116 +    var test = TESTS.shift();
   1.117 +    test(run_next_test);
   1.118 +  } else {
   1.119 +    SimpleTest.finish();
   1.120 +  }
   1.121 +}
   1.122 +
   1.123 +SimpleTest.waitForExplicitFinish();
   1.124 +SpecialPowers.pushPrefEnv({
   1.125 +  "set" : [ [ "dom.messageChannel.enabled", true ] ]
   1.126 +}, run_next_test);
   1.127 +</script>
   1.128 +  </body>
   1.129 +</html>

mercurial