Bug 1250254 - Enable ESLint "no-throw-literal" rule for PSM. r=dkeeler

MozReview-Commit-ID: LZcitO0FTWH

--HG--
rename : security/manager/.eslintrc => security/manager/.eslintrc.json
extra : transplant_source : %95%EA%08ofJn-l%3D%A2W%90%A6i%E4%5D%A1c%3E
This commit is contained in:
Cykesiopka 2016-02-29 20:05:55 -08:00
Родитель adc97d0666
Коммит a650e7a431
14 изменённых файлов: 59 добавлений и 41 удалений

Просмотреть файл

@ -128,6 +128,10 @@
// No spaces between function name and parentheses
"no-spaced-func": 2,
// Disallow throwing literals (eg. |throw "error"| instead of
// |throw new Error("error")|)
"no-throw-literal": 2,
// No trailing whitespace
"no-trailing-spaces": 2,
@ -174,6 +178,6 @@
"use-isnan": 2,
// Only check typeof against valid results
"valid-typeof": 2,
"valid-typeof": 2
}
}

Просмотреть файл

@ -28,7 +28,7 @@ badCertListener.prototype = {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
throw new Error(Components.results.NS_ERROR_NO_INTERFACE);
},
handle_test_result: function () {
if (gSSLStatus) {

Просмотреть файл

@ -165,7 +165,7 @@ listener.prototype.QueryInterface =
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
throw new Error(Components.results.NS_ERROR_NO_INTERFACE);
};
listener.prototype.notify =

Просмотреть файл

@ -21,7 +21,7 @@ FakeSSLStatus.prototype = {
aIID.equals(Ci.nsISupports)) {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
throw new Error(Cr.NS_ERROR_NO_INTERFACE);
},
};

Просмотреть файл

@ -180,7 +180,7 @@ function isSecurityState(expectedState, message, test)
test(ui && !isInsecure && !isBroken && isEV, "for 'EV' expected flags [0,0,1], " + (message || ""));
break;
default:
throw "Invalid isSecurityState state";
throw new Error("Invalid isSecurityState state");
}
}

Просмотреть файл

@ -229,7 +229,7 @@ function clearSessionCache() {
_getLibraryFunctionWithNoArguments("SSL_ClearSessionCache", "nss3");
}
if (!SSL_ClearSessionCache || SSL_ClearSessionCache() != 0) {
throw "Failed to clear SSL session cache";
throw new Error("Failed to clear SSL session cache");
}
}
@ -634,7 +634,7 @@ FakeSSLStatus.prototype = {
aIID.equals(Ci.nsISupports)) {
return this;
}
throw Components.results.NS_ERROR_NO_INTERFACE;
throw new Error(Cr.NS_ERROR_NO_INTERFACE);
},
};

Просмотреть файл

