Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: log whitelist match for OTP email
Browse files Browse the repository at this point in the history
timotheeg committed Apr 12, 2024
1 parent 66a6b51 commit 15cba2d
Showing 2 changed files with 16 additions and 4 deletions.
18 changes: 15 additions & 3 deletions src/services/identity/UsersService.ts
Original file line number Diff line number Diff line change
@@ -159,7 +159,7 @@ class UsersService {
// raw query because ORMs suck!
const records = (await this.sequelize.query(
`
SELECT 1 AS found
SELECT email AS found
FROM whitelist
WHERE
(expiry is NULL OR expiry >= NOW())
@@ -170,9 +170,21 @@ class UsersService {
replacements: { email: normalizedEmail },
type: QueryTypes.SELECT,
}
)) as { found: 1 }[]
)) as { email: string }[]

if (records.length >= 1) {
logger.info({
message: "Email valid for OTP by whitelist",
meta: {
email,
whitelistEntry: records[0].email,
},
})

return true
}

return records.length >= 1
return false
}

async sendEmailOtp(email: string) {
2 changes: 1 addition & 1 deletion src/services/identity/__tests__/UsersService.spec.ts
Original file line number Diff line number Diff line change
@@ -125,7 +125,7 @@ describe("User Service", () => {
it("should return true when the db query returns a record", async () => {
// Arrange
const expected = true
MockSequelize.query.mockResolvedValueOnce([{ found: 1 }])
MockSequelize.query.mockResolvedValueOnce([{ email: ".gov.sg" }])

// Act
const actual = await UsersService.canSendEmailOtp(mockEmail)

0 comments on commit 15cba2d

Please sign in to comment.