-
Notifications
You must be signed in to change notification settings - Fork 120
BE-444: Fix email verification failing for uppercase signups #8901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TimDiekmann
merged 8 commits into
main
from
t/be-444-email-verification-code-fails-when-signing-up-with-uppercase
Jun 25, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de87de3
BE-444: Fix email verification failing for uppercase signups
TimDiekmann 3b8ce4b
BE-444: Build upstream deps before test:unit
TimDiekmann 4b289d5
BE-444: Address review feedback
TimDiekmann e50fa4e
Update apps/hash-api/src/graph/knowledge/system-types/user.ts
TimDiekmann 3b52014
Update apps/hash-api/src/graph/knowledge/system-types/user.ts
TimDiekmann af5029f
Collapse emails normalization into single line
TimDiekmann d031a24
Normalize invite email using normalizeEmail util
TimDiekmann 893fafc
BE-444: Add integration test for case-insensitive org invitations
TimDiekmann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
68 changes: 68 additions & 0 deletions
68
apps/hash-api/src/auth/create-unverified-email-cleanup-job.test.ts
This file contains hidden or 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,68 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { isPrimaryEmailVerified } from "./create-unverified-email-cleanup-job"; | ||
|
|
||
| import type { Identity } from "@ory/kratos-client"; | ||
|
|
||
| /** | ||
| * Build a minimal Kratos identity for the cleanup-job predicate. Only the | ||
| * fields `isPrimaryEmailVerified` reads (`traits.emails`, `verifiable_addresses`) | ||
| * are populated; the rest of the `Identity` shape is irrelevant here. | ||
| */ | ||
| const identity = ( | ||
| emails: string[], | ||
| verifiableAddresses: Array<{ value: string; verified: boolean }>, | ||
| ): Identity => | ||
| ({ | ||
| traits: { emails }, | ||
| verifiable_addresses: verifiableAddresses, | ||
| }) as unknown as Identity; | ||
|
|
||
| describe("isPrimaryEmailVerified (cleanup-job deletion gate)", () => { | ||
| it("treats a verified address as verified despite trait/address casing mismatch", () => { | ||
| expect( | ||
| isPrimaryEmailVerified( | ||
| identity( | ||
| ["User@Example.com"], | ||
| [{ value: "user@example.com", verified: true }], | ||
| ), | ||
| ), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("treats a verified address as verified when casing matches", () => { | ||
| expect( | ||
| isPrimaryEmailVerified( | ||
| identity( | ||
| ["user@example.com"], | ||
| [{ value: "user@example.com", verified: true }], | ||
| ), | ||
| ), | ||
| ).toBe(true); | ||
| }); | ||
|
|
||
| it("treats a genuinely unverified address as unverified (eligible for cleanup)", () => { | ||
| expect( | ||
| isPrimaryEmailVerified( | ||
| identity( | ||
| ["User@Example.com"], | ||
| [{ value: "user@example.com", verified: false }], | ||
| ), | ||
| ), | ||
| ).toBe(false); | ||
| }); | ||
|
|
||
| it("returns false when there is no verifiable address", () => { | ||
| expect(isPrimaryEmailVerified(identity(["user@example.com"], []))).toBe( | ||
| false, | ||
| ); | ||
| }); | ||
|
|
||
| it("returns false when the identity has no email traits", () => { | ||
| expect( | ||
| isPrimaryEmailVerified( | ||
| identity([], [{ value: "user@example.com", verified: true }]), | ||
| ), | ||
| ).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,30 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import { normalizeEmail } from "./normalize.js"; | ||
|
|
||
| describe("normalizeEmail", () => { | ||
| it("lowercases the address", () => { | ||
| expect(normalizeEmail("User@Example.com")).toBe("user@example.com"); | ||
| expect(normalizeEmail("Signup-Allow@Example.COM")).toBe( | ||
| "signup-allow@example.com", | ||
| ); | ||
| }); | ||
|
|
||
| it("trims surrounding whitespace", () => { | ||
| expect(normalizeEmail(" user@example.com ")).toBe("user@example.com"); | ||
| expect(normalizeEmail("\tUser@Example.com\n")).toBe("user@example.com"); | ||
| }); | ||
|
|
||
| it("is idempotent on already-normalized input", () => { | ||
| const normalized = normalizeEmail("User@Example.com"); | ||
| expect(normalizeEmail(normalized)).toBe(normalized); | ||
| }); | ||
|
|
||
| it("only trims and lowercases β it does not canonicalize the local part", () => { | ||
| // Guards the comparison contract: normalization must not strip `+tag` | ||
| // suffixes or dots, which would silently change email matching everywhere. | ||
| expect(normalizeEmail("First.Last+Tag@Example.com")).toBe( | ||
| "first.last+tag@example.com", | ||
| ); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.