Bug 1356427 - P3. Add a testcase to test download protection will skip checking whitelist for non-binary files. r=francois
authorDimi Lee <dlee@mozilla.com>
Thu, 18 Oct 2018 14:39:41 +0000
changeset 490298 6e0c72599e0b63fe2e4957184c40520c2fa6339c
parent 490297 c3e09876ab13c1b27355f2d0680b0e34a40bbcf4
child 490299 cf707f5b0477c1537f411d1f776ad10303f2ccd2
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersfrancois
bugs1356427
milestone64.0a1
Bug 1356427 - P3. Add a testcase to test download protection will skip checking whitelist for non-binary files. r=francois Add xpcshell test test_whitelisted_non_binary_source. In this test, we pass a whitelisted sourceURI and a non-binary file extension. Check the returned result is NO_LIST to ensure no whitelisted local db query has been made. This patch also adds binary filename for testcases require whitelist query being made. Differential Revision: https://phabricator.services.mozilla.com/D8702
toolkit/components/reputationservice/test/unit/test_app_rep.js
--- a/toolkit/components/reputationservice/test/unit/test_app_rep.js
+++ b/toolkit/components/reputationservice/test/unit/test_app_rep.js
@@ -14,16 +14,18 @@ var gTables = {};
 
 var ALLOW_LIST = 0;
 var BLOCK_LIST = 1;
 var NO_LIST = 2;
 
 var whitelistedURI = createURI("http://foo:bar@whitelisted.com/index.htm#junk");
 var exampleURI = createURI("http://user:password@example.com/i.html?foo=bar");
 var blocklistedURI = createURI("http://baz:qux@blocklisted.com?xyzzy");
+var binaryFile = "binaryFile.exe";
+var nonBinaryFile = "nonBinaryFile.txt";
 
 const appRepURLPref = "browser.safebrowsing.downloads.remote.url";
 
 function readFileToString(aFilename) {
   let f = do_get_file(aFilename);
   let stream = Cc["@mozilla.org/network/file-input-stream;1"]
                  .createInstance(Ci.nsIFileInputStream);
   stream.init(f, -1, 0, 0);
@@ -287,16 +289,17 @@ add_test(function test_blocklist_trumps_
                              "http://localhost:4444/download");
   let counts = get_telemetry_counts();
   let listCounts = counts.listCounts;
   listCounts[BLOCK_LIST]++;
   listCounts[ALLOW_LIST]++;
   gAppRep.queryReputation({
     sourceURI: whitelistedURI,
     referrerURI: blocklistedURI,
+    suggestedFileName: binaryFile,
     fileSize: 12,
   }, function onComplete(aShouldBlock, aStatus) {
     Assert.equal(Cr.NS_OK, aStatus);
     Assert.ok(aShouldBlock);
     check_telemetry(counts.shouldBlock + 1, listCounts);
     run_next_test();
   });
 });
@@ -332,16 +335,17 @@ add_test(function test_redirect_on_block
     principal: secman.createCodebasePrincipal(whitelistedURI, {}),
   };
   badRedirects.appendElement(redirect3);
 
   gAppRep.queryReputation({
     sourceURI: whitelistedURI,
     referrerURI: exampleURI,
     redirects: badRedirects,
+    suggestedFileName: binaryFile,
     fileSize: 12,
   }, function onComplete(aShouldBlock, aStatus) {
     Assert.equal(Cr.NS_OK, aStatus);
     Assert.ok(aShouldBlock);
     check_telemetry(counts.shouldBlock + 1, listCounts);
     run_next_test();
   });
 });
@@ -349,16 +353,35 @@ add_test(function test_redirect_on_block
 add_test(function test_whitelisted_source() {
   Services.prefs.setCharPref(appRepURLPref,
                              "http://localhost:4444/download");
   let counts = get_telemetry_counts();
   let listCounts = counts.listCounts;
   listCounts[ALLOW_LIST]++;
   gAppRep.queryReputation({
     sourceURI: whitelistedURI,
+    suggestedFileName: binaryFile,
+    fileSize: 12,
+  }, function onComplete(aShouldBlock, aStatus) {
+    Assert.equal(Cr.NS_OK, aStatus);
+    Assert.ok(!aShouldBlock);
+    check_telemetry(counts.shouldBlock, listCounts);
+    run_next_test();
+  });
+});
+
+add_test(function test_whitelisted_non_binary_source() {
+  Services.prefs.setCharPref(appRepURLPref,
+                             "http://localhost:4444/download");
+  let counts = get_telemetry_counts();
+  let listCounts = counts.listCounts;
+  listCounts[NO_LIST]++;
+  gAppRep.queryReputation({
+    sourceURI: whitelistedURI,
+    suggestedFileName: nonBinaryFile,
     fileSize: 12,
   }, function onComplete(aShouldBlock, aStatus) {
     Assert.equal(Cr.NS_OK, aStatus);
     Assert.ok(!aShouldBlock);
     check_telemetry(counts.shouldBlock, listCounts);
     run_next_test();
   });
 });