tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_getIdentityAssertion.html (3590B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <script type="application/javascript">var scriptRelativePath = "../";</script>
      5  <script type="application/javascript" src="../pc.js"></script>
      6 </head>
      7 <body>
      8 <pre id="test">
      9 <script type="application/javascript">
     10  createHTML({
     11    title: "getIdentityAssertion Tests",
     12    bug: "942367"
     13  });
     14 
     15 function checkIdentity(assertion, identity) {
     16  // here we dig into the payload, which means we need to know something
     17  // about how the IdP actually works (not good in general, but OK here)
     18  var assertion = JSON.parse(atob(assertion)).assertion;
     19  var user = JSON.parse(assertion).username;
     20  is(user, identity, 'id should be "' + identity + '" is "' + user + '"');
     21 }
     22 
     23 function getAssertion(t, instructions, userHint) {
     24  dump('instructions: ' + instructions + '\n');
     25  dump('userHint: ' + userHint + '\n');
     26  t.pcLocal.setIdentityProvider('example.com',
     27                                { protocol: 'idp.js' + instructions,
     28                                  usernameHint: userHint });
     29  return t.pcLocal._pc.getIdentityAssertion();
     30 }
     31 
     32 var test;
     33 function theTest() {
     34  test = new PeerConnectionTest();
     35  test.setMediaConstraints([{audio: true}], [{audio: true}]);
     36  test.chain.removeAfter('PC_REMOTE_CHECK_INITIAL_SIGNALINGSTATE');
     37  test.chain.append([
     38    function PC_LOCAL_IDENTITY_ASSERTION_FAILS_WITHOUT_PROVIDER(t) {
     39      return t.pcLocal._pc.getIdentityAssertion()
     40        .then(a => ok(false, 'should fail without provider'),
     41              e => ok(e, 'should fail without provider'));
     42    },
     43 
     44    function PC_LOCAL_IDENTITY_ASSERTION_FAILS_WITH_BAD_PROVIDER(t) {
     45      t.pcLocal._pc.setIdentityProvider('example.com',
     46                                        { protocol: 'idp-bad.js',
     47                                          usernameHint: '' });
     48      return t.pcLocal._pc.getIdentityAssertion()
     49        .then(a => ok(false, 'should fail with bad provider'),
     50              e => {
     51                is(e.name, 'IdpError', 'should fail with bad provider');
     52                ok(e.message, 'should include a nice message');
     53              });
     54    },
     55 
     56    function PC_LOCAL_GET_TWO_ASSERTIONS(t) {
     57      return Promise.all([
     58        getAssertion(t, ''),
     59        getAssertion(t, '')
     60      ]).then(assertions => {
     61        is(assertions.length, 2, "Two assertions generated");
     62        assertions.forEach(a => checkIdentity(a, 'someone@example.com'));
     63      });
     64    },
     65 
     66    function PC_LOCAL_IDP_FAILS(t) {
     67      return getAssertion(t, '#fail')
     68        .then(a => ok(false, '#fail should not get an identity result'),
     69              e => is(e.name, 'IdpError', '#fail should cause rejection'));
     70    },
     71 
     72    function PC_LOCAL_IDP_LOGIN_ERROR(t) {
     73      return getAssertion(t, '#login')
     74        .then(a => ok(false, '#login should not work'),
     75              e => {
     76                is(e.name, 'IdpLoginError', 'name is IdpLoginError');
     77                is(t.pcLocal._pc.idpLoginUrl.split('#')[0],
     78                   'https://example.com/.well-known/idp-proxy/login.html',
     79                   'got the right login URL from the IdP');
     80              });
     81    },
     82 
     83    function PC_LOCAL_IDP_NOT_READY(t) {
     84      return getAssertion(t, '#not_ready')
     85        .then(a => ok(false, '#not_ready should not get an identity result'),
     86              e => is(e.name, 'IdpError', '#not_ready should cause rejection'));
     87    },
     88 
     89    function PC_LOCAL_ASSERTION_WITH_SPECIFIC_NAME(t) {
     90      return getAssertion(t, '', 'user@example.com')
     91        .then(a => checkIdentity(a, 'user@example.com'));
     92    }
     93  ]);
     94  return test.run();
     95 }
     96 runNetworkTest(theTest);
     97 
     98 </script>
     99 </pre>
    100 </body>
    101 </html>