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

mozilla / blurts-server / #11898

pending completion
#11898

push

circleci

web-flow
Merge pull request #2770 from mozilla/license

Add license headers in source files

282 of 1138 branches covered (24.78%)

Branch coverage included in aggregate %.

959 of 3049 relevant lines covered (31.45%)

2.55 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
 * @param {*} verifiedEmails verified emails array from allBreaches object
13
 * @returns breach summary
14
 */
15

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

28
  if (!verifiedEmails) return breachSummary
×
29

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

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

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

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

49
  return breachSummary
×
50
}
51

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

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

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

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

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

84
  return breachedDataTypes
×
85
}
86

87
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