Bug 1076708 - [Loop] Close the verification code windows cause the app trying to authenticate infinitely. r=spenrose
authorFernando Jiménez <ferjmoreno@gmail.com>
Fri, 10 Oct 2014 14:38:51 +0200
changeset 209812 c716f771ecbeb9fd6cbf7c076d63e52cca0f79f2
parent 209811 68070e4a6d9aab8ebf341147f7444f046abe6726
child 209813 b724fb89c334f3bf823eff4076a947b2f8082300
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersspenrose
bugs1076708
milestone35.0a1
Bug 1076708 - [Loop] Close the verification code windows cause the app trying to authenticate infinitely. r=spenrose
services/mobileid/MobileIdentityManager.jsm
services/mobileid/tests/xpcshell/test_mobileid_manager.js
--- a/services/mobileid/MobileIdentityManager.jsm
+++ b/services/mobileid/MobileIdentityManager.jsm
@@ -412,17 +412,17 @@ this.MobileIdentityManager = {
 
   /*********************************************************
    * UI callbacks
    ********************************************************/
 
   onUICancel: function() {
     log.debug("UI cancel");
     if (this.activeVerificationFlow) {
-      this.activeVerificationFlow.cleanup(true);
+      this.rejectVerification();
     }
   },
 
   onUIResendCode: function() {
     log.debug("UI resend code");
     if (!this.activeVerificationFlow) {
       return;
     }
@@ -462,33 +462,33 @@ this.MobileIdentityManager = {
    ********************************************************/
 
   rejectVerification: function(aReason) {
     if (!this.activeVerificationDeferred) {
       return;
     }
     this.activeVerificationDeferred.reject(aReason);
     this.activeVerificationDeferred = null;
-    this.cleanupVerification(true);
+    this.cleanupVerification(true /* unregister */);
   },
 
   resolveVerification: function(aResult) {
     if (!this.activeVerificationDeferred) {
       return;
     }
     this.activeVerificationDeferred.resolve(aResult);
     this.activeVerificationDeferred = null;
     this.cleanupVerification();
   },
 
-  cleanupVerification: function() {
+  cleanupVerification: function(aUnregister = false) {
     if (!this.activeVerificationFlow) {
       return;
     }
-    this.activeVerificationFlow.cleanup();
+    this.activeVerificationFlow.cleanup(aUnregister);
     this.activeVerificationFlow = null;
   },
 
   doVerification: function() {
     this.activeVerificationFlow.doVerification()
     .then(
       (verificationResult) => {
         log.debug("onVerificationResult ");
--- a/services/mobileid/tests/xpcshell/test_mobileid_manager.js
+++ b/services/mobileid/tests/xpcshell/test_mobileid_manager.js
@@ -1454,8 +1454,59 @@ add_test(function() {
     principal: PRINCIPAL,
     target: mm,
     json: {
       promiseId: promiseId,
       options: {}
     }
   });
 });
+
+add_test(function() {
+  do_print("= Cancel verification flow =");
+
+  do_register_cleanup(cleanup);
+
+  do_test_pending();
+
+  let _sessionToken = Date.now();
+
+  let ui = new MockUi();
+  ui.verificationCodePrompt = function() {
+    MobileIdentityManager.onUICancel();
+  };
+  MobileIdentityManager.ui = ui;
+
+  let credStore = new MockCredStore();
+  MobileIdentityManager.credStore = credStore;
+
+  let client = new MockClient();
+  MobileIdentityManager.client = client;
+
+  let promiseId = Date.now();
+  let mm = {
+    sendAsyncMessage: function(aMsg, aData) {
+      do_print("sendAsyncMessage " + aMsg + " - " + JSON.stringify(aData));
+
+      // Check result.
+      do_check_eq(aMsg, GET_ASSERTION_RETURN_KO);
+      do_check_eq(typeof aData, "object");
+      do_check_eq(aData.promiseId, promiseId);
+      do_check_eq(aData.error, DIALOG_CLOSED_BY_USER);
+
+      do_test_finished();
+      run_next_test();
+    }
+  };
+
+  addPermission(Ci.nsIPermissionManager.ALLOW_ACTION);
+
+  MobileIdentityManager.receiveMessage({
+    name: GET_ASSERTION_IPC_MSG,
+    principal: PRINCIPAL,
+    target: mm,
+    json: {
+      promiseId: promiseId,
+      options: {}
+    }
+  });
+});
+