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

mozilla / blurts-server / #12632

pending completion
#12632

push

circleci

web-flow
Merge pull request #2854 from mozilla/MNTOR-741

MNTOR-741

282 of 1416 branches covered (19.92%)

Branch coverage included in aggregate %.

107 of 107 new or added lines in 9 files covered. (100.0%)

959 of 3912 relevant lines covered (24.51%)

2.04 hits per line

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

0.0
/src/db/tables/breaches.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
import Knex from 'knex'
6
import knexConfig from '../knexfile.js'
7
import mozlog from '../../utils/log.js'
8
const knex = Knex(knexConfig)
×
9
const log = mozlog('DB.breaches')
×
10

11
/**
12
 * Get all records from "breaches" table
13
 *
14
 * @returns Array of all records from "breaches" table
15
 */
16
async function getAllBreaches () {
17
  return knex('breaches')
×
18
    .returning()
19
}
20

21
/**
22
 * Upsert breaches into "breaches" table
23
 * Skip inserting when 'name' field (unique) has a conflict
24
 *
25
 * @param {Array} hibpBreaches breaches array from HIBP API
26
 * @returns
27
 */
28
async function upsertBreaches (hibpBreaches) {
29
  log.debug('upsertBreaches', hibpBreaches[0])
×
30

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

57
    try {
×
58
      const value = await Promise.all(queries)
×
59
      return trx.commit(value)
×
60
    } catch (error) {
61
      return trx.rollback(error)
×
62
    }
63
  })
64
}
65

66
export {
67
  getAllBreaches,
68
  upsertBreaches
69
}
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