tor-browser

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

identityPcTest.js (2398B)


      1 function identityPcTest(remoteOptions) {
      2  var user = "someone";
      3  var domain1 = "test1.example.com";
      4  var domain2 = "test2.example.com";
      5  var id1 = user + "@" + domain1;
      6  var id2 = user + "@" + domain2;
      7 
      8  const audioContext = new AudioContext();
      9  // Start a tone so that the gUM call will record something even with
     10  // --use-test-media-devices.  TEST_AUDIO_FREQ matches the frequency of the
     11  // tone in fake microphone devices.
     12  const tone = new LoopbackTone(audioContext, TEST_AUDIO_FREQ);
     13  tone.start();
     14 
     15  test = new PeerConnectionTest({
     16    config_local: {
     17      peerIdentity: id2,
     18    },
     19    config_remote: {
     20      peerIdentity: id1,
     21    },
     22  });
     23  test.setMediaConstraints(
     24    [
     25      {
     26        audio: true,
     27        video: true,
     28        peerIdentity: id2,
     29      },
     30    ],
     31    [
     32      remoteOptions || {
     33        audio: true,
     34        video: true,
     35        peerIdentity: id1,
     36      },
     37    ]
     38  );
     39  test.pcLocal.setIdentityProvider("test1.example.com", { protocol: "idp.js" });
     40  test.pcRemote.setIdentityProvider("test2.example.com", {
     41    protocol: "idp.js",
     42  });
     43  test.chain.append([
     44    function PEER_IDENTITY_IS_SET_CORRECTLY(test) {
     45      // no need to wait to check identity in this case,
     46      // setRemoteDescription should wait for the IdP to complete
     47      function checkIdentity(pc, pfx, idp, name) {
     48        return pc.peerIdentity.then(peerInfo => {
     49          is(peerInfo.idp, idp, pfx + "IdP check");
     50          is(peerInfo.name, name + "@" + idp, pfx + "identity check");
     51        });
     52      }
     53 
     54      return Promise.all([
     55        checkIdentity(
     56          test.pcLocal._pc,
     57          "local: ",
     58          "test2.example.com",
     59          "someone"
     60        ),
     61        checkIdentity(
     62          test.pcRemote._pc,
     63          "remote: ",
     64          "test1.example.com",
     65          "someone"
     66        ),
     67      ]);
     68    },
     69 
     70    function REMOTE_STREAMS_ARE_RESTRICTED(test) {
     71      var remoteStream = test.pcLocal._pc.getRemoteStreams()[0];
     72      for (const track of remoteStream.getTracks()) {
     73        mustThrowWith(
     74          `Freshly received ${track.kind} track with peerIdentity`,
     75          "SecurityError",
     76          () => new MediaRecorder(new MediaStream([track])).start()
     77        );
     78      }
     79      return Promise.all([
     80        audioIsSilence(true, remoteStream),
     81        videoIsBlack(true, remoteStream),
     82      ]);
     83    },
     84  ]);
     85  return test.run().finally(() => tone.stop());
     86 }