• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mozilla / blurts-server / #11898

pending completion
#11898

push

circleci

web-flow
Merge pull request #2770 from mozilla/license

Add license headers in source files

282 of 1138 branches covered (24.78%)

Branch coverage included in aggregate %.

959 of 3049 relevant lines covered (31.45%)

2.55 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/scripts/syncBreaches.js
1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
 * License, v. 2.0. If a copy of the MPL was not distributed with this
3
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4

5
/* Cron: Daily
6
 * Fetches the list of breaches from HIBP, sync database with the latest breaches list
7
 *
8
 * Usage:
9
 * node scripts/syncBreaches.js
10
 */
11

12
import { req, formatDataClassesArray } from '../utils/hibp.js'
13
import { getAllBreaches, upsertBreaches } from '../db/tables/breaches.js'
14

15
const breachesResponse = await req('/breaches')
×
16
const breaches = []
×
17
const seen = new Set()
×
18
for (const breach of breachesResponse) {
×
19
  breach.DataClasses = formatDataClassesArray(breach.DataClasses)
×
20
  breach.LogoPath = /[^/]*$/.exec(breach.LogoPath)[0]
×
21
  breaches.push(breach)
×
22
  seen.add(breach.Name + breach.BreachDate)
×
23

24
  // sanity check: corrupt data structure
25
  if (!isValidBreach(breach)) throw new Error('Breach data structure is not valid', JSON.stringify(breach))
×
26
}
27

28
console.log('Breaches found: ', breaches.length)
×
29
console.log('Unique breaches based on Name + BreachDate', seen.size)
×
30

31
// sanity check: no duplicate breaches with Name + BreachDate
32
if (seen.size !== breaches.length) {
×
33
  throw new Error('Breaches contain duplicates. Stopping script...')
×
34
} else {
35
  await upsertBreaches(breaches)
×
36

37
  // get
38
  const result = await getAllBreaches()
×
39
  console.log(result.length)
×
40
  process.exit()
×
41
}
42

43
/**
44
 * Null check for some required field
45
 * @param {Object} breach breach object from HIBP
46
 * @returns Boolean is it a valid breach
47
 */
48
function isValidBreach (breach) {
49
  return breach.Name !== undefined &&
×
50
    breach.BreachDate !== undefined &&
51
    breach.Title !== undefined &&
52
    breach.Domain !== undefined &&
53
    breach.DataClasses !== undefined
54
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc