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

mozilla / blurts-server / #11668

pending completion
#11668

push

circleci

web-flow
Merge pull request #2732 from mozilla/MNTOR-976

Mntor 976: Storage for Breaches

278 of 1080 branches covered (25.74%)

Branch coverage included in aggregate %.

44 of 44 new or added lines in 3 files covered. (100.0%)

948 of 2953 relevant lines covered (32.1%)

2.57 hits per line

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

0.0
/src/scripts/syncBreaches.js
1
/* Cron: Daily
2
 * Fetches the list of breaches from HIBP, sync database with the latest breaches list
3
 *
4
 * Usage:
5
 * node scripts/syncBreaches.js
6
 */
7

8
import { req, formatDataClassesArray } from '../utils/hibp.js'
9
import { getAllBreaches, upsertBreaches } from '../db/tables/breaches.js'
10

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

20
  // sanity check: corrupt data structure
21
  if (!isValidBreach(breach)) throw new Error('Breach data structure is not valid', JSON.stringify(breach))
×
22
}
23

24
console.log('Breaches found: ', breaches.length)
×
25
console.log('Unique breaches based on Name + BreachDate', seen.size)
×
26

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

33
  // get
34
  const result = await getAllBreaches()
×
35
  console.log(result.length)
×
36
  process.exit()
×
37
}
38

39
/**
40
 * Null check for some required field
41
 * @param {Object} breach breach object from HIBP
42
 * @returns Boolean is it a valid breach
43
 */
44
function isValidBreach (breach) {
45
  return breach.Name !== undefined &&
×
46
    breach.BreachDate !== undefined &&
47
    breach.Title !== undefined &&
48
    breach.Domain !== undefined &&
49
    breach.DataClasses !== undefined
50
}
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