forked from mozilla/blurts-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
for mozilla#1182: lowercase email addresses for all HIBP calls
for mozilla#1182: script to lower-case sha1 db records
- Loading branch information
1 parent
990ba69
commit e921363
Showing
6 changed files
with
94 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use strict"; | ||
|
||
|
||
const Knex = require("knex"); | ||
const knexConfig = require("../db/knexfile"); | ||
const knex = Knex(knexConfig); | ||
|
||
const HIBP = require("../hibp"); | ||
const getSha1 = require("../sha1-utils"); | ||
|
||
|
||
async function subscribeLowercaseHashToHIBP(emailAddress) { | ||
const lowerCasedEmail = emailAddress.toLowerCase(); | ||
const lowerCasedSha1 = getSha1(lowerCasedEmail); | ||
await HIBP.subscribeHash(lowerCasedSha1); | ||
return lowerCasedSha1; | ||
} | ||
|
||
|
||
(async () => { | ||
const subRecordsWithUpperChars = await knex("subscribers") | ||
.whereRaw("primary_email != lower(primary_email)"); | ||
for (const subRecord of subRecordsWithUpperChars) { | ||
const lowerCasedSha1 = await subscribeLowercaseHashToHIBP(subRecord.primary_email); | ||
await knex("subscribers") | ||
.update({ | ||
primary_sha1: lowerCasedSha1, | ||
}) | ||
.where("id", subRecord.id); | ||
} | ||
|
||
const emailRecordsWithUpperChars = await knex("email_addresses") | ||
.whereRaw("email != lower(email)"); | ||
for (const emailRecord of emailRecordsWithUpperChars) { | ||
const lowerCasedSha1 = await subscribeLowercaseHashToHIBP(emailRecord.email); | ||
await knex("email_addresses") | ||
.update({ | ||
sha1: lowerCasedSha1, | ||
}) | ||
.where("id", emailRecord.id); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters