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

7
/**
8
 * Equivalent of Typescript "enum"
9
 * These enum types map to HIBP's breach data types, defined in HIBP's API
10
 * Always reference enum instead of strings to avoid spelling error / typos (ie. BreachDataTypes.Passwords)
11
 */
12
const BreachDataTypes = {
×
13
  Passwords: 'passwords',
14
  Email: 'email-addresses',
15
  SSN: 'social-security-numbers',
16
  CreditCard: 'partial-credit-card-data',
17
  BankAccount: 'bank-account-numbers',
18
  PIN: 'pins',
19
  IP: 'ip-addresses',
20
  Address: 'physical-addresses',
21
  DoB: 'dates-of-birth',
22
  Phone: 'phone-numbers',
23
  SecurityQuestions: 'security-questions-and-answers',
24
  HistoricalPasswords: 'historical-passwords',
25
  General: 'general'
26
}
27

28
/**
29
 * TODO: Map from google doc: https://docs.google.com/document/d/1KoItFsTYVIBInIG2YmA7wSxkKS4vti_X0A0td_yaHVM/edit#
30
 * Hardcoded map of breach resolution data types
31
 */
32
const breachResolutionDataTypes = {
×
33
  [BreachDataTypes.Passwords]: {
34
    priority: 1,
35
    header: 'breach-checklist-pw-header',
36
    body: 'breach-checklist-pw-body'
37
  },
38
  [BreachDataTypes.Email]: {
39
    priority: 2,
40
    header: 'breach-checklist-email-header',
41
    body: 'breach-checklist-email-body'
42
  },
43
  [BreachDataTypes.SSN]: {
44
    priority: 3,
45
    header: 'breach-checklist-ssn-header',
46
    body: 'breach-checklist-ssn-body'
47
  },
48
  [BreachDataTypes.CreditCard]: {
49
    priority: 4,
50
    header: 'breach-checklist-cc-header',
51
    body: 'breach-checklist-cc-body'
52
  },
53
  [BreachDataTypes.BankAccount]: {
54
    priority: 5,
55
    header: 'breach-checklist-bank-header',
56
    body: 'breach-checklist-bank-body'
57
  },
58
  [BreachDataTypes.PIN]: {
59
    priority: 6,
60
    header: 'breach-checklist-pin-header',
61
    body: 'breach-checklist-pin-body'
62
  },
63
  [BreachDataTypes.IP]: {
64
    priority: 7,
65
    header: 'breach-checklist-ip-header',
66
    body: 'breach-checklist-ip-body'
67
  },
68
  [BreachDataTypes.Address]: {
69
    priority: 8,
70
    header: 'breach-checklist-address-header',
71
    body: 'breach-checklist-address-body'
72
  },
73
  [BreachDataTypes.DoB]: {
74
    priority: 9,
75
    header: 'breach-checklist-dob-header',
76
    body: 'breach-checklist-dob-body'
77
  },
78
  [BreachDataTypes.Phone]: {
79
    priority: 10,
80
    header: 'breach-checklist-phone-header'
81
  },
82
  [BreachDataTypes.SecurityQuestions]: {
83
    priority: 11,
84
    header: 'breach-checklist-sq-header',
85
    body: 'breach-checklist-sq-body'
86
  },
87
  [BreachDataTypes.HistoricalPasswords]: {
88
    priority: 12,
89
    header: 'breach-checklist-hp-header',
90
    body: 'breach-checklist-hp-body'
91
  },
92
  [BreachDataTypes.General]: {
93
    priority: 13,
94
    header: 'breach-checklist-general-header'
95
  }
96
}
97

98
/**
99
 * Append a field "breachChecklist" to the breaches array of each verified emails
100
 * The checklist serves the UI with relevant recommendations based on the array of datatypes leaked during a breach.
101
 *
102
 * @param {Array} userBreachData contains monitored verified emails array. Each email may contain a breaches array
103
 * @returns {*} void
104
 */
105
function appendBreachResolutionChecklist (userBreachData) {
106
  const { verifiedEmails } = userBreachData
×
107
  for (const { breaches } of verifiedEmails) {
×
108
    breaches.forEach(b => {
×
109
      const dataClasses = b.DataClasses
×
110
      const args = {
×
111
        companyName: b.Name,
112
        breachedCompanyUrl: `https://${b.Domain}`
113
      }
114
      b.breachChecklist = getResolutionRecsPerBreach(dataClasses, args)
×
115
    })
116
  }
117
}
118

119
/**
120
 * Get a subset of the breach resolution data types map
121
 * based on the array of datatypes leaked during a breach
122
 *
123
 * @param {Array} dataTypes datatypes leaked during the breach
124
 * @param {object} args contains necessary variables for the fluent file
125
 *  - companyName
126
 *  - breachedCompanyUrl
127
 * @returns {Map} map of relevant breach resolution recommendations
128
 */
129
function getResolutionRecsPerBreach (dataTypes, args) {
130
  const filteredBreachRecs = {}
×
131

132
  // if datatypes is empty or null, return general only.
133
  if (!dataTypes?.length) dataTypes = [BreachDataTypes.General]
×
134

135
  // filter breachResolutionDataTypes based on relevant data types passed in
136
  for (const [key, value] of Object.entries(breachResolutionDataTypes)) {
×
137
    if (dataTypes.includes(key)) {
×
138
      // find fluent text based on fluent ids
139
      let { header, body, priority } = value
×
140
      header = header ? getMessage(header, args) : ''
×
141
      body = body ? getMessage(body, args) : ''
×
142
      filteredBreachRecs[key] = { header, body, priority }
×
143
    }
144
  }
145

146
  // loop through the breach recs
147
  return filteredBreachRecs
×
148
}
149

150
/**
151
 * Take breach DataTypes array from HIBP and filter based on BreachDataTypes enums above
152
 *
153
 * @param {Array} originalDataTypes breach DataTypes array from HIBP
154
 * @returns {Array} filtered breach data types
155
 */
156
function filterBreachDataTypes (originalDataTypes) {
157
  const relevantDataTypes = Object.values(BreachDataTypes)
×
158
  return originalDataTypes.filter(d => relevantDataTypes.includes(d))
×
159
}
160

161
export { BreachDataTypes, appendBreachResolutionChecklist, filterBreachDataTypes }
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