summaryrefslogtreecommitdiffstats
path: root/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
blob: 6629816134c9c131c99a659a69760120a392393e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<!DOCTYPE HTML>
<html>
<head>
  <script type="application/javascript">var scriptRelativePath = "../";</script>
  <script type="application/javascript" src="../pc.js"></script>
</head>
<body>
<pre id="test">
<script type="application/javascript">
  createHTML({
    title: "getIdentityAssertion Tests",
    bug: "942367"
  });

function checkIdentity(assertion, identity) {
  // here we dig into the payload, which means we need to know something
  // about how the IdP actually works (not good in general, but OK here)
  var assertion = JSON.parse(atob(assertion)).assertion;
  var user = JSON.parse(assertion).username;
  is(user, identity, 'id should be "' + identity + '" is "' + user + '"');
}

function getAssertion(t, instructions, userHint) {
  t.pcLocal.setIdentityProvider('example.com', 'idp.js' + instructions,
                                userHint);
  return t.pcLocal._pc.getIdentityAssertion();
}

var test;
function theTest() {
  test = new PeerConnectionTest();
  test.setMediaConstraints([{audio: true}], [{audio: true}]);
  test.chain.removeAfter('PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE');
  test.chain.append([
    function PC_LOCAL_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER(t) {
      return t.pcLocal._pc.getIdentityAssertion()
        .then(a => ok(false, 'should fail without provider'),
              e => ok(e, 'should fail without provider'));
    },

    function PC_LOCAL_IDENTITY_ASSERTION_FAILS_WITH_BAD_PROVIDER(t) {
      t.pcLocal._pc.setIdentityProvider('example.com', 'idp-bad.js', '');
      return t.pcLocal._pc.getIdentityAssertion()
        .then(a => ok(false, 'should fail with bad provider'),
              e => {
                is(e.name, 'IdpError', 'should fail with bad provider');
                ok(e.message, 'should include a nice message');
              });
    },

    function PC_LOCAL_GET_TWO_ASSERTIONS(t) {
      return Promise.all([
        getAssertion(t, ''),
        getAssertion(t, '')
      ]).then(assertions => {
        is(assertions.length, 2, "Two assertions generated");
        assertions.forEach(a => checkIdentity(a, 'someone@example.com'));
      });
    },

    function PC_LOCAL_IDP_FAILS(t) {
      return getAssertion(t, '#fail')
        .then(a => ok(false, '#fail should not get an identity result'),
              e => is(e.name, 'IdpError', '#fail should cause rejection'));
    },

    function PC_LOCAL_IDP_LOGIN_ERROR(t) {
      return getAssertion(t, '#login')
        .then(a => ok(false, '#login should not work'),
              e => {
                is(e.name, 'IdpLoginError', 'name is IdpLoginError');
                is(t.pcLocal._pc.idpLoginUrl.split('#')[0],
                   'https://example.com/.well-known/idp-proxy/login.html',
                   'got the right login URL from the IdP');
              });
    },

    function PC_LOCAL_IDP_NOT_READY(t) {
      return getAssertion(t, '#not_ready')
        .then(a => ok(false, '#not_ready should not get an identity result'),
              e => is(e.name, 'IdpError', '#not_ready should cause rejection'));
    },

    function PC_LOCAL_ASSERTION_WITH_SPECIFIC_NAME(t) {
      return getAssertion(t, '', 'user@example.com')
        .then(a => checkIdentity(a, 'user@example.com'));
    }
  ]);
  test.run();
}
runNetworkTest(theTest);

</script>
</pre>
</body>
</html>