tor-browser

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

identity-helper.sub.js (2179B)


      1 'use strict';
      2 
      3 /*
      4  In web-platform-test, a number of domains are required to be set up locally.
      5  The list is available at docs/_writing-tests/server-features.md. The
      6  appropriate hosts file entries can be generated with the WPT CLI via the
      7  following command: `wpt make-hosts-file`.
      8 */
      9 
     10 /*
     11    dictionary RTCIdentityProviderDetails {
     12      required DOMString domain;
     13               DOMString protocol = "default";
     14    };
     15 */
     16 
     17 // Parse a base64 JSON encoded string returned from getIdentityAssertion().
     18 // This is also the string that is set in the a=identity line.
     19 // Returns a { idp, assertion } where idp is of type RTCIdentityProviderDetails
     20 // and assertion is the deserialized JSON that was returned by the
     21 // IdP proxy's generateAssertion() function.
     22 function parseAssertionResult(assertionResultStr) {
     23  const assertionResult = JSON.parse(atob(assertionResultStr));
     24 
     25  const { idp } = assertionResult;
     26  const assertion = JSON.parse(assertionResult.assertion);
     27 
     28  return { idp, assertion };
     29 }
     30 
     31 // Return two distinct IdP domains that are different from current domain
     32 function getIdpDomains() {
     33  const domainA = '{{domains[www]}}';
     34  const domainB = '{{domains[www1]}}';
     35  const domainC = '{{domains[www2]}}';
     36 
     37  if(window.location.hostname === domainA) {
     38    return [domainB, domainC];
     39  } else if(window.location.hostname === domainB) {
     40    return [domainA, domainC];
     41  } else {
     42    return [domainA, domainB];
     43  }
     44 }
     45 
     46 function assert_rtcerror_rejection(errorDetail, promise, desc) {
     47  return promise.then(
     48    res => {
     49      assert_unreached(`Expect promise to be rejected with RTCError, but instead got ${res}`);
     50    }, err => {
     51      assert_true(err instanceof RTCError,
     52        'Expect error object to be instance of RTCError');
     53 
     54      assert_equals(err.errorDetail, errorDetail,
     55        `Expect RTCError object have errorDetail set to ${errorDetail}`);
     56 
     57      return err;
     58    });
     59 }
     60 
     61 // construct a host string consist of domain and optionally port
     62 // If the default HTTP/HTTPS port is used, window.location.port returns
     63 // empty string.
     64 function hostString(domain, port) {
     65  if(port === '') {
     66    return domain;
     67  } else {
     68    return `${domain}:${port}`;
     69  }
     70 }