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

mozilla / blurts-server / #11795

pending completion
#11795

push

circleci

web-flow
Merge pull request #2742 from mozilla/MNTOR-1079

MNTOR-1079: Breach summary utility funcs

282 of 1138 branches covered (24.78%)

Branch coverage included in aggregate %.

27 of 27 new or added lines in 1 file covered. (100.0%)

959 of 3049 relevant lines covered (31.45%)

2.53 hits per line

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

0.0
/src/utils/breach-summary.js
1
import { BreachDataTypes } from './breach-resolution.js'
2

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

12
function breachSummary (verifiedEmails) {
13
  const breachSummary = {
×
14
    monitoredEmails: {
15
      count: 0
16
    },
17
    numBreaches: {
18
      count: 0,
19
      numResolved: 0,
20
      numUnresolved: 0
21
    }
22
  }
23

24
  if (!verifiedEmails) return breachSummary
×
25

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

35
    // update breaches count
36
    breachSummary.numBreaches.count += email.breaches.length
×
37
  })
38

39
  // total number of verified emails being monitored
40
  breachSummary.monitoredEmails.count = verifiedEmails.length
×
41

42
  // calculate unresolved breaches count
43
  breachSummary.numBreaches.numUnresolved = breachSummary.numBreaches.count - breachSummary.numBreaches.numResolved
×
44

45
  return breachSummary
×
46
}
47

48
function breachedDataTypes (verifiedEmails) {
49
  const breachedDataTypes = {}
×
50
  if (!verifiedEmails) return breachedDataTypes
×
51

52
  verifiedEmails.forEach(email => {
×
53
    breachedDataTypes[email.email] = {
×
54
      [BreachDataTypes.Passwords]: 0,
55
      [BreachDataTypes.Email]: 0,
56
      [BreachDataTypes.IP]: 0,
57
      other: 0
58
    }
59

60
    email.breaches.forEach(breach => {
×
61
      let isOther = true
×
62

63
      if (breach.DataClasses.includes(BreachDataTypes.Passwords)) {
×
64
        breachedDataTypes[email.email][BreachDataTypes.Passwords]++
×
65
        isOther = false
×
66
      }
67
      if (breach.DataClasses.includes(BreachDataTypes.Email)) {
×
68
        breachedDataTypes[email.email][BreachDataTypes.Email]++
×
69
        isOther = false
×
70
      }
71
      if (breach.DataClasses.includes(BreachDataTypes.IP)) {
×
72
        breachedDataTypes[email.email][BreachDataTypes.IP]++
×
73
        isOther = false
×
74
      }
75

76
      if (isOther) breachedDataTypes[email.email].other++
×
77
    })
78
  })
79

80
  return breachedDataTypes
×
81
}
82

83
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