-
Notifications
You must be signed in to change notification settings - Fork 514
Turnstile integration for fraud protection #1239
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 all commits
Commits
Show all changes
96 commits
Select commit
Hold shift + click to select a range
4c8ed5e
Risk scores
N2D4 0b9a688
Merge branch 'dev' into fraud-protection
mantrakp04 14f5b22
COUNTRY CODE (1)
mantrakp04 fb315a9
Enhance sign-up rules with derived country code and risk score handli…
mantrakp04 26b3506
Refactor country code handling across the application. Introduced a c…
mantrakp04 7e258d7
Refactor sign-up country code handling to derive only from request ge…
mantrakp04 5250595
Refactor country code validation by introducing a centralized `validC…
mantrakp04 ebbfa47
Enhance `getDerivedSignUpCountryCode` function to support email-based…
mantrakp04 cabefdd
Refactor user schema to centralize metadata for admin restrictions an…
mantrakp04 33dd37a
Add KMS script to package.json for managing port processes
mantrakp04 23bd2aa
Implement country code selection component in sign-up rules and updat…
mantrakp04 6db97e7
Update user test cases to include country_code and risk_scores fields…
mantrakp04 7de1a49
Update user and OAuth test cases to include country_code and risk_sco…
mantrakp04 180c1a7
Update team membership and user tests to reflect changes in response …
mantrakp04 0b962fe
Enhance CEL expression evaluation tests for country code handling. Ad…
mantrakp04 bd51d88
Refactor user creation logic to improve handling of restricted user a…
mantrakp04 6539bdb
Implement disposable email domain heuristics for sign-up risk scoring…
mantrakp04 4c62869
Make heuristic pipeline weights configurable via env vars
mantrakp04 3e1e509
Integrate Emailable API for email validation and enhance sign-up heur…
mantrakp04 bbb7983
Merge branch 'dev' into fraud-protection
mantrakp04 1257021
Merge branch 'fraud-protection' into fraud-protection-country-code
mantrakp04 5f7d7f4
Merge branch 'dev' into fraud-protection
mantrakp04 9c5eda1
Merge branch 'fraud-protection' into fraud-protection-country-code
mantrakp04 7a492f1
Enhance Vitest configuration and TypeScript paths for stack-shared ut…
mantrakp04 ba30281
Clean up shared import resolution on FML
mantrakp04 41e6cd2
Merge fraud-protection-country-code
mantrakp04 f576fd7
Fix Docker build
N2D4 c8b7f27
Stack CLI (#1227)
BilalG1 169984e
Managed email provider (#1222)
BilalG1 e643feb
chore: update package versions
N2D4 3fb9e83
Hosted components (#1229)
BilalG1 3f4aefc
Update dashboard components (Except for major 4) (#1205)
Developing-Gamer d9d4512
Use package exports for stack-shared imports
mantrakp04 bad853b
Enhance sign-up process with Turnstile integration and refactor relat…
mantrakp04 58aeb3c
Merge branch 'dev' into fraud-protection
mantrakp04 7d42522
Merge branch 'fraud-protection' into fraud-protection-country-code
mantrakp04 0e6f99c
Merge branch 'fraud-protection-country-code' into fraud-protection-te…
mantrakp04 28e0af9
Enhance package exports for stack-shared utilities
mantrakp04 af11525
Merge branch 'fraud-protection-temp-emails' into fraud-protection-tru…
mantrakp04 04d4a6b
Refactor imports in backend and dashboard components to use stack-sha…
mantrakp04 e5fafda
Update codegen-docs:watch script to exclude node_modules from watch p…
mantrakp04 2a84dd0
Enhance Turnstile integration and refactor related components
mantrakp04 5d029e0
Refactor Turnstile integration across authentication routes
mantrakp04 142d548
Add risk score weights and thresholds for sign-up assessments
mantrakp04 da8b06e
Refactor sign-up context and enhance risk score handling
mantrakp04 c64ad75
Refactor risk score handling and enhance Turnstile integration
mantrakp04 6cc06d3
Enhance development scripts and update dependencies
mantrakp04 040e1e7
Remove deprecated react-dom-client type and implementation files
mantrakp04 94626ee
Update risk score weights and enhance development scripts
mantrakp04 eec2387
Add submodule for private risk engine and refactor risk score calcula…
mantrakp04 6f97329
Refactor ProjectUser schema and enhance sign-up data handling
mantrakp04 cba1f98
Enhance risk score validation and refactor related components
mantrakp04 762b872
Remove terminal word separators from VSCode settings for cleaner term…
mantrakp04 b9290d5
Merge branch 'dev' into fraud-protection
mantrakp04 5e4da43
Merge branch 'fraud-protection' into fraud-protection-country-code
mantrakp04 441e35e
Merge branch 'fraud-protection-country-code' into fraud-protection-te…
mantrakp04 a02dbf9
Merge branch 'fraud-protection-temp-emails' into fraud-protection-tru…
mantrakp04 52fe7ed
Improve error handling in Turnstile script loading
mantrakp04 8010c64
Merge branch 'dev' into fraud-protection-trunstile
mantrakp04 a24fcdd
Refactor sign-up timestamp handling in ProjectUser model
mantrakp04 d2f2d17
Merge branch 'dev' into fraud-protection-trunstile
mantrakp04 09a039a
Enhance email validation handling and update dependencies
mantrakp04 8d3cdc0
Refactor ProjectUser model and enhance sign-up fraud protection
mantrakp04 e436762
Clear STACK_EMAILABLE_API_KEY in development environment for security…
mantrakp04 a9d3650
Enhance email validation logic to handle reserved test domains
mantrakp04 ec5a8d3
Refactor OAuth response handling and update CORS configuration
mantrakp04 fce866d
Refactor ProjectUser model and enhance sign-up risk score initialization
mantrakp04 4bbcdf1
Update submodule branch and enhance ProjectUser migration scripts for…
mantrakp04 4160fb0
Enhance Turnstile integration and refactor user handling logic
mantrakp04 443dc99
Refactor ProjectUser model and enhance sign-up handling
mantrakp04 141fd4b
Enhance ProjectUser model and implement sign-up fraud protection feat…
mantrakp04 ba0648c
Enhance Turnstile integration and improve error handling
mantrakp04 930b10b
Refactor Turnstile integration and improve error handling
mantrakp04 629ced0
Refactor user signup handling and improve error management
mantrakp04 c7c3fdf
Refactor CEL evaluator and email validation logic
mantrakp04 a95f97f
Enhance Turnstile integration and update environment configuration
mantrakp04 e753510
Update Turnstile assessment handling and improve hostname validation
mantrakp04 9ecb43c
Merge branch 'dev' into fraud-protection-trunstile
mantrakp04 8098582
Refactor Turnstile integration to Bot Challenge and enhance fraud pro…
mantrakp04 6c4a811
Update ProjectUser model and migrations for signedUpAt field
mantrakp04 fa208cf
Update ProjectUser model to reflect partial index management
mantrakp04 fe3a061
Finalize sign-up fraud protection implementation
mantrakp04 3cac0e5
Update user sign-up handling and enforce non-nullable signedUpAt field
mantrakp04 42c913b
Remove non-null constraint and validation for signedUpAt field in Pro…
mantrakp04 cc6dac4
Implement non-null constraint and trigger for signedUpAt field in Pro…
mantrakp04 e7d8865
Add RUN_OUTSIDE_TRANSACTION_SENTINEL to ProjectUser migration triggers
mantrakp04 6f5d02e
Enhance external DB sync test with timeout and interval settings
mantrakp04 39f4381
Merge branch 'dev' into fraud-protection-trunstile
mantrakp04 05a6d87
Enhance OAuth and OTP handling with request context serialization
mantrakp04 785efe0
Refactor OTP verification code handling and sign-up context schema
mantrakp04 dc69508
Implement Turnstile bot challenge handling and sign-up policy adjustm…
mantrakp04 b1be033
Merge branch 'dev' into fraud-protection-trunstile
mantrakp04 fd68a88
Enhance bot challenge error handling in client interface
mantrakp04 8b1c6cb
Refactor OpenAPI response handling to support multiple response variants
mantrakp04 94c8c2c
Enhance bot challenge handling in client interface
mantrakp04 9a55542
Implement bot challenge disabling feature in local development
mantrakp04 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [submodule "packages/private"] | ||
| path = packages/private | ||
| url = https://github.com/stack-auth/private.git | ||
| branch = main | ||
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
19 changes: 19 additions & 0 deletions
19
apps/backend/prisma/migrations/20260308000000_add_signup_fraud_protection/migration.sql
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,19 @@ | ||
| ALTER TABLE "ProjectUser" ADD COLUMN "signUpRiskScoreBot" SMALLINT NOT NULL DEFAULT 0; | ||
|
mantrakp04 marked this conversation as resolved.
|
||
| ALTER TABLE "ProjectUser" ADD COLUMN "signUpRiskScoreFreeTrialAbuse" SMALLINT NOT NULL DEFAULT 0; | ||
|
|
||
| ALTER TABLE "ProjectUser" | ||
| ADD CONSTRAINT "ProjectUser_risk_score_bot_range" | ||
| CHECK ("signUpRiskScoreBot" >= 0 AND "signUpRiskScoreBot" <= 100) NOT VALID; | ||
|
|
||
| ALTER TABLE "ProjectUser" | ||
| ADD CONSTRAINT "ProjectUser_risk_score_free_trial_abuse_range" | ||
| CHECK ("signUpRiskScoreFreeTrialAbuse" >= 0 AND "signUpRiskScoreFreeTrialAbuse" <= 100) NOT VALID; | ||
|
|
||
| ALTER TABLE "ProjectUser" ADD COLUMN "signUpCountryCode" TEXT; | ||
|
|
||
| ALTER TABLE "ProjectUser" | ||
| ADD COLUMN "signedUpAt" TIMESTAMP(3), | ||
| ADD COLUMN "signUpIp" TEXT, | ||
| ADD COLUMN "signUpIpTrusted" BOOLEAN, | ||
| ADD COLUMN "signUpEmailNormalized" TEXT, | ||
| ADD COLUMN "signUpEmailBase" TEXT; | ||
|
mantrakp04 marked this conversation as resolved.
|
||
16 changes: 16 additions & 0 deletions
16
apps/backend/prisma/migrations/20260308000001_backfill_signup_fraud_protection/migration.sql
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,16 @@ | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- CONDITIONALLY_REPEAT_MIGRATION_SENTINEL | ||
| WITH to_update AS ( | ||
| SELECT "projectUserId", "tenancyId" | ||
| FROM "ProjectUser" | ||
| WHERE "signedUpAt" IS NULL | ||
| LIMIT 10000 | ||
| ), | ||
| updated AS ( | ||
| UPDATE "ProjectUser" pu | ||
| SET "signedUpAt" = pu."createdAt" | ||
| FROM to_update tu | ||
| WHERE pu."tenancyId" = tu."tenancyId" AND pu."projectUserId" = tu."projectUserId" | ||
| RETURNING 1 | ||
| ) | ||
| SELECT COUNT(*) > 0 AS should_repeat_migration FROM updated; |
32 changes: 32 additions & 0 deletions
32
...migrations/20260308000001_backfill_signup_fraud_protection/tests/backfill-and-defaults.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,32 @@ | ||
| import { randomUUID } from 'crypto'; | ||
| import type { Sql } from 'postgres'; | ||
| import { expect } from 'vitest'; | ||
|
|
||
| export const preMigration = async (sql: Sql) => { | ||
| const projectId = `test-${randomUUID()}`; | ||
| const tenancyId = randomUUID(); | ||
| const regularUserId = randomUUID(); | ||
| const anonUserId = randomUUID(); | ||
|
|
||
| await sql`INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode") VALUES (${projectId}, NOW(), NOW(), 'Test', '', false)`; | ||
| await sql`INSERT INTO "Tenancy" ("id", "createdAt", "updatedAt", "projectId", "branchId", "hasNoOrganization") VALUES (${tenancyId}::uuid, NOW(), NOW(), ${projectId}, 'main', 'TRUE'::"BooleanTrue")`; | ||
| await sql`INSERT INTO "ProjectUser" ("projectUserId", "tenancyId", "mirroredProjectId", "mirroredBranchId", "createdAt", "updatedAt", "lastActiveAt") VALUES (${regularUserId}::uuid, ${tenancyId}::uuid, ${projectId}, 'main', NOW(), NOW(), NOW())`; | ||
| await sql`INSERT INTO "ProjectUser" ("projectUserId", "tenancyId", "mirroredProjectId", "mirroredBranchId", "createdAt", "updatedAt", "lastActiveAt", "isAnonymous") VALUES (${anonUserId}::uuid, ${tenancyId}::uuid, ${projectId}, 'main', NOW(), NOW(), NOW(), true)`; | ||
|
|
||
| return { regularUserId, anonUserId }; | ||
| }; | ||
|
|
||
| export const postMigration = async (sql: Sql, ctx: Awaited<ReturnType<typeof preMigration>>) => { | ||
| for (const userId of [ctx.regularUserId, ctx.anonUserId]) { | ||
| const rows = await sql` | ||
| SELECT "signedUpAt", "createdAt", "signUpRiskScoreBot", "signUpRiskScoreFreeTrialAbuse" | ||
| FROM "ProjectUser" | ||
| WHERE "projectUserId" = ${userId}::uuid | ||
| `; | ||
|
|
||
| expect(rows).toHaveLength(1); | ||
| expect(rows[0].signedUpAt.toISOString()).toBe(rows[0].createdAt.toISOString()); | ||
| expect(rows[0].signUpRiskScoreBot).toBe(0); | ||
| expect(rows[0].signUpRiskScoreFreeTrialAbuse).toBe(0); | ||
| } | ||
| }; |
65 changes: 65 additions & 0 deletions
65
apps/backend/prisma/migrations/20260308000002_finalize_signup_fraud_protection/migration.sql
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,65 @@ | ||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "ProjectUser_signedUpAt_asc" | ||
| ON "ProjectUser"("tenancyId", "isAnonymous", "signedUpAt" ASC); | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "ProjectUser_signUpIp_recent_idx" | ||
| ON "ProjectUser"("tenancyId", "isAnonymous", "signUpIp", "signedUpAt"); | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| CREATE INDEX CONCURRENTLY IF NOT EXISTS "ProjectUser_signUpEmailBase_recent_idx" | ||
| ON "ProjectUser"("tenancyId", "isAnonymous", "signUpEmailBase", "signedUpAt"); | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| ALTER TABLE "ProjectUser" VALIDATE CONSTRAINT "ProjectUser_risk_score_bot_range"; | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| ALTER TABLE "ProjectUser" VALIDATE CONSTRAINT "ProjectUser_risk_score_free_trial_abuse_range"; | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| CREATE OR REPLACE FUNCTION "set_project_user_signed_up_at_from_created_at"() | ||
| RETURNS TRIGGER AS $$ | ||
| BEGIN | ||
| IF NEW."signedUpAt" IS NULL THEN | ||
| NEW."signedUpAt" := NEW."createdAt"; | ||
| END IF; | ||
| RETURN NEW; | ||
| END; | ||
| $$ LANGUAGE plpgsql; | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| CREATE TRIGGER "ProjectUser_set_signedUpAt_from_createdAt" | ||
| BEFORE INSERT ON "ProjectUser" | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION "set_project_user_signed_up_at_from_created_at"(); | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| ALTER TABLE "ProjectUser" | ||
| ADD CONSTRAINT "ProjectUser_signedUpAt_not_null" | ||
| CHECK ("signedUpAt" IS NOT NULL) NOT VALID; | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| ALTER TABLE "ProjectUser" VALIDATE CONSTRAINT "ProjectUser_signedUpAt_not_null"; | ||
|
|
||
| -- SPLIT_STATEMENT_SENTINEL | ||
| -- SINGLE_STATEMENT_SENTINEL | ||
| -- RUN_OUTSIDE_TRANSACTION_SENTINEL | ||
| ALTER TABLE "ProjectUser" ALTER COLUMN "signedUpAt" SET NOT NULL; |
39 changes: 39 additions & 0 deletions
39
...migrations/20260308000002_finalize_signup_fraud_protection/tests/constraints-validated.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,39 @@ | ||
| import type { Sql } from 'postgres'; | ||
| import { expect } from 'vitest'; | ||
|
|
||
| export const postMigration = async (sql: Sql) => { | ||
| const triggers = await sql` | ||
| SELECT tgname | ||
| FROM pg_trigger | ||
| WHERE tgrelid = '"ProjectUser"'::regclass | ||
| AND tgname = 'ProjectUser_set_signedUpAt_from_createdAt' | ||
| AND NOT tgisinternal | ||
| `; | ||
| expect(triggers).toHaveLength(1); | ||
|
|
||
| const constraints = await sql` | ||
| SELECT conname, convalidated | ||
| FROM pg_constraint | ||
| WHERE conrelid = '"ProjectUser"'::regclass | ||
| AND conname IN ( | ||
| 'ProjectUser_risk_score_bot_range', | ||
| 'ProjectUser_risk_score_free_trial_abuse_range', | ||
| 'ProjectUser_signedUpAt_not_null' | ||
| ) | ||
| ORDER BY conname | ||
| `; | ||
|
|
||
| expect(constraints).toHaveLength(3); | ||
| for (const c of constraints) { | ||
| expect(c.convalidated, `${c.conname} should be validated`).toBe(true); | ||
| } | ||
|
|
||
| const colInfo = await sql` | ||
| SELECT is_nullable, column_default | ||
| FROM information_schema.columns | ||
| WHERE table_name = 'ProjectUser' AND column_name = 'signedUpAt' | ||
| `; | ||
| expect(colInfo).toHaveLength(1); | ||
| expect(colInfo[0].is_nullable).toBe('NO'); | ||
| expect(colInfo[0].column_default).toBe(null); | ||
| }; |
23 changes: 23 additions & 0 deletions
23
...sma/migrations/20260308000002_finalize_signup_fraud_protection/tests/default-on-insert.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,23 @@ | ||
| import { randomUUID } from 'crypto'; | ||
| import type { Sql } from 'postgres'; | ||
| import { expect } from 'vitest'; | ||
|
|
||
| export const postMigration = async (sql: Sql) => { | ||
| const projectId = `test-${randomUUID()}`; | ||
| const tenancyId = randomUUID(); | ||
| const userId = randomUUID(); | ||
|
|
||
| await sql`INSERT INTO "Project" ("id", "createdAt", "updatedAt", "displayName", "description", "isProductionMode") VALUES (${projectId}, NOW(), NOW(), 'Test', '', false)`; | ||
| await sql`INSERT INTO "Tenancy" ("id", "createdAt", "updatedAt", "projectId", "branchId", "hasNoOrganization") VALUES (${tenancyId}::uuid, NOW(), NOW(), ${projectId}, 'main', 'TRUE'::"BooleanTrue")`; | ||
| await sql`INSERT INTO "ProjectUser" ("projectUserId", "tenancyId", "mirroredProjectId", "mirroredBranchId", "createdAt", "updatedAt", "lastActiveAt") VALUES (${userId}::uuid, ${tenancyId}::uuid, ${projectId}, 'main', NOW(), NOW(), NOW())`; | ||
|
|
||
| const rows = await sql` | ||
| SELECT "signedUpAt", "createdAt" | ||
| FROM "ProjectUser" | ||
| WHERE "projectUserId" = ${userId}::uuid | ||
| `; | ||
|
|
||
| expect(rows).toHaveLength(1); | ||
| expect(rows[0].signedUpAt).not.toBeNull(); | ||
| expect(rows[0].signedUpAt.toISOString()).toBe(rows[0].createdAt.toISOString()); | ||
| }; |
29 changes: 29 additions & 0 deletions
29
.../prisma/migrations/20260308000002_finalize_signup_fraud_protection/tests/indexes-exist.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,29 @@ | ||
| import type { Sql } from 'postgres'; | ||
| import { expect } from 'vitest'; | ||
|
|
||
| export const postMigration = async (sql: Sql) => { | ||
| const indexes = await sql` | ||
| SELECT indexname, indexdef | ||
| FROM pg_indexes | ||
| WHERE schemaname = current_schema() | ||
| AND tablename = 'ProjectUser' | ||
| AND indexname IN ( | ||
| 'ProjectUser_signedUpAt_asc', | ||
| 'ProjectUser_signUpIp_recent_idx', | ||
| 'ProjectUser_signUpEmailBase_recent_idx' | ||
| ) | ||
| ORDER BY indexname | ||
| `; | ||
|
|
||
| expect(indexes.map((row) => row.indexname)).toEqual([ | ||
| 'ProjectUser_signUpEmailBase_recent_idx', | ||
| 'ProjectUser_signUpIp_recent_idx', | ||
| 'ProjectUser_signedUpAt_asc', | ||
| ]); | ||
|
|
||
| const indexDefByName = Object.fromEntries(indexes.map((row) => [row.indexname, row.indexdef])); | ||
|
|
||
| expect(indexDefByName['ProjectUser_signedUpAt_asc']).toContain('"tenancyId", "isAnonymous", "signedUpAt"'); | ||
| expect(indexDefByName['ProjectUser_signUpIp_recent_idx']).toContain('"tenancyId", "isAnonymous", "signUpIp", "signedUpAt"'); | ||
| expect(indexDefByName['ProjectUser_signUpEmailBase_recent_idx']).toContain('"tenancyId", "isAnonymous", "signUpEmailBase", "signedUpAt"'); | ||
| }; |
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
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.