Skip to content

Commit

Permalink
move load-breaches and add-breached-emails to scripts/
Browse files Browse the repository at this point in the history
  • Loading branch information
groovecoder committed May 16, 2018
1 parent 43c6ae3 commit b1580b2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ const arg = require("arg");

require("dotenv").load();

const DBUtils = require("../../db/utils");
const DBUtils = require("../db/utils");


const args = arg({
"--createAMBreach": Boolean,
"--extraTestEmail": String,
"--help": Boolean,
});

if (args["--help"]) {
console.log("Usage: node make-breach-with-emails.js [--createAMBreach] [--extraTestEmail=<...>]");
console.log("--createAMBreach creates the 'AllMusic' test fixture breach.");
console.log("--extraTestEmail adds the supplied test email address and includes it in the LinkedIn, Adobe, and AllMusic breaches.");
console.log("Usage: node add-breached-emails.js [--extraTestEmail=<...>]");
console.log("Adds test[1-3]@test.com emails to LinkedIn, Adobe, and AllMusic breaches.");
console.log("--extraTestEmail also adds the supplied test email address and includes it in the LinkedIn, Adobe, and AllMusic breaches.");
// We can `process.exit()` here since it's a CLI script.
// eslint-disable-next-line no-process-exit
process.exit();
Expand All @@ -38,16 +37,7 @@ const sampleBreaches = [
];

(async () => {
if (args["--createAMBreach"]) {
await DBUtils.createBreach("AllMusic", {
Name: "AllMusic",
BreachDate: "2015-012-06",
DataClasses: ["Email addresses", "IP addresses", "Passwords", "Usernames", "Website activity"],
PwnCount: 1436486,
});
}
for (const sB of sampleBreaches) {
await DBUtils.getBreachByName(sB.name);
for (const e of sB.emails) {
await DBUtils.addBreachedEmail(sB.name, e);
if (args["--extraTestEmail"]) {
Expand Down
22 changes: 22 additions & 0 deletions scripts/load-breaches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";

const arg = require("arg");
const got = require("got");

const AppConstants = require("../app-constants");
Expand All @@ -9,6 +10,19 @@ const pkg = require("../package.json");
const HIBP_USER_AGENT = `${pkg.name}/${pkg.version}`;


const args = arg({
"--createAMBreach": Boolean,
"--help": Boolean,
});

if (args["--help"]) {
console.log("Usage: node load-breaaches.js [--createAMBreach]");
console.log("--createAMBreach creates the 'AllMusic' test fixture breach.");
// We can `process.exit()` here since it's a CLI script.
// eslint-disable-next-line no-process-exit
process.exit();
}

async function handleBreachesResponse(response) {
try {
const breachesJSON = JSON.parse(response.body);
Expand All @@ -25,6 +39,14 @@ async function handleBreachesResponse(response) {
}

(async () => {
if (args["--createAMBreach"]) {
await DBUtils.createBreach("AllMusic", {
Name: "AllMusic",
BreachDate: "2015-012-06",
DataClasses: ["Email addresses", "IP addresses", "Passwords", "Usernames", "Website activity"],
PwnCount: 1436486,
});
}
try {
const breachesResponse = await got(
`${AppConstants.HIBP_API_ROOT}/breaches`,
Expand Down
File renamed without changes.

0 comments on commit b1580b2

Please sign in to comment.