Bug 1446880: update setIdentityProvider() to take RTCIdentityProviderOptions. r=mt draft
authorNils Ohlmeier [:drno] <drno@ohlmeier.org>
Mon, 19 Mar 2018 06:16:20 +0000
changeset 777651 b597b7fe0daff9b6fead92b3cc9c2da3e45a671c
parent 777650 76dbf6ae8903f4fe6bfe73eff930abec9c40fafd
child 777652 043a2217af0735ad0a5d0d72398e7771fd055105
push id105260
push userdrno@ohlmeier.org
push dateThu, 05 Apr 2018 03:49:09 +0000
reviewersmt
bugs1446880
milestone61.0a1
Bug 1446880: update setIdentityProvider() to take RTCIdentityProviderOptions. r=mt MozReview-Commit-ID: Hx3LV9Uw7fi
dom/media/PeerConnection.js
dom/media/PeerConnectionIdp.jsm
dom/media/tests/mochitest/identity/identityPcTest.js
dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
dom/media/tests/mochitest/identity/test_loginNeeded.html
dom/media/tests/mochitest/identity/test_setIdentityProvider.html
dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html
dom/media/tests/mochitest/pc.js
--- a/dom/media/PeerConnection.js
+++ b/dom/media/PeerConnection.js
@@ -1057,19 +1057,21 @@ class RTCPeerConnection {
         await this._validateIdentity(sdp, origin);
       }
       await haveSetRemote;
       this._negotiationNeeded = false;
       this.updateNegotiationNeeded();
     });
   }
 
-  setIdentityProvider(provider, protocol, username) {
+  setIdentityProvider(provider,
+                      {protocol, usernameHint, peerIdentity} = {}) {
     this._checkClosed();
-    this._localIdp.setIdentityProvider(provider, protocol, username);
+    this._localIdp.setIdentityProvider(provider,
+                                       protocol, usernameHint, peerIdentity);
   }
 
   async _getIdentityAssertion(origin) {
     await this._certificateReady;
     return this._localIdp.getIdentityAssertion(this._impl.fingerprint, origin);
   }
 
   getIdentityAssertion() {
--- a/dom/media/PeerConnectionIdp.jsm
+++ b/dom/media/PeerConnectionIdp.jsm
@@ -38,21 +38,22 @@ PeerConnectionIdp.prototype = {
     return !!this._idp;
   },
 
   _resetAssertion() {
     this.assertion = null;
     this.idpLoginUrl = null;
   },
 
-  setIdentityProvider(provider, protocol, username) {
+  setIdentityProvider(provider, protocol, usernameHint, peerIdentity) {
     this._resetAssertion();
     this.provider = provider;
-    this.protocol = protocol || "default";
-    this.username = username;
+    this.protocol = protocol;
+    this.username = usernameHint;
+    this.peeridentity = peerIdentity;
     if (this._idp) {
       if (this._idp.isSame(provider, protocol)) {
         return; // noop
       }
       this._idp.stop();
     }
     this._idp = new IdpSandbox(provider, protocol, this._win);
   },
--- a/dom/media/tests/mochitest/identity/identityPcTest.js
+++ b/dom/media/tests/mochitest/identity/identityPcTest.js
@@ -17,18 +17,18 @@ function identityPcTest(remoteOptions) {
     audio: true,
     video: true,
     peerIdentity: id2
   }], [remoteOptions || {
     audio: true,
     video: true,
     peerIdentity: id1
   }]);
-  test.pcLocal.setIdentityProvider('test1.example.com', 'idp.js');
-  test.pcRemote.setIdentityProvider('test2.example.com', 'idp.js');
+  test.pcLocal.setIdentityProvider('test1.example.com', { protocol: 'idp.js' });
+  test.pcRemote.setIdentityProvider('test2.example.com', { protocol: 'idp.js' });
   test.chain.append([
     function PEER_IDENTITY_IS_SET_CORRECTLY(test) {
       // no need to wait to check identity in this case,
       // setRemoteDescription should wait for the IdP to complete
       function checkIdentity(pc, pfx, idp, name) {
         return pc.peerIdentity.then(peerInfo => {
           is(peerInfo.idp, idp, pfx + "IdP check");
           is(peerInfo.name, name + "@" + idp, pfx + "identity check");
--- a/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
+++ b/dom/media/tests/mochitest/identity/test_getIdentityAssertion.html
@@ -16,35 +16,38 @@ function checkIdentity(assertion, identi
   // 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);
+  t.pcLocal.setIdentityProvider('example.com',
+                                { protocol: 'idp.js' + instructions,
+                                  usernameHint: 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', '');
+      t.pcLocal._pc.setIdentityProvider('example.com',
+                                        { protocol: 'idp-bad.js',
+                                          usernameHint: '' });
       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');
               });
     },
 
--- a/dom/media/tests/mochitest/identity/test_loginNeeded.html
+++ b/dom/media/tests/mochitest/identity/test_loginNeeded.html
@@ -19,17 +19,18 @@ function waitForLoginDone() {
       is(e.data, 'LOGINDONE', 'got the right message');
       window.removeEventListener('message', listener);
       resolve();
     });
   });
 }
 
 function checkLogin(t, name, onLoginNeeded) {
-  t.pcLocal.setIdentityProvider('example.com', 'idp.js#login:' + name);
+  t.pcLocal.setIdentityProvider('example.com',
+                                { protocol: 'idp.js#login:' + name });
   return t.pcLocal._pc.getIdentityAssertion()
     .then(a => ok(false, 'should request login'),
           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');
             return t.pcLocal._pc.idpLoginUrl;
--- a/dom/media/tests/mochitest/identity/test_setIdentityProvider.html
+++ b/dom/media/tests/mochitest/identity/test_setIdentityProvider.html
@@ -19,18 +19,22 @@ function checkIdentity(peer, prefix, idp
     is(peerIdentity.idp, idp, prefix + "IdP is correct");
     is(peerIdentity.name, name + "@" + idp, prefix + "identity is correct");
   });
 }
 
 function theTest() {
   var test = new PeerConnectionTest();
   test.setMediaConstraints([{audio: true}], [{audio: true}]);
-  test.pcLocal.setIdentityProvider("test1.example.com", "idp.js", "someone");
-  test.pcRemote.setIdentityProvider("test2.example.com", "idp.js", "someone");
+  test.pcLocal.setIdentityProvider("test1.example.com",
+                                   { protocol: "idp.js",
+                                     usernameHint: "someone" });
+  test.pcRemote.setIdentityProvider("test2.example.com",
+                                    { protocol: "idp.js",
+                                      usernameHinte: "someone"});
 
   test.chain.append([
     function PC_LOCAL_PEER_IDENTITY_IS_SET_CORRECTLY(test) {
       return checkIdentity(test.pcLocal, "local", "test2.example.com", "someone");
     },
     function PC_REMOTE_PEER_IDENTITY_IS_SET_CORRECTLY(test) {
       return checkIdentity(test.pcRemote, "remote", "test1.example.com", "someone");
     },
--- a/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html
+++ b/dom/media/tests/mochitest/identity/test_setIdentityProviderWithErrors.html
@@ -13,17 +13,19 @@
     bug: "942367"
   });
 
 runNetworkTest(function () {
   var test = new PeerConnectionTest();
   test.setMediaConstraints([{audio: true}], [{audio: true}]);
   // No IdP for local.
   // Remote generates a bad assertion, but that only fails to validate
-  test.pcRemote.setIdentityProvider('example.com', 'idp.js#bad-validate', 'nobody');
+  test.pcRemote.setIdentityProvider('example.com',
+                                    { protocol: 'idp.js#bad-validate',
+                                      usernameHint: 'nobody' });
 
   // Save the peerIdentity promises now, since when they reject they are
   // replaced and we expect them to be rejected this time
   var peerIdentityLocal = test.pcLocal._pc.peerIdentity;
   var peerIdentityRemote = test.pcRemote._pc.peerIdentity;
 
   test.chain.append([
     function ONLY_REMOTE_SDP_INCLUDES_IDENTITY_ASSERTION(t) {
--- a/dom/media/tests/mochitest/pc.js
+++ b/dom/media/tests/mochitest/pc.js
@@ -868,18 +868,18 @@ PeerConnectionWrapper.prototype = {
    * Returns the ICE connection state.
    *
    * @returns {object} The local description
    */
   get iceConnectionState() {
     return this._pc.iceConnectionState;
   },
 
-  setIdentityProvider: function(provider, protocol, identity) {
-    this._pc.setIdentityProvider(provider, protocol, identity);
+  setIdentityProvider: function(provider, options) {
+    this._pc.setIdentityProvider(provider, options);
   },
 
   elementPrefix : direction =>
   {
     return [this.label, direction].join('_');
   },
 
   getMediaElementForTrack : function (track, direction)