Bug 1423844 - Enable ESLint for dom/security/test/unit/ r=Standard8,jkt
authorchampionshuttler <shivams2799@gmail.com>
Mon, 17 Dec 2018 15:47:44 +0000
changeset 450960 8df1cbc7c991ab921e26d53c1ddc664e9beeef18
parent 450959 cb5149cb7718033d55bbb5a8acda1d26967d1243
child 450961 8565623b2025f012117a3801a522e251c9446dc3
push id35222
push useraiakab@mozilla.com
push dateMon, 17 Dec 2018 22:01:00 +0000
treeherdermozilla-central@edf1f05e9d00 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersStandard8, jkt
bugs1423844
milestone66.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 1423844 - Enable ESLint for dom/security/test/unit/ r=Standard8,jkt Enable ESLint for dom/security/test/unit Differential Revision: https://phabricator.services.mozilla.com/D14617
.eslintignore
dom/security/test/unit/test_csp_reports.js
dom/security/test/unit/test_csp_upgrade_insecure_request_header.js
dom/security/test/unit/test_isOriginPotentiallyTrustworthy.js
--- a/.eslintignore
+++ b/.eslintignore
@@ -210,17 +210,16 @@ dom/plugins/test/unit/**
 dom/promise/**
 dom/push/**
 dom/quota/**
 dom/security/test/cors/**
 dom/security/test/csp/**
 dom/security/test/general/**
 dom/security/test/mixedcontentblocker/**
 dom/security/test/sri/**
-dom/security/test/unit/**
 dom/serviceworkers/**
 dom/smil/**
 dom/svg/**
 dom/system/**
 dom/tests/browser/**
 dom/tests/html/**
 dom/tests/mochitest/**
 dom/tests/unit/**
--- a/dom/security/test/unit/test_csp_reports.js
+++ b/dom/security/test/unit/test_csp_reports.js
@@ -1,13 +1,13 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
-ChromeUtils.import('resource://gre/modules/NetUtil.jsm');
+ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/Services.jsm");
 ChromeUtils.import("resource://testing-common/httpd.js");
 
 var httpServer = new HttpServer();
 httpServer.start(-1);
 var testsToFinish = 0;
 
 var principal;
@@ -28,31 +28,31 @@ function makeReportHandler(testpath, mes
       return;
     }
 
     // check content-type of report is "application/csp-report"
     var contentType = request.hasHeader("Content-Type")
                     ? request.getHeader("Content-Type") : undefined;
     if (contentType !== "application/csp-report") {
       do_throw("violation report should have the 'application/csp-report' " +
-               "content-type, when in fact it is " + contentType.toString())
+               "content-type, when in fact it is " + contentType.toString());
     }
 
     // obtain violation report
     var reportObj = JSON.parse(
           NetUtil.readInputStreamToString(
             request.bodyInputStream,
             request.bodyInputStream.available()));
 
     // dump("GOT REPORT:\n" + JSON.stringify(reportObj) + "\n");
     // dump("TESTPATH:    " + testpath + "\n");
     // dump("EXPECTED:  \n" + JSON.stringify(expectedJSON) + "\n\n");
 
     for (var i in expectedJSON)
-      Assert.equal(expectedJSON[i], reportObj['csp-report'][i]);
+      Assert.equal(expectedJSON[i], reportObj["csp-report"][i]);
 
     testsToFinish--;
     httpServer.registerPathHandler(testpath, null);
     if (testsToFinish < 1)
       httpServer.stop(do_test_finished);
     else
       do_test_finished();
   };
@@ -75,30 +75,28 @@ function makeTest(id, expectedJSON, useR
                                ":" + REPORT_SERVER_PORT +
                                "/test" + id;
   var selfuri = NetUtil.newURI(REPORT_SERVER_URI +
                                ":" + REPORT_SERVER_PORT +
                                "/foo/self");
 
   dump("Created test " + id + " : " + policy + "\n\n");
 
-  let ssm = Cc["@mozilla.org/scriptsecuritymanager;1"]
-              .getService(Ci.nsIScriptSecurityManager);
-  principal = ssm.createCodebasePrincipal(selfuri, {});
+  principal = Services.scriptSecurityManager.createCodebasePrincipal(selfuri, {});
   csp.setRequestContext(null, principal);
 
   // Load up the policy
   // set as report-only if that's the case
   csp.appendPolicy(policy, useReportOnlyPolicy, false);
 
   // prime the report server
   var handler = makeReportHandler("/test" + id, "Test " + id, expectedJSON);
   httpServer.registerPathHandler("/test" + id, handler);
 
-  //trigger the violation
+  // trigger the violation
   callback(csp);
 }
 
 function run_test() {
   var selfuri = NetUtil.newURI(REPORT_SERVER_URI +
                                ":" + REPORT_SERVER_PORT +
                                "/foo/self");
 
@@ -117,21 +115,21 @@ function run_test() {
 
         // this is not a report only policy, so it better block inline scripts
         Assert.ok(!inlineOK);
       });
 
   // test that eval violations cause a report.
   makeTest(1, {"blocked-uri": "eval",
                // JSON script-sample is UTF8 encoded
-               "script-sample" : "\xc2\xa3\xc2\xa5\xc2\xb5\xe5\x8c\x97\xf0\xa0\x9d\xb9",
+               "script-sample": "\xc2\xa3\xc2\xa5\xc2\xb5\xe5\x8c\x97\xf0\xa0\x9d\xb9",
                "line-number": 1,
                "column-number": 2}, false,
       function(csp) {
-        let evalOK = true, oReportViolation = {'value': false};
+        let evalOK = true, oReportViolation = {"value": false};
         evalOK = csp.getAllowsEval(oReportViolation);
 
         // this is not a report only policy, so it better block eval
         Assert.ok(!evalOK);
         // ... and cause reports to go out
         Assert.ok(oReportViolation.value);
 
         if (oReportViolation.value) {
@@ -173,17 +171,17 @@ function run_test() {
 
         // this is a report only policy, so it better allow inline scripts
         Assert.ok(inlineOK);
       });
 
   // test that eval violations cause a report in report-only policy
   makeTest(4, {"blocked-uri": "inline"}, true,
       function(csp) {
-        let evalOK = true, oReportViolation = {'value': false};
+        let evalOK = true, oReportViolation = {"value": false};
         evalOK = csp.getAllowsEval(oReportViolation);
 
         // this is a report only policy, so it better allow eval
         Assert.ok(evalOK);
         // ... but still cause reports to go out
         Assert.ok(oReportViolation.value);
 
         if (oReportViolation.value) {
@@ -220,17 +218,16 @@ function run_test() {
                      NetUtil.newURI("intent://mymaps.com/maps?um=1&ie=UTF-8&fb=1&sll"),
                      null, null, null, null, true);
       });
 
   // test fragment removal
   var selfSpec = REPORT_SERVER_URI + ":" + REPORT_SERVER_PORT + "/foo/self/foo.js";
   makeTest(7, {"blocked-uri": selfSpec}, false,
     function(csp) {
-      var uri = NetUtil
       // shouldLoad creates and sends out the report here.
       csp.shouldLoad(Ci.nsIContentPolicy.TYPE_SCRIPT,
                      null, // nsICSPEventListener
                      NetUtil.newURI(selfSpec + "#bar"),
                      null, null, null, null, true);
       });
 
   // test scheme of ftp:
--- a/dom/security/test/unit/test_csp_upgrade_insecure_request_header.js
+++ b/dom/security/test/unit/test_csp_upgrade_insecure_request_header.js
@@ -1,82 +1,80 @@
 ChromeUtils.import("resource://testing-common/httpd.js");
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-var prefs = Cc["@mozilla.org/preferences-service;1"].
-              getService(Ci.nsIPrefBranch);
 
 // Since this test creates a TYPE_DOCUMENT channel via javascript, it will
 // end up using the wrong LoadInfo constructor. Setting this pref will disable
 // the ContentPolicyType assertion in the constructor.
-prefs.setBoolPref("network.loadinfo.skip_type_assertion", true);
+Services.prefs.setBoolPref("network.loadinfo.skip_type_assertion", true);
 
 XPCOMUtils.defineLazyGetter(this, "URL", function() {
   return "http://localhost:" + httpserver.identity.primaryPort;
 });
 
 var httpserver =  null;
 var channel = null;
 var curTest = null;
 var testpath = "/footpath";
 
 var tests = [
   {
     description: "should not set request header for TYPE_OTHER",
     expectingHeader: false,
-    contentType: Ci.nsIContentPolicy.TYPE_OTHER
+    contentType: Ci.nsIContentPolicy.TYPE_OTHER,
   },
   {
     description: "should set request header for TYPE_DOCUMENT",
     expectingHeader: true,
-    contentType: Ci.nsIContentPolicy.TYPE_DOCUMENT
+    contentType: Ci.nsIContentPolicy.TYPE_DOCUMENT,
   },
   {
     description: "should set request header for TYPE_SUBDOCUMENT",
     expectingHeader: true,
-    contentType: Ci.nsIContentPolicy.TYPE_SUBDOCUMENT
+    contentType: Ci.nsIContentPolicy.TYPE_SUBDOCUMENT,
   },
   {
     description: "should not set request header for TYPE_IMG",
     expectingHeader: false,
-    contentType: Ci.nsIContentPolicy.TYPE_IMG
+    contentType: Ci.nsIContentPolicy.TYPE_IMG,
   },
 ];
 
 function ChannelListener() {
 }
 
 ChannelListener.prototype = {
-  onStartRequest: function(request, context) { },
-  onDataAvailable: function(request, context, stream, offset, count) {
+  onStartRequest(request, context) { },
+  onDataAvailable(request, context, stream, offset, count) {
     do_throw("Should not get any data!");
   },
-  onStopRequest: function(request, context, status) {
+  onStopRequest(request, context, status) {
     var upgrade_insecure_header = false;
     try {
       if (request.getRequestHeader("Upgrade-Insecure-Requests")) {
         upgrade_insecure_header = true;
       }
-    }
-    catch (e) {
+    } catch (e) {
       // exception is thrown if header is not available on the request
     }
     // debug
     // dump("executing test: " + curTest.description);
-    Assert.equal(upgrade_insecure_header, curTest.expectingHeader)
+    Assert.equal(upgrade_insecure_header, curTest.expectingHeader);
     run_next_test();
   },
 };
 
 function setupChannel(aContentType) {
   var chan = NetUtil.newChannel({
     uri: URL + testpath,
     loadUsingSystemPrincipal: true,
-    contentPolicyType: aContentType
+    contentPolicyType: aContentType,
   });
   chan.QueryInterface(Ci.nsIHttpChannel);
   chan.requestMethod = "GET";
   return chan;
 }
 
 function serverHandler(metadata, response) {
   // no need to perform anything here
--- a/dom/security/test/unit/test_isOriginPotentiallyTrustworthy.js
+++ b/dom/security/test/unit/test_isOriginPotentiallyTrustworthy.js
@@ -3,27 +3,27 @@
 
 /*
  * Tests the "Is origin potentially trustworthy?" logic from
  * <https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy>.
  */
 
 ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
 ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
+ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gScriptSecurityManager",
                                    "@mozilla.org/scriptsecuritymanager;1",
                                    "nsIScriptSecurityManager");
 
 XPCOMUtils.defineLazyServiceGetter(this, "gContentSecurityManager",
                                    "@mozilla.org/contentsecuritymanager;1",
                                    "nsIContentSecurityManager");
 
-var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
-prefs.setCharPref("dom.securecontext.whitelist", "example.net,example.org");
+Services.prefs.setCharPref("dom.securecontext.whitelist", "example.net,example.org");
 
 add_task(async function test_isOriginPotentiallyTrustworthy() {
   for (let [uriSpec, expectedResult] of [
     ["http://example.com/", false],
     ["https://example.com/", true],
     ["http://localhost/", true],
     ["http://127.0.0.1/", true],
     ["file:///", true],
@@ -38,14 +38,14 @@ add_task(async function test_isOriginPot
   ]) {
     let uri = NetUtil.newURI(uriSpec);
     let principal = gScriptSecurityManager.createCodebasePrincipal(uri, {});
     Assert.equal(gContentSecurityManager.isOriginPotentiallyTrustworthy(principal),
                  expectedResult);
   }
   // And now let's test whether .onion sites are properly treated when
   // whitelisted, see bug 1382359.
-  prefs.setBoolPref("dom.securecontext.whitelist_onions", true);
+  Services.prefs.setBoolPref("dom.securecontext.whitelist_onions", true);
   let uri = NetUtil.newURI("http://1234567890abcdef.onion/");
   let principal = gScriptSecurityManager.createCodebasePrincipal(uri, {});
   Assert.equal(gContentSecurityManager.isOriginPotentiallyTrustworthy(principal),
                true);
 });