Re-enable prefer-const and a few minor tweaks
This commit is contained in:
Родитель
2900cc27c7
Коммит
7057f4e73d
|
@ -19,7 +19,7 @@ module.exports = {
|
|||
"no-unused-vars": ["error", {vars: "all", args: "none", ignoreRestSiblings: false}],
|
||||
"no-var": "error",
|
||||
"no-warning-comments": "warn",
|
||||
"prefer-const": "off",
|
||||
"prefer-const": "error",
|
||||
"quotes": ["error", "double"],
|
||||
"require-jsdoc": "off",
|
||||
"semi": ["error", "always"],
|
||||
|
|
|
@ -23,7 +23,7 @@ const kEnvironmentVariables = [
|
|||
|
||||
const AppConstants = {
|
||||
init() {
|
||||
for (let v of kEnvironmentVariables) {
|
||||
for (const v of kEnvironmentVariables) {
|
||||
if (process.env[v] === undefined) {
|
||||
throw new Error(`Required environment variable was not set: ${v}`);
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ const request = require("request");
|
|||
const pkg = require("./package.json");
|
||||
|
||||
const HIBP_AUTH = `Bearer ${AppConstants.HIBP_API_TOKEN}`;
|
||||
const USER_AGENT = `${pkg.name}@${pkg.version}`;
|
||||
const HIBP_USER_AGENT = `${pkg.name}/${pkg.version}`;
|
||||
const BREACH_HASHSET_DIR = "breach_hashsets";
|
||||
|
||||
|
||||
|
@ -22,38 +22,53 @@ function getBreachHashset(breach) {
|
|||
* See https://haveibeenpwned.com/API/v2#BreachModel for more
|
||||
*/
|
||||
if (breach.IsActive && breach.IsVerified && breach.DataClasses.includes("Email addresses")) {
|
||||
console.log("Active, verified breach with email addresses: " + breach.Name);
|
||||
const url = AppConstants.HIBP_API_ROOT + "/enterprisesubscriber/hashset/" + breach.Name;
|
||||
console.log("url: " + url);
|
||||
|
||||
const url = `${AppConstants.HIBP_API_ROOT}/enterprisesubscriber/hashset/${breach.Name}`;
|
||||
const headers = {
|
||||
"User-Agent": USER_AGENT,
|
||||
"User-Agent": HIBP_USER_AGENT,
|
||||
"Authorization": HIBP_AUTH,
|
||||
};
|
||||
const hashsetRequestObject = {
|
||||
url: url,
|
||||
headers: headers,
|
||||
url,
|
||||
headers,
|
||||
};
|
||||
const BREACH_HASHSET_ZIP = path.join(BREACH_HASHSET_DIR, `${breach.Name}.zip`);
|
||||
|
||||
request(hashsetRequestObject).pipe(fs.createWriteStream(path.join(BREACH_HASHSET_DIR, `${breach.Name}.zip`)));
|
||||
console.log(`Active, verified breach with email addresses: ${breach.Name}`);
|
||||
console.log(`Fetching ${url}...`);
|
||||
request(hashsetRequestObject).pipe(fs.createWriteStream(BREACH_HASHSET_ZIP));
|
||||
}
|
||||
}
|
||||
|
||||
function handleBreachesResponse(error, response, body) {
|
||||
let breachesJSON = JSON.parse(body);
|
||||
for (let breach of breachesJSON) {
|
||||
getBreachHashset(breach);
|
||||
if (error) {
|
||||
console.error(error);
|
||||
// We can `process.exit()` here since it's a CLI script.
|
||||
// eslint-disable-next-line no-process-exit
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
try {
|
||||
const breachesJSON = JSON.parse(body);
|
||||
|
||||
if (!fs.existsSync(BREACH_HASHSET_DIR)) {
|
||||
fs.mkdirSync(BREACH_HASHSET_DIR);
|
||||
}
|
||||
for (const breach of breachesJSON) {
|
||||
getBreachHashset(breach);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
}
|
||||
|
||||
const breachesRequestObject = {
|
||||
url: AppConstants.HIBP_API_ROOT + "/breaches",
|
||||
headers: {
|
||||
"User-Agent": USER_AGENT,
|
||||
},
|
||||
};
|
||||
|
||||
if (!fs.existsSync(BREACH_HASHSET_DIR)) {
|
||||
fs.mkdirSync(BREACH_HASHSET_DIR);
|
||||
function getBreaches() {
|
||||
const breachesRequestObject = {
|
||||
url: `${AppConstants.HIBP_API_ROOT}/breaches`,
|
||||
headers: {
|
||||
"User-Agent": HIBP_USER_AGENT,
|
||||
},
|
||||
};
|
||||
request(breachesRequestObject, handleBreachesResponse);
|
||||
}
|
||||
request(breachesRequestObject, handleBreachesResponse);
|
||||
|
||||
getBreaches();
|
||||
|
|
|
@ -39,6 +39,7 @@
|
|||
"url": "git+https://github.com/mozilla/blurts-server.git"
|
||||
},
|
||||
"scripts": {
|
||||
"get_hashsets": "node get_hashsets",
|
||||
"lint": "eslint .",
|
||||
"pretest": "eslint .",
|
||||
"start": "node server.js",
|
||||
|
|
|
@ -77,7 +77,7 @@ router.post("/breached", (req, res) => {
|
|||
let emailQueue = Promise.resolve();
|
||||
// Send notification email to the intersection of the set of
|
||||
// emails in the request and the set of registered emails.
|
||||
for (let email of emails) {
|
||||
for (const email of emails) {
|
||||
if (gEmails.has(email)) {
|
||||
emailQueue = emailQueue.then(() => {
|
||||
EmailUtils.sendEmail(email, "Firefox Breach Alert",
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
const crypto = require("crypto");
|
||||
const stdin = process.openStdin();
|
||||
|
||||
const PROMPT = "\nEnter an email address to get the SHA1 hash as it would appear in a HIBP hashset file:";
|
||||
|
||||
console.log("Enter an email address to get the SHA1 hash as it would appear in a HIBP hashset file.");
|
||||
console.log(PROMPT);
|
||||
|
||||
stdin.addListener("data", data => {
|
||||
const shasum = crypto.createHash("sha1");
|
||||
const trimmedString = data.toString().trim();
|
||||
console.log("You entered: [" + trimmedString + "], sha1 hash of lowercase: ");
|
||||
const shasum = crypto.createHash("sha1");
|
||||
shasum.update(trimmedString.toLowerCase());
|
||||
console.log(shasum.digest("hex"));
|
||||
console.log("Enter an email address to get the SHA1 hash as it would appear in a HIBP hashset file.");
|
||||
console.log(`You entered: [${trimmedString}], sha1 hash of lowercase: ${shasum.digest("hex")}`);
|
||||
console.log(PROMPT);
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче