Bug 1786197 - Turn on ESLint rule for prefer-boolean-length-check for security. r=keeler

Differential Revision: https://phabricator.services.mozilla.com/D155165
This commit is contained in:
Mark Banner 2022-08-26 13:39:34 +00:00
Родитель 145c8af411
Коммит e3bad2d44a
12 изменённых файлов: 27 добавлений и 29 удалений

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

@ -490,7 +490,6 @@ module.exports = {
"modules/**",
"netwerk/**",
"remote/**",
"security/manager/**",
"storage/test/unit/test_vacuum.js",
"taskcluster/docker/periodic-updates/scripts/**",
"testing/**",

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

@ -700,7 +700,7 @@ async function restoreCerts() {
errorCode = certdb.importPKCS12File(fp.file, password.value);
if (
errorCode == Ci.nsIX509CertDB.ERROR_BAD_PASSWORD &&
password.value.length == 0
!password.value.length
) {
// It didn't like empty string password, try no password.
errorCode = certdb.importPKCS12File(fp.file, null);

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

@ -155,13 +155,13 @@ async function setDetails() {
];
let parsedCert = await parse(pemToDER(cert.getBase64DERString()));
let keyUsages = parsedCert.ext.keyUsages;
if (keyUsages && keyUsages.purposes.length > 0) {
if (keyUsages && keyUsages.purposes.length) {
detailLines.push(
bundle.getFormattedString("clientAuthKeyUsages", [keyUsages.purposes])
);
}
let emailAddresses = cert.getEmailAddresses();
if (emailAddresses.length > 0) {
if (emailAddresses.length) {
let joinedAddresses = emailAddresses.join(", ");
detailLines.push(
bundle.getFormattedString("clientAuthEmailAddresses", [joinedAddresses])

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

@ -46,7 +46,7 @@ function onLoad() {
let bundle = document.getElementById("pippki_bundle");
let caName = gCert.commonName;
if (caName.length == 0) {
if (!caName.length) {
caName = bundle.getString("unnamedCA");
}

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

@ -332,7 +332,7 @@ class IntermediatePreloads {
lazy.log.debug(
`There are ${waiting.length} intermediates awaiting download.`
);
if (waiting.length == 0) {
if (!waiting.length) {
// Nothing to do.
Services.obs.notifyObservers(
null,
@ -605,7 +605,7 @@ class CRLiteFilters {
let fullFiltersDownloaded = filtersDownloaded.filter(
filter => !filter.incremental
);
if (fullFiltersDownloaded.length > 0) {
if (fullFiltersDownloaded.length) {
if (fullFiltersDownloaded.length > 1) {
lazy.log.warn("trying to install more than one full CRLite filter?");
}
@ -643,7 +643,7 @@ class CRLiteFilters {
concatenatedStashes.set(filter.bytes, offset);
offset += filter.bytes.length;
}
if (concatenatedStashes.length > 0) {
if (concatenatedStashes.length) {
lazy.log.debug(
`adding concatenated incremental updates of total length ${concatenatedStashes.length}`
);

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

@ -62,7 +62,7 @@ class OID {
bytes.shift();
let accumulator = 0;
// Lint TODO: prevent overflow here
while (bytes.length > 0) {
while (bytes.length) {
let value = bytes.shift();
accumulator *= 128;
if (value > 128) {

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

@ -18,9 +18,9 @@ async function checkServerCertificates(win, expectedValues = []) {
// The strings we will get from the DOM are localized with Fluent.
// This will wait until the translation is applied.
if (expectedValues.length > 0) {
if (expectedValues.length) {
await BrowserTestUtils.waitForCondition(
() => labels[1].value || labels[1].textContent.length > 0,
() => labels[1].value || !!labels[1].textContent.length,
"At least one label is populated"
);
}

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

@ -188,7 +188,7 @@ add_task(async function testRememberedDecisionsUI() {
);
await BrowserTestUtils.waitForCondition(
() => labels[10].textContent.length > 0,
() => !!labels[10].textContent.length,
"Localized label is populated"
);

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

@ -85,18 +85,17 @@ function asyncTestEV(
) {
let now = Date.now() / 1000;
return new Promise((resolve, reject) => {
let ocspResponder =
expectedOCSPRequestPaths.length > 0
? startOCSPResponder(
SERVER_PORT,
"www.example.com",
"test_ev_certs",
expectedOCSPRequestPaths,
expectedOCSPRequestPaths.slice(),
null,
ocspResponseTypes
)
: failingOCSPResponder();
let ocspResponder = expectedOCSPRequestPaths.length
? startOCSPResponder(
SERVER_PORT,
"www.example.com",
"test_ev_certs",
expectedOCSPRequestPaths,
expectedOCSPRequestPaths.slice(),
null,
ocspResponseTypes
)
: failingOCSPResponder();
let result = new EVCertVerificationResult(
cert.subjectName,
expectedPRErrorCode,

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

@ -90,7 +90,7 @@ function doHash(algo, value, cmp) {
function doHashStream(algo, value, cmp) {
// TODO(Bug 459835): Make updateFromStream() accept zero length streams.
if (value.length == 0) {
if (!value.length) {
return;
}

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

@ -337,7 +337,7 @@ add_task(async function test_preload_basic() {
let localDB = await IntermediatePreloadsClient.client.db;
let data = await localDB.list();
ok(data.length > 0, "should have some entries");
ok(!!data.length, "should have some entries");
// simulate a sync (syncAndDownload doesn't actually... sync.)
await IntermediatePreloadsClient.client.emit("sync", {
data: {
@ -402,7 +402,7 @@ add_task(async function test_delete() {
let localDB = await IntermediatePreloadsClient.client.db;
let data = await localDB.list();
ok(data.length > 0, "should have some entries");
ok(!!data.length, "should have some entries");
let subject = data[0].subjectDN;
let certStorage = Cc["@mozilla.org/security/certstorage;1"].getService(
Ci.nsICertStorage

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

@ -271,7 +271,7 @@ add_task(async function() {
);
let recoveryPhrase = await keystore.asyncGenerateSecret(LABELS[0]);
ok(
recoveryPhrase && recoveryPhrase.length > 0,
recoveryPhrase && !!recoveryPhrase.length,
"we should be able to re-use that label to generate a new secret"
);
await delete_all_secrets();
@ -401,7 +401,7 @@ add_task(async function() {
let recoveryPhrase = await keystore.asyncGenerateSecret(LABELS[0]);
ok(
recoveryPhrase && recoveryPhrase.length > 0,
recoveryPhrase && !!recoveryPhrase.length,
"we should be able to use that label to generate a new secret"
);
ok(