Bug 1252722 - Add additional tests. r=keeler
authorCykesiopka <cykesiopka.bmo@gmail.com>
Thu, 31 Mar 2016 17:33:06 -0700
changeset 291235 0e7aec22dfef3b8f6abd5f3f1a569643bd544800
parent 291234 71b02a7c2340ce884f3650976621eb7c9ab10051
child 291236 f56afd13cb91786fbc21981687de46796a86f9e0
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
Bug 1252722 - Add additional tests. r=keeler MozReview-Commit-ID: Ds5t8RSd1Mk
--- a/security/manager/ssl/tests/unit/test_pkcs11_module.js
+++ b/security/manager/ssl/tests/unit/test_pkcs11_module.js
@@ -97,16 +97,36 @@ function run_test() {
   // Check that finding the test slot by name is possible, and that trying to
   // find a non-present slot fails.
   notEqual(testModule.findSlotByName("Test PKCS11 Slot"), null,
            "Test slot should be findable by name");
   throws(() => testModule.findSlotByName("Not Present"), /NS_ERROR_FAILURE/,
          "Non-present slot should not be findable by name");
+  // Check that the strangely named nsIPKCS11ModuleDB.findSlotByName() works.
+  // In particular, a comment in nsPKCS11Slot.cpp notes that the method
+  // "is essentially the same as nsIPK11Token::findTokenByName, except that it
+  //  returns an nsIPKCS11Slot".
+  let strBundleSvc = Cc["@mozilla.org/intl/stringbundle;1"]
+                       .getService(Ci.nsIStringBundleService);
+  let bundle =
+    strBundleSvc.createBundle("chrome://pipnss/locale/pipnss.properties");
+  let internalTokenName = bundle.GetStringFromName("PrivateTokenDescription");
+  let internalTokenAsSlot = gModuleDB.findSlotByName(internalTokenName);
+  notEqual(internalTokenAsSlot, null,
+           "Internal 'slot' should be findable by name via the module DB");
+  ok(internalTokenAsSlot instanceof Ci.nsIPKCS11Slot,
+     "Module DB findSlotByName() should return a token as an nsIPKCS11Slot");
+  equal(internalTokenAsSlot.name,
+        bundle.GetStringFromName("PrivateSlotDescription"),
+        "Spot check: actual and expected internal 'slot' names should be equal");
+  throws(() => gModuleDB.findSlotByName("Not Present"), /NS_ERROR_FAILURE/,
+         "Non-present 'slot' should not be findable by name via the module DB");
   // Check that deleting the test module makes it disappear from the module list.
   pkcs11.deleteModule("PKCS11 Test Module");
   // Check miscellaneous module DB methods and attributes.
   notEqual(gModuleDB.getInternal(), null,
            "The internal module should be present");
   notEqual(gModuleDB.getInternalFIPS(), null,
--- a/security/manager/ssl/tests/unit/test_pkcs11_slot.js
+++ b/security/manager/ssl/tests/unit/test_pkcs11_slot.js
@@ -34,9 +34,16 @@ function run_test() {
   equal(testSlot.HWVersion, "0.0",
         "Actual and expected hardware version should match");
   equal(testSlot.FWVersion, "0.0",
         "Actual and expected firmware version should match");
   // Note: testSlot.status is not tested because the implementation calls
   //       PK11_IsPresent(), which checks whether the test token is present.
   //       The test module inserts and removes the test token in a tight loop,
   //       so the result might not be deterministic.
+  // Note: testSlot.tokenName isn't tested for the same reason testSlot.status
+  //       isn't.
+  let testToken = testSlot.getToken();
+  notEqual(testToken, null, "getToken() should succeed");
+  equal(testToken.tokenLabel, "Test PKCS11 Tokeñ Label",
+        "Spot check: the actual and expected test token labels should be equal");
--- a/security/manager/ssl/tests/unit/test_pkcs11_token.js
+++ b/security/manager/ssl/tests/unit/test_pkcs11_token.js
@@ -69,37 +69,47 @@ function checkPasswordFeaturesAndResetPa
      "Token should be logged out after an incorrect password was given");
      "Token should still be init with a password even if an incorrect " +
      "password was given");
      "Token should need password init after reset");
+  ok(!token.isLoggedIn(), "Token should be logged out of after reset");
 function run_test() {
   let tokenDB = Cc["@mozilla.org/security/pk11tokendb;1"]
   let token = tokenDB.getInternalKeyToken();
   notEqual(token, null, "The internal token should be present");
   ok(!token.isLoggedIn(), "Token should not be logged into yet");
-  let initialPW = "foo 1234567890`~!#$%^&*()-_=+{[}]|\\:;'\",<.>/?";
+  // Test that attempting to log out even when the token was not logged into
+  // does not result in an error.
+  token.logoutSimple();
+  ok(!token.isLoggedIn(), "Token should still not be logged into");
+  let initialPW = "foo 1234567890`~!@#$%^&*()-_=+{[}]|\\:;'\",<.>/? 一二三";
   token.login(/*force*/ false);
   ok(token.isLoggedIn(), "Token should now be logged into");
   checkPasswordFeaturesAndResetPassword(token, initialPW);
   // We reset the password previously, so we need to initialize again.
+  ok(token.isLoggedIn(),
+     "Token should be logged into after initializing password again");
      "Token should be logged out after calling logoutSimple()");
      "The internal token should not be considered a hardware token");
      "The internal token should always be considered friendly");
+  ok(token.needsLogin(),
+     "The internal token should always need authentication");