• 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/db/tables/breaches.js
1
import Knex from 'knex'
2
import knexConfig from '../knexfile.js'
3
import mozlog from '../../utils/log.js'
4
const knex = Knex(knexConfig)
×
5
const log = mozlog('DB.breaches')
×
6

7
/**
8
 * Get all records from "breaches" table
9
 * @returns Array of all records from "breaches" table
10
 */
11
async function getAllBreaches () {
12
  return knex('breaches')
×
13
    .returning()
14
}
15

16
/**
17
 * Upsert breaches into "breaches" table
18
 * @param {Array} hibpBreaches breaches array from HIBP API
19
 * @returns
20
 */
21
async function upsertBreaches (hibpBreaches) {
22
  log.debug('upsertBreaches', hibpBreaches[0])
×
23

24
  return knex.transaction(async trx => {
×
25
    const queries = hibpBreaches.map(breach =>
×
26
      knex('breaches')
×
27
        .insert({
28
          name: breach.Name,
29
          title: breach.Title,
30
          domain: breach.Domain,
31
          breach_date: breach.BreachDate,
32
          added_date: breach.AddedDate,
33
          modified_date: breach.ModifiedDate,
34
          pwn_count: breach.PwnCount,
35
          description: breach.Description,
36
          logo_path: breach.LogoPath,
37
          data_classes: breach.DataClasses,
38
          is_verified: breach.IsVerified,
39
          is_fabricated: breach.IsFabricated,
40
          is_sensitive: breach.IsSensitive,
41
          is_retired: breach.IsRetired,
42
          is_spam_list: breach.IsSpamList,
43
          is_malware: breach.IsMalware
44
        })
45
        .onConflict('name')
46
        .merge()
47
        .transacting(trx)
48
    )
49

50
    try {
×
51
      const value = await Promise.all(queries)
×
52
      return trx.commit(value)
×
53
    } catch (error) {
54
      return trx.rollback(error)
×
55
    }
56
  })
57
}
58

59
export {
60
  getAllBreaches,
61
  upsertBreaches
62
}
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