@ -52,7 +52,7 @@ var XULAppInfoFactory = {
createInstance: function (outer, iid) {
appInfo.QueryInterface(iid);
if (outer != null) {
throw Cr.NS_ERROR_NO_AGGREGATION;
throw new Error(Cr.NS_ERROR_NO_AGGREGATION);
}
return appInfo.QueryInterface(iid);
}

Просмотреть файл

@ -25,7 +25,7 @@ function run_test() {
let xulRuntimeFactory = {
createInstance: function (outer, iid) {
if (outer != null) {
throw Cr.NS_ERROR_NO_AGGREGATION;
throw new Error(Cr.NS_ERROR_NO_AGGREGATION);
}
return xulRuntime.QueryInterface(iid);
}

Просмотреть файл

@ -74,7 +74,7 @@ function tamper(inFilePath, outFilePath, modifications, newEntries) {
// in the input file that wasn't there.
for (let name in modifications) {
if (modifications.hasOwnProperty(name)) {
throw "input file was missing expected entries: " + name;
throw new Error("input file was missing expected entries: " + name);
}
}
@ -102,7 +102,8 @@ function removeEntry(entry, entryInput) { return [null, null]; }
function truncateEntry(entry, entryInput) {
if (entryInput.available() == 0) {
throw "Truncating already-zero length entry will result in identical entry.";
throw new Error("Truncating already-zero length entry will result in " +
"identical entry.");
}
var content = Cc["@mozilla.org/io/string-input-stream;1"]

Просмотреть файл

@ -25,11 +25,12 @@ function downloadRoots() {
req.send();
}
catch (e) {
throw "ERROR: problem downloading Google Root PEMs: " + e;
throw new Error("ERROR: problem downloading Google Root PEMs: " + e);
}
if (req.status != 200) {
throw "ERROR: problem downloading Google Root PEMs. Status: " + req.status;
throw new Error("ERROR: problem downloading Google Root PEMs. Status: " +
req.status);
}
let pem = req.responseText;

Просмотреть файл

@ -13,10 +13,10 @@
"use strict";
if (arguments.length != 3) {
throw "Usage: genHPKPStaticPins.js " +
"<absolute path to PreloadedHPKPins.json> " +
"<an unused argument - see bug 1205406> " +
"<absolute path to StaticHPKPins.h>";
throw new Error("Usage: genHPKPStaticPins.js " +
"<absolute path to PreloadedHPKPins.json> " +
"<an unused argument - see bug 1205406> " +
"<absolute path to StaticHPKPins.h>");
}
var { 'classes': Cc, 'interfaces': Ci, 'utils': Cu, 'results': Cr } = Components;
@ -122,11 +122,12 @@ function download(filename) {
req.send();
}
catch (e) {
throw "ERROR: problem downloading '" + filename + "': " + e;
throw new Error(`ERROR: problem downloading '${filename}': ${e}`);
}
if (req.status != 200) {
throw `ERROR: problem downloading '${filename}': status ${req.status}`;
throw new Error("ERROR: problem downloading '" + filename + "': status " +
req.status);
}
let resultDecoded;
@ -134,7 +135,8 @@ function download(filename) {
resultDecoded = atob(req.responseText);
}
catch (e) {
throw "ERROR: could not decode data as base64 from '" + filename + "': " + e;
throw new Error("ERROR: could not decode data as base64 from '" + filename +
"': " + e);
}
return resultDecoded;
}
@ -147,7 +149,7 @@ function downloadAsJson(filename) {
data = JSON.parse(result);
}
catch (e) {
throw "ERROR: could not parse data from '" + filename + "': " + e;
throw new Error("ERROR: could not parse data from '" + filename + "': " + e);
}
return data;
}
@ -171,7 +173,7 @@ function sha256Base64(input) {
decodedValue = atob(input);
}
catch (e) {
throw `ERROR: could not decode as base64: '${input}': ${e}`;
throw new Error(`ERROR: could not decode as base64: '${input}': ${e}`);
}
// Convert |decodedValue| to an array so that it can be hashed by the
@ -255,7 +257,8 @@ function downloadAndParseChromeCerts(filename, certNameToSKD, certSKDToName) {
} else if (line.startsWith(BEGIN_PUB_KEY)) {
state = IN_PUB_KEY;
} else {
throw "ERROR: couldn't parse Chrome certificate file " + line;
throw new Error("ERROR: couldn't parse Chrome certificate file " +
"line: " + line);
}
break;
case IN_CERT:
@ -293,7 +296,7 @@ function downloadAndParseChromeCerts(filename, certNameToSKD, certSKDToName) {
}
break;
default:
throw "ERROR: couldn't parse Chrome certificate file " + line;
throw new Error("ERROR: couldn't parse Chrome certificate file " + line);
}
}
return [ chromeNameToHash, chromeNameToMozName ];
@ -335,7 +338,7 @@ function downloadAndParseChromePins(filename,
// We should have already added hashes for all of these when we
// imported the certificate file.
if (!certNameToSKD[name]) {
throw "No hash for name: " + name;
throw new Error("ERROR: No hash for name: " + name);
}
} else if (name in chromeNameToMozName) {
pinset.sha256_hashes.push(chromeNameToMozName[name]);
@ -449,7 +452,7 @@ function genExpirationTime() {
function writeFullPinset(certNameToSKD, certSKDToName, pinset) {
let prefix = "kPinset_" + pinset.name;
if (!pinset.sha256_hashes || pinset.sha256_hashes.length == 0) {
throw `ERROR: Pinset ${pinset.name} does not contain any hashes.`;
throw new Error(`ERROR: Pinset ${pinset.name} does not contain any hashes`);
}
writeFingerprints(certNameToSKD, certSKDToName, pinset.name,
pinset.sha256_hashes);
@ -461,7 +464,7 @@ function writeFingerprints(certNameToSKD, certSKDToName, name, hashes) {
let SKDList = [];
for (let certName of hashes) {
if (!(certName in certNameToSKD)) {
throw "Can't find " + certName + " in certNameToSKD";
throw new Error(`ERROR: Can't find '${certName}' in certNameToSKD`);
}
SKDList.push(certNameToSKD[certName]);
}
@ -503,7 +506,7 @@ function writeEntry(entry) {
}
if ("id" in entry) {
if (entry.id >= 256) {
throw "Not enough buckets in histogram";
throw new Error("ERROR: Not enough buckets in histogram");
}
if (entry.id >= 0) {
printVal += entry.id + ", ";

Просмотреть файл

@ -215,8 +215,9 @@ function insertTrustAnchorsFromDatabase() {
// PRIMARY LOGIC
//
if (arguments.length < 1) {
throw "Usage: genRootCAHashes.js <absolute path to current RootHashes.inc>";
if (arguments.length != 1) {
throw new Error("Usage: genRootCAHashes.js " +
"<absolute path to current RootHashes.inc>");
}
var trustAnchorsFile = FileUtils.getFile("CurWorkD", [FILENAME_TRUST_ANCHORS]);

Просмотреть файл

@ -60,11 +60,12 @@ function download() {
req.send();
}
catch (e) {
throw "ERROR: problem downloading '" + SOURCE + "': " + e;
throw new Error(`ERROR: problem downloading '${SOURCE}': ${e}`);
}
if (req.status != 200) {
throw "ERROR: problem downloading '" + SOURCE + "': status " + req.status;
throw new Error("ERROR: problem downloading '" + SOURCE + "': status " +
req.status);
}
var resultDecoded;
@ -72,7 +73,8 @@ function download() {
resultDecoded = atob(req.responseText);
}
catch (e) {
throw "ERROR: could not decode data as base64 from '" + SOURCE + "': " + e;
throw new Error("ERROR: could not decode data as base64 from '" + SOURCE +
"': " + e);
}
// we have to filter out '//' comments, while not mangling the json
@ -82,7 +84,7 @@ function download() {
data = JSON.parse(result);
}
catch (e) {
throw "ERROR: could not parse data from '" + SOURCE + "': " + e;
throw new Error(`ERROR: could not parse data from '${SOURCE}': ${e}`);
}
return data;
}
@ -91,7 +93,8 @@ function getHosts(rawdata) {
var hosts = [];
if (!rawdata || !rawdata.entries) {
throw "ERROR: source data not formatted correctly: 'entries' not found";
throw new Error("ERROR: source data not formatted correctly: 'entries' " +
"not found");
}
for (entry of rawdata.entries) {
@ -101,7 +104,7 @@ function getHosts(rawdata) {
entry.originalIncludeSubdomains = entry.include_subdomains;
hosts.push(entry);
} else {
throw "ERROR: entry not formatted correctly: no name found";
throw new Error("ERROR: entry not formatted correctly: no name found");
}
}
}
@ -157,7 +160,7 @@ function RedirectAndAuthStopper() {}
RedirectAndAuthStopper.prototype = {
// nsIChannelEventSink
asyncOnChannelRedirect: function(oldChannel, newChannel, flags, callback) {
throw Cr.NS_ERROR_ENTITY_CHANGED;
throw new Error(Cr.NS_ERROR_ENTITY_CHANGED);
},
// nsIAuthPrompt2
@ -166,7 +169,7 @@ RedirectAndAuthStopper.prototype = {
},
asyncPromptAuth: function(channel, callback, context, level, authInfo) {
throw Cr.NS_ERROR_NOT_IMPLEMENTED;
throw new Error(Cr.NS_ERROR_NOT_IMPLEMENTED);
},
getInterface: function(iid) {
@ -371,8 +374,9 @@ function combineLists(newHosts, currentHosts) {
// ****************************************************************************
// This is where the action happens:
if (arguments.length < 1) {
throw "Usage: getHSTSPreloadList.js <absolute path to current nsSTSPreloadList.inc>";
if (arguments.length != 1) {
throw new Error("Usage: getHSTSPreloadList.js " +
"<absolute path to current nsSTSPreloadList.inc>");
}
// get the current preload list
var currentHosts = readCurrentList(arguments[0]);

Просмотреть файл

@ -7,7 +7,10 @@
// 2. [obtain firefox source code]
// 3. [build/obtain firefox binaries]
// 4. run `[path to]/run-mozilla.sh [path to]/xpcshell makeCNNICHashes.js \
// [path to]/intermediatesFile
// [path to]/certlist'
// Where |intermediatesFile| is a file containing PEM encoded intermediate
// certificates that the certificates in |certlist| may be issued by.
// where certlist is a file containing a list of paths to certificates to
// be included in the whitelist
@ -232,7 +235,8 @@ function loadIntermediates(intermediatesFile) {
///////////////////////////////////////////////////////////////////////////////
if (arguments.length != 2) {
throw "Usage: makeCNNICHashes.js <intermediates file> <path to list of certificates>";
throw new Error("Usage: makeCNNICHashes.js <PEM intermediates file> " +
"<path to list of certificates>");
}
Services.prefs.setIntPref("security.OCSP.enabled", 0);