Bug 1200472 - Don't allow creating invalid logins with LTU.TestData helpers. r=sfoster
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 13 Nov 2019 01:14:46 +0000
changeset 502095 2e5826c18532792aa955c670e4a7d6f3919c3ff8
parent 502094 877779162b15b1cf31b69187a7eb6be1d834f3df
child 502096 c72321ba48b8af4a8a4e36ee6212121429de6ce9
push id114172
push userdluca@mozilla.com
push dateTue, 19 Nov 2019 11:31:10 +0000
treeherdermozilla-inbound@b5c5ba07d3db [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs1200472
milestone72.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1200472 - Don't allow creating invalid logins with LTU.TestData helpers. r=sfoster Reduce the chance of accidentally creating invalid test cases. Depends on D52629 Differential Revision: https://phabricator.services.mozilla.com/D52630
toolkit/components/passwordmgr/test/LoginTestUtils.jsm
toolkit/components/passwordmgr/test/unit/test_logins_change.js
toolkit/components/passwordmgr/test/unit/test_telemetry.js
--- a/toolkit/components/passwordmgr/test/LoginTestUtils.jsm
+++ b/toolkit/components/passwordmgr/test/LoginTestUtils.jsm
@@ -142,16 +142,19 @@ this.LoginTestUtils.testData = {
       "the username",
       "the password",
       "form_field_username",
       "form_field_password"
     );
     loginInfo.QueryInterface(Ci.nsILoginMetaInfo);
     if (modifications) {
       for (let [name, value] of Object.entries(modifications)) {
+        if (name == "httpRealm" && value !== null) {
+          throw new Error("httpRealm not supported for form logins");
+        }
         loginInfo[name] = value;
       }
     }
     return loginInfo;
   },
 
   /**
    * Returns a new nsILoginInfo for use with HTTP authentication.
@@ -166,16 +169,21 @@ this.LoginTestUtils.testData = {
       null,
       "The HTTP Realm",
       "the username",
       "the password"
     );
     loginInfo.QueryInterface(Ci.nsILoginMetaInfo);
     if (modifications) {
       for (let [name, value] of Object.entries(modifications)) {
+        if (name == "formActionOrigin" && value !== null) {
+          throw new Error(
+            "formActionOrigin not supported for HTTP auth. logins"
+          );
+        }
         loginInfo[name] = value;
       }
     }
     return loginInfo;
   },
 
   /**
    * Returns an array of typical nsILoginInfo that could be stored in the
--- a/toolkit/components/passwordmgr/test/unit/test_logins_change.js
+++ b/toolkit/components/passwordmgr/test/unit/test_logins_change.js
@@ -125,43 +125,39 @@ add_task(function test_invalid_httpRealm
 
   // httpRealm === "", formActionOrigin === null
   checkLoginInvalid(
     TestData.authLogin({ httpRealm: "" }),
     /without a httpRealm or formActionOrigin/
   );
 
   // httpRealm === null, formActionOrigin === ""
-  // This is not enforced for now.
+  // TODO: This is not enforced for now.
   // checkLoginInvalid(TestData.formLogin({ formActionOrigin: "" }),
   //                   /without a httpRealm or formActionOrigin/);
 
   // httpRealm === "", formActionOrigin === ""
-  checkLoginInvalid(
-    TestData.formLogin({ formActionOrigin: "", httpRealm: "" }),
-    /both a httpRealm and formActionOrigin/
-  );
+  let login = TestData.formLogin({ formActionOrigin: "" });
+  login.httpRealm = "";
+  checkLoginInvalid(login, /both a httpRealm and formActionOrigin/);
 
   // !!httpRealm, !!formActionOrigin
-  checkLoginInvalid(
-    TestData.formLogin({ httpRealm: "The HTTP Realm" }),
-    /both a httpRealm and formActionOrigin/
-  );
+  login = TestData.formLogin();
+  login.httpRealm = "The HTTP Realm";
+  checkLoginInvalid(login, /both a httpRealm and formActionOrigin/);
 
   // httpRealm === "", !!formActionOrigin
-  checkLoginInvalid(
-    TestData.formLogin({ httpRealm: "" }),
-    /both a httpRealm and formActionOrigin/
-  );
+  login = TestData.formLogin();
+  login.httpRealm = "";
+  checkLoginInvalid(login, /both a httpRealm and formActionOrigin/);
 
   // !!httpRealm, formActionOrigin === ""
-  checkLoginInvalid(
-    TestData.authLogin({ formActionOrigin: "" }),
-    /both a httpRealm and formActionOrigin/
-  );
+  login = TestData.authLogin();
+  login.formActionOrigin = "";
+  checkLoginInvalid(login, /both a httpRealm and formActionOrigin/);
 });
 
 /**
  * Tests null or empty values in required login properties.
  */
 add_task(function test_missing_properties() {
   checkLoginInvalid(
     TestData.formLogin({ origin: null }),
--- a/toolkit/components/passwordmgr/test/unit/test_telemetry.js
+++ b/toolkit/components/passwordmgr/test/unit/test_telemetry.js
@@ -111,17 +111,23 @@ add_task(function test_initialize() {
   Services.telemetry.canRecordExtended = true;
   registerCleanupFunction(function() {
     Services.telemetry.canRecordExtended = oldCanRecord;
   });
 
   let uniqueNumber = 1;
   for (let loginModifications of StatisticsTestData) {
     loginModifications.origin = `http://${uniqueNumber++}.example.com`;
-    Services.logins.addLogin(TestData.formLogin(loginModifications));
+    let login;
+    if (typeof loginModifications.httpRealm != "undefined") {
+      login = TestData.authLogin(loginModifications);
+    } else {
+      login = TestData.formLogin(loginModifications);
+    }
+    Services.logins.addLogin(login);
   }
 });
 
 /**
  * Tests the collection of statistics related to login metadata.
  */
 add_task(function test_logins_statistics() {
   // Repeat the operation twice to test that histograms are not accumulated.