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

mozilla / blurts-server / 45ba77d7-fd3c-4064-90eb-157d6aa10611

pending completion
45ba77d7-fd3c-4064-90eb-157d6aa10611

push

circleci

Robert Helmer
update the queue adr

282 of 1631 branches covered (17.29%)

Branch coverage included in aggregate %.

959 of 4375 relevant lines covered (21.92%)

3.65 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
 *
46
 * @param {object} breach breach object from HIBP
47
 * @returns Boolean is it a valid breach
48
 */
49
function isValidBreach (breach) {
50
  return breach.Name !== undefined &&
×
51
    breach.BreachDate !== undefined &&
52
    breach.Title !== undefined &&
53
    breach.Domain !== undefined &&
54
    breach.DataClasses !== undefined
55
}
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