From 855f4d1a2f2770a81542fef51007cf4dfc92cece Mon Sep 17 00:00:00 2001
From: Shane Tomlinson <stomlinson@mozilla.com>
Date: Mon, 9 Jan 2012 21:19:58 +0000
Subject: [PATCH] Updating the unit tests to go along with the new auth_level
 field in session_context.

---
 resources/static/shared/network.js            |  5 ++-
 resources/static/test/qunit/mocks/xhr.js      |  1 +
 .../qunit/resources/internal_api_unit_test.js |  4 +--
 .../resources/state_machine_unit_test.js      |  4 +--
 .../test/qunit/shared/network_unit_test.js    | 10 +++---
 .../test/qunit/shared/user_unit_test.js       | 32 +++++++++----------
 6 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/resources/static/shared/network.js b/resources/static/shared/network.js
index b1687c5b9..c5d4b625d 100644
--- a/resources/static/shared/network.js
+++ b/resources/static/shared/network.js
@@ -117,7 +117,7 @@ BrowserID.Network = (function() {
   }
 
   function withContext(cb, onFailure) {
-    if (typeof auth_status !== 'undefined' && typeof csrf_token !== 'undefined') cb();
+    if (typeof csrf_token !== 'undefined') cb();
     else {
       var url = "/wsapi/session_context";
       xhr.ajax({
@@ -129,7 +129,7 @@ BrowserID.Network = (function() {
             local: (new Date()).getTime()
           };
           domain_key_creation_time = result.domain_key_creation_time;
-          auth_status = result.authenticated;
+          auth_status = result.auth_level;
           // XXX remove the ABC123
           code_version = result.code_version || "ABC123";
 
@@ -241,7 +241,6 @@ BrowserID.Network = (function() {
     checkAuth: function(onComplete, onFailure) {
       withContext(function() {
         try {
-          if (typeof auth_status === 'undefined') throw "can't get authentication status!";
           if (onComplete) onComplete(auth_status);
         } catch(e) {
           if (onFailure) onFailure(e.toString());
diff --git a/resources/static/test/qunit/mocks/xhr.js b/resources/static/test/qunit/mocks/xhr.js
index 7438c4dba..de42f62ec 100644
--- a/resources/static/test/qunit/mocks/xhr.js
+++ b/resources/static/test/qunit/mocks/xhr.js
@@ -41,6 +41,7 @@ BrowserID.Mocks.xhr = (function() {
       domain_key_creation_time: (new Date().getTime() - (30 * 24 * 60 * 60 * 1000)),
       csrf_token: "csrf",
       authenticated: false,
+      auth_level: undefined,
       code_version: "ABC123",
       random_seed: "H+ZgKuhjVckv/H4i0Qvj/JGJEGDVOXSIS5RCOjY9/Bo="
     };
diff --git a/resources/static/test/qunit/resources/internal_api_unit_test.js b/resources/static/test/qunit/resources/internal_api_unit_test.js
index 988c8efa4..537cba83f 100644
--- a/resources/static/test/qunit/resources/internal_api_unit_test.js
+++ b/resources/static/test/qunit/resources/internal_api_unit_test.js
@@ -57,7 +57,7 @@
     setup: function() {
       network.setXHR(xhr);
       xhr.useResult("valid");
-      xhr.setContextInfo("authenticated", false);
+      xhr.setContextInfo("auth_level", undefined);
       storage.clear();
       moduleManager.reset();
       moduleManager.register("dialog", ModuleMock);
@@ -73,7 +73,7 @@
     ok(bid.internal, "BrowserID.internal exists");
   });
 
-  asyncTest("BrowserID.internal.setPersistent with the user not authenticated", function() {
+  asyncTest("BrowserID.internal.setPersistent unauthenticated user", function() {
     internal.setPersistent(origin, function(status) {
       strictEqual(status, null, "user is not authenticated should not succeed in setting persistent");
 
diff --git a/resources/static/test/qunit/resources/state_machine_unit_test.js b/resources/static/test/qunit/resources/state_machine_unit_test.js
index f02af9d7f..d65d2ec57 100644
--- a/resources/static/test/qunit/resources/state_machine_unit_test.js
+++ b/resources/static/test/qunit/resources/state_machine_unit_test.js
@@ -266,7 +266,7 @@
     var email = "testuser@testuser.com";
     storage.addEmail(email, { type: "secondary" });
 
-    xhr.setContextInfo("authenticated", "assertion");
+    xhr.setContextInfo("auth_level", "assertion");
 
     mediator.publish("email_chosen", {
       email: email,
@@ -280,7 +280,7 @@
   asyncTest("email_chosen with secondary email, user authenticated to secondary - call doEmailChosen", function() {
     var email = "testuser@testuser.com";
     storage.addEmail(email, { type: "secondary" });
-    xhr.setContextInfo("authenticated", "password");
+    xhr.setContextInfo("auth_level", "password");
 
     mediator.publish("email_chosen", {
       email: email,
diff --git a/resources/static/test/qunit/shared/network_unit_test.js b/resources/static/test/qunit/shared/network_unit_test.js
index 9ef4def3f..7a2ea7e16 100644
--- a/resources/static/test/qunit/shared/network_unit_test.js
+++ b/resources/static/test/qunit/shared/network_unit_test.js
@@ -96,19 +96,19 @@
   });
 
   asyncTest("checkAuth with valid authentication", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
     network.checkAuth(function onSuccess(authenticated) {
-      equal(authenticated, true, "we have an authentication");
+      equal(authenticated, "primary", "we have an authentication");
       start();
     }, testHelpers.unexpectedXHRFailure);
   });
 
   asyncTest("checkAuth with invalid authentication", function() {
     xhr.useResult("invalid");
-    xhr.setContextInfo("authenticated", false);
+    xhr.setContextInfo("auth_level", undefined);
 
     network.checkAuth(function onSuccess(authenticated) {
-      equal(authenticated, false, "we are not authenticated");
+      equal(authenticated, undefined, "we are not authenticated");
       start();
     }, testHelpers.unexpectedXHRFailure);
   });
@@ -117,7 +117,7 @@
 
   asyncTest("checkAuth with XHR failure", function() {
     xhr.useResult("ajaxError");
-    xhr.setContextInfo("authenticated", false);
+    xhr.setContextInfo("auth_level", undefined);
 
     // Do not convert this to failureCheck, we do this manually because
     // checkAuth does not make an XHR request.  Since it does not make an XHR
diff --git a/resources/static/test/qunit/shared/user_unit_test.js b/resources/static/test/qunit/shared/user_unit_test.js
index 733e48d2e..4cdc965e6 100644
--- a/resources/static/test/qunit/shared/user_unit_test.js
+++ b/resources/static/test/qunit/shared/user_unit_test.js
@@ -562,9 +562,9 @@ var vep = require("./vep");
 
 
   asyncTest("checkAuthentication with valid authentication", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
     lib.checkAuthentication(function(authenticated) {
-      equal(authenticated, true, "We are authenticated!");
+      equal(authenticated, "primary", "We are authenticated!");
       start();
     });
   });
@@ -572,9 +572,9 @@ var vep = require("./vep");
 
 
   asyncTest("checkAuthentication with invalid authentication", function() {
-    xhr.setContextInfo("authenticated", false);
+    xhr.setContextInfo("auth_level", undefined);
     lib.checkAuthentication(function(authenticated) {
-      equal(authenticated, false, "We are not authenticated!");
+      equal(authenticated, undefined, "We are not authenticated!");
       start();
     });
   });
@@ -589,10 +589,10 @@ var vep = require("./vep");
 
 
   asyncTest("checkAuthenticationAndSync with valid authentication", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
 
     lib.checkAuthenticationAndSync(function(authenticated) {
-      equal(authenticated, true, "We are authenticated!");
+      equal(authenticated, "primary", "We are authenticated!");
       start();
     }, testHelpers.unexpectedXHRFailure);
   });
@@ -600,17 +600,17 @@ var vep = require("./vep");
 
 
   asyncTest("checkAuthenticationAndSync with invalid authentication", function() {
-    xhr.setContextInfo("authenticated", false);
+    xhr.setContextInfo("auth_level", undefined);
 
     lib.checkAuthenticationAndSync(function onComplete(authenticated) {
-      equal(authenticated, false, "We are not authenticated!");
+      equal(authenticated, undefined, "We are not authenticated!");
       start();
     }, testHelpers.unexpectedXHRFailure);
   });
 
 
   asyncTest("checkAuthenticationAndSync with XHR failure", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
 
     failureCheck(lib.checkAuthenticationAndSync);
   });
@@ -1036,7 +1036,7 @@ var vep = require("./vep");
   });
 
   asyncTest("getPersistentSigninAssertion with invalid login - expect null assertion", function() {
-    xhr.setContextInfo("authenticated", false);
+    xhr.setContextInfo("auth_level", undefined);
 
     lib.syncEmailKeypair("testuser@testuser.com", function() {
       storage.site.set(testOrigin, "remember", false);
@@ -1051,7 +1051,7 @@ var vep = require("./vep");
   });
 
   asyncTest("getPersistentSigninAssertion without email set for site - expect null assertion", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
     storage.site.set(testOrigin, "remember", true);
     storage.site.remove(testOrigin, "email");
 
@@ -1062,7 +1062,7 @@ var vep = require("./vep");
   });
 
   asyncTest("getPersistentSigninAssertion without remember set for site - expect null assertion", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
     lib.syncEmailKeypair("testuser@testuser.com", function() {
       storage.site.set(testOrigin, "remember", false);
       storage.site.set(testOrigin, "email", "testuser@testuser.com");
@@ -1078,7 +1078,7 @@ var vep = require("./vep");
   });
 
   asyncTest("getPersistentSigninAssertion with valid login, email, and remember set to true - expect assertion", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
     lib.syncEmailKeypair("testuser@testuser.com", function() {
       storage.site.set(testOrigin, "remember", true);
       storage.site.set(testOrigin, "email", "testuser@testuser.com");
@@ -1094,7 +1094,7 @@ var vep = require("./vep");
   });
 
   asyncTest("getPersistentSigninAssertion with XHR failure", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
     lib.syncEmailKeypair("testuser@testuser.com", function() {
       storage.site.set(testOrigin, "remember", true);
       storage.site.set(testOrigin, "email", "testuser@testuser.com");
@@ -1109,7 +1109,7 @@ var vep = require("./vep");
   });
 
   asyncTest("clearPersistentSignin with invalid login", function() {
-    xhr.setContextInfo("authenticated", false);
+    xhr.setContextInfo("auth_level", undefined);
 
     lib.clearPersistentSignin(function onComplete(success) {
       strictEqual(success, false, "success with invalid login is false");
@@ -1118,7 +1118,7 @@ var vep = require("./vep");
   });
 
   asyncTest("clearPersistentSignin with valid login with remember set to true", function() {
-    xhr.setContextInfo("authenticated", true);
+    xhr.setContextInfo("auth_level", "primary");
     storage.site.set(testOrigin, "remember", true);
 
     lib.clearPersistentSignin(function onComplete(success) {
-- 
GitLab