• 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/utils/breach-summary.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 { BreachDataTypes } from './breach-resolution.js'
6

7
/**
8
 * Returns a breach summary JSON that contains the following attributes
9
 *  - monitoredEmails: the number of emails monitored
10
 *  - numBreaches: resolved, unresolved, total number of breaches
11
 *  - breachedDataTypes: total number of breaches for passwords, emails, ips, or others
12
 *
13
 * @param {*} verifiedEmails verified emails array from allBreaches object
14
 * @returns breach summary
15
 */
16

17
function breachSummary (verifiedEmails) {
18
  const breachSummary = {
×
19
    monitoredEmails: {
20
      count: 0
21
    },
22
    numBreaches: {
23
      count: 0,
24
      numResolved: 0,
25
      numUnresolved: 0
26
    }
27
  }
28

29
  if (!verifiedEmails) return breachSummary
×
30

31
  // combine the breaches for each account, breach duplicates are ok
32
  // since the user may have multiple accounts with different emails
33
  verifiedEmails.forEach(email => {
×
34
    email.breaches.forEach(breach => {
×
35
      if (breach.IsResolved) {
×
36
        breachSummary.numBreaches.numResolved++
×
37
      }
38
    })
39

40
    // update breaches count
41
    breachSummary.numBreaches.count += email.breaches.length
×
42
  })
43

44
  // total number of verified emails being monitored
45
  breachSummary.monitoredEmails.count = verifiedEmails.length
×
46

47
  // calculate unresolved breaches count
48
  breachSummary.numBreaches.numUnresolved = breachSummary.numBreaches.count - breachSummary.numBreaches.numResolved
×
49

50
  return breachSummary
×
51
}
52

53
function breachedDataTypes (verifiedEmails) {
54
  const breachedDataTypes = {}
×
55
  if (!verifiedEmails) return breachedDataTypes
×
56

57
  verifiedEmails.forEach(email => {
×
58
    breachedDataTypes[email.email] = {
×
59
      [BreachDataTypes.Passwords]: 0,
60
      [BreachDataTypes.Email]: 0,
61
      [BreachDataTypes.IP]: 0,
62
      other: 0
63
    }
64

65
    email.breaches.forEach(breach => {
×
66
      let isOther = true
×
67

68
      if (breach.DataClasses.includes(BreachDataTypes.Passwords)) {
×
69
        breachedDataTypes[email.email][BreachDataTypes.Passwords]++
×
70
        isOther = false
×
71
      }
72
      if (breach.DataClasses.includes(BreachDataTypes.Email)) {
×
73
        breachedDataTypes[email.email][BreachDataTypes.Email]++
×
74
        isOther = false
×
75
      }
76
      if (breach.DataClasses.includes(BreachDataTypes.IP)) {
×
77
        breachedDataTypes[email.email][BreachDataTypes.IP]++
×
78
        isOther = false
×
79
      }
80

81
      if (isOther) breachedDataTypes[email.email].other++
×
82
    })
83
  })
84

85
  return breachedDataTypes
×
86
}
87

88
export { breachSummary, breachedDataTypes }
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