-
Notifications
You must be signed in to change notification settings - Fork 93
fix(auth): stop reporting an unsolved captcha as a wedged challenge #3940
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
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
33 changes: 33 additions & 0 deletions
33
apps/deploy-web/src/components/turnstile/CaptchaChallengeError.spec.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,33 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| import type { CaptchaChallengeReason } from "./CaptchaChallengeError"; | ||
| import { CaptchaChallengeError, SKIP_REPORTING_CAPTCHA_OUTCOME } from "./CaptchaChallengeError"; | ||
|
|
||
| describe(CaptchaChallengeError.name, () => { | ||
| it.each<CaptchaChallengeReason>(["abandoned", "timeout", "dismissed", "error"])("carries a message the visitor can read for %s", reason => { | ||
| expect(new CaptchaChallengeError(reason).message).toMatch(/^Verification .+\.$/); | ||
| }); | ||
|
|
||
| it("survives instanceof against both its own type and Error", () => { | ||
| const error = new CaptchaChallengeError("abandoned"); | ||
|
|
||
| expect(error).toBeInstanceOf(CaptchaChallengeError); | ||
| expect(error).toBeInstanceOf(Error); | ||
| expect(error.name).toBe("CaptchaChallengeError"); | ||
| }); | ||
|
|
||
| it("keeps the cloudflare error code when there is one", () => { | ||
| expect(new CaptchaChallengeError("error", "300010").code).toBe("300010"); | ||
| }); | ||
|
|
||
| describe("SKIP_REPORTING_CAPTCHA_OUTCOME", () => { | ||
| it("skips reporting for a captcha outcome", () => { | ||
| expect(SKIP_REPORTING_CAPTCHA_OUTCOME.skipErrorReporting(new CaptchaChallengeError("timeout"))).toBe(true); | ||
| }); | ||
|
|
||
| it("leaves every other failure reportable", () => { | ||
| expect(SKIP_REPORTING_CAPTCHA_OUTCOME.skipErrorReporting(new Error("auth api is down"))).toBe(false); | ||
| expect(SKIP_REPORTING_CAPTCHA_OUTCOME.skipErrorReporting({ reason: "timeout" })).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
25 changes: 25 additions & 0 deletions
25
apps/deploy-web/src/components/turnstile/CaptchaChallengeError.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,25 @@ | ||
| export type CaptchaChallengeReason = "abandoned" | "timeout" | "dismissed" | "error"; | ||
|
|
||
| const MESSAGES: Record<CaptchaChallengeReason, string> = { | ||
| abandoned: "Verification wasn't completed. Please try again.", | ||
| timeout: "Verification didn't finish in time. Please try again.", | ||
| dismissed: "Verification was cancelled.", | ||
| error: "Verification failed. Please try again." | ||
| }; | ||
|
|
||
| export class CaptchaChallengeError extends Error { | ||
| readonly name = "CaptchaChallengeError"; | ||
|
|
||
| constructor( | ||
| readonly reason: CaptchaChallengeReason, | ||
| readonly code?: string | ||
| ) { | ||
| super(MESSAGES[reason]); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * The widget reports its own anomalies with tags the global cache handler cannot know, and a challenge the visitor | ||
| * simply never solved is not a fault at all, so neither shape should reach Sentry a second time from a mutation. | ||
| */ | ||
| export const SKIP_REPORTING_CAPTCHA_OUTCOME = { skipErrorReporting: (error: unknown) => error instanceof CaptchaChallengeError }; | ||
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.
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.