From 03c10f400b400d8feb7f3beb1534285757a076fd Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 28 Nov 2025 09:54:45 +0530 Subject: [PATCH 1/3] Remove DUB_TEST_IDENTITY_HEADER --- apps/web/lib/middleware/utils/get-identity-hash.ts | 13 ------------- apps/web/tests/fraud/index.test.ts | 7 +------ apps/web/tests/utils/resource.ts | 10 ---------- 3 files changed, 1 insertion(+), 29 deletions(-) diff --git a/apps/web/lib/middleware/utils/get-identity-hash.ts b/apps/web/lib/middleware/utils/get-identity-hash.ts index 4ef076bd688..4609fff0fdf 100644 --- a/apps/web/lib/middleware/utils/get-identity-hash.ts +++ b/apps/web/lib/middleware/utils/get-identity-hash.ts @@ -1,24 +1,11 @@ import { LOCALHOST_IP, hashStringSHA256 } from "@dub/utils"; import { ipAddress } from "@vercel/functions"; import { userAgent } from "next/server"; -import { DUB_TEST_IDENTITY_HEADER } from "tests/utils/resource"; /** * Combine IP + UA to create a unique identifier for the user (for deduplication) */ export async function getIdentityHash(req: Request) { - // If provided, use this identity directly (for E2E) - if ( - process.env.NODE_ENV === "development" || - process.env.VERCEL_ENV === "preview" - ) { - const testOverride = req.headers.get(DUB_TEST_IDENTITY_HEADER); - - if (testOverride) { - return await hashStringSHA256(testOverride); - } - } - const ip = ipAddress(req) || LOCALHOST_IP; const ua = userAgent(req); return await hashStringSHA256(`${ip}-${ua.ua}`); diff --git a/apps/web/tests/fraud/index.test.ts b/apps/web/tests/fraud/index.test.ts index e788eec903e..fad82b0aac2 100644 --- a/apps/web/tests/fraud/index.test.ts +++ b/apps/web/tests/fraud/index.test.ts @@ -1,9 +1,8 @@ import { Customer, fraudEventGroupProps, TrackLeadResponse } from "@/lib/types"; import { FraudRuleType } from "@prisma/client"; -import { randomCustomer, randomId, retry } from "tests/utils/helpers"; +import { randomCustomer, retry } from "tests/utils/helpers"; import { HttpClient } from "tests/utils/http"; import { - DUB_TEST_IDENTITY_HEADER, E2E_FRAUD_PARTNER, E2E_FRAUD_REFERRAL_SOURCE_BANNED_DOMAIN, E2E_TRACK_CLICK_HEADERS, @@ -23,7 +22,6 @@ describe.concurrent("/fraud/**", async () => { path: "/track/click", headers: { ...E2E_TRACK_CLICK_HEADERS, - [DUB_TEST_IDENTITY_HEADER]: randomId(10), }, body: { domain: clickLink.domain, @@ -66,7 +64,6 @@ describe.concurrent("/fraud/**", async () => { path: "/track/click", headers: { ...E2E_TRACK_CLICK_HEADERS, - [DUB_TEST_IDENTITY_HEADER]: randomId(10), }, body: { domain: clickLink.domain, @@ -107,7 +104,6 @@ describe.concurrent("/fraud/**", async () => { headers: { ...E2E_TRACK_CLICK_HEADERS, referer: `https://${E2E_FRAUD_REFERRAL_SOURCE_BANNED_DOMAIN}`, - [DUB_TEST_IDENTITY_HEADER]: randomId(10), }, body: { domain: clickLink.domain, @@ -147,7 +143,6 @@ describe.concurrent("/fraud/**", async () => { path: "/track/click", headers: { ...E2E_TRACK_CLICK_HEADERS, - [DUB_TEST_IDENTITY_HEADER]: randomId(10), }, body: { domain: clickLink.domain, diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index d942699cb5e..cc6571e8db1 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -8,16 +8,6 @@ export const E2E_LINK = { url: "https://github.com/dubinc", }; -/** - * Used exclusively in E2E tests to override the computed identity hash. - * When this header is present, `getIdentityHash()` will use its value - * as the hash input instead of relying on the real IP/User-Agent. - * - * This prevents deduplication during automated tests where multiple - * requests originate from the same IP and UA. - */ -export const DUB_TEST_IDENTITY_HEADER = "x-dub-test-identity"; - export const E2E_TRACK_CLICK_HEADERS = { referer: "https://dub.co", "User-Agent": From 3599f9db8eec48408063c7d10436bf377fe34899 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 28 Nov 2025 10:01:54 +0530 Subject: [PATCH 2/3] Update fraud tests to use new E2E_FRAUD_PARTNER links structure --- apps/web/tests/fraud/index.test.ts | 8 ++++---- apps/web/tests/utils/resource.ts | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/apps/web/tests/fraud/index.test.ts b/apps/web/tests/fraud/index.test.ts index fad82b0aac2..003dd73b0b8 100644 --- a/apps/web/tests/fraud/index.test.ts +++ b/apps/web/tests/fraud/index.test.ts @@ -15,7 +15,7 @@ describe.concurrent("/fraud/**", async () => { const { http } = await h.init(); test("FraudRuleType = customerEmailMatch", async () => { - const clickLink = E2E_FRAUD_PARTNER.link; + const clickLink = E2E_FRAUD_PARTNER.links[0]; // Track a click const clickResponse = await http.post<{ clickId: string }>({ @@ -57,7 +57,7 @@ describe.concurrent("/fraud/**", async () => { }); test("FraudRuleType = customerEmailSuspiciousDomain", async () => { - const clickLink = E2E_FRAUD_PARTNER.link; + const clickLink = E2E_FRAUD_PARTNER.links[1]; // Track a click const clickResponse = await http.post<{ clickId: string }>({ @@ -96,7 +96,7 @@ describe.concurrent("/fraud/**", async () => { }); test("FraudRuleType = referralSourceBanned", async () => { - const clickLink = E2E_FRAUD_PARTNER.link; + const clickLink = E2E_FRAUD_PARTNER.links[2]; // Track a click const clickResponse = await http.post<{ clickId: string }>({ @@ -136,7 +136,7 @@ describe.concurrent("/fraud/**", async () => { }); test("FraudRuleType = paidTrafficDetected", async () => { - const clickLink = E2E_FRAUD_PARTNER.link; + const clickLink = E2E_FRAUD_PARTNER.links[3]; // Track a click const clickResponse = await http.post<{ clickId: string }>({ diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index cc6571e8db1..22ca2cb22e7 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -210,10 +210,24 @@ export const E2E_CUSTOMERS = [ export const E2E_FRAUD_PARTNER = { id: "pn_1K8ND11BZ4XPEX39QX3YMBGY0", email: "kiran+e2e+1@dub.co", - link: { - domain: "getacme.link", - key: "kiran-e2e-1", - }, + links: [ + { + domain: "getacme.link", + key: "fraud-customer-match", + }, + { + domain: "getacme.link", + key: "fraud-customer-suspicious", + }, + { + domain: "getacme.link", + key: "fraud-referral-source-banned", + }, + { + domain: "getacme.link", + key: "fraud-paid-traffic", + }, + ], } as const; export const E2E_FRAUD_REFERRAL_SOURCE_BANNED_DOMAIN = From 241b62c6cd801c416e22783ed2b505cb9376f683 Mon Sep 17 00:00:00 2001 From: Kiran K Date: Fri, 28 Nov 2025 10:10:35 +0530 Subject: [PATCH 3/3] Use a keyed map --- apps/web/tests/fraud/index.test.ts | 8 ++++---- apps/web/tests/utils/resource.ts | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/apps/web/tests/fraud/index.test.ts b/apps/web/tests/fraud/index.test.ts index 003dd73b0b8..53b5aa38d47 100644 --- a/apps/web/tests/fraud/index.test.ts +++ b/apps/web/tests/fraud/index.test.ts @@ -15,7 +15,7 @@ describe.concurrent("/fraud/**", async () => { const { http } = await h.init(); test("FraudRuleType = customerEmailMatch", async () => { - const clickLink = E2E_FRAUD_PARTNER.links[0]; + const clickLink = E2E_FRAUD_PARTNER.links.customerEmailMatch; // Track a click const clickResponse = await http.post<{ clickId: string }>({ @@ -57,7 +57,7 @@ describe.concurrent("/fraud/**", async () => { }); test("FraudRuleType = customerEmailSuspiciousDomain", async () => { - const clickLink = E2E_FRAUD_PARTNER.links[1]; + const clickLink = E2E_FRAUD_PARTNER.links.customerEmailSuspiciousDomain; // Track a click const clickResponse = await http.post<{ clickId: string }>({ @@ -96,7 +96,7 @@ describe.concurrent("/fraud/**", async () => { }); test("FraudRuleType = referralSourceBanned", async () => { - const clickLink = E2E_FRAUD_PARTNER.links[2]; + const clickLink = E2E_FRAUD_PARTNER.links.referralSourceBanned; // Track a click const clickResponse = await http.post<{ clickId: string }>({ @@ -136,7 +136,7 @@ describe.concurrent("/fraud/**", async () => { }); test("FraudRuleType = paidTrafficDetected", async () => { - const clickLink = E2E_FRAUD_PARTNER.links[3]; + const clickLink = E2E_FRAUD_PARTNER.links.paidTrafficDetected; // Track a click const clickResponse = await http.post<{ clickId: string }>({ diff --git a/apps/web/tests/utils/resource.ts b/apps/web/tests/utils/resource.ts index 22ca2cb22e7..94685c462e2 100644 --- a/apps/web/tests/utils/resource.ts +++ b/apps/web/tests/utils/resource.ts @@ -210,24 +210,24 @@ export const E2E_CUSTOMERS = [ export const E2E_FRAUD_PARTNER = { id: "pn_1K8ND11BZ4XPEX39QX3YMBGY0", email: "kiran+e2e+1@dub.co", - links: [ - { + links: { + customerEmailMatch: { domain: "getacme.link", key: "fraud-customer-match", }, - { + customerEmailSuspiciousDomain: { domain: "getacme.link", key: "fraud-customer-suspicious", }, - { + referralSourceBanned: { domain: "getacme.link", key: "fraud-referral-source-banned", }, - { + paidTrafficDetected: { domain: "getacme.link", key: "fraud-paid-traffic", }, - ], + }, } as const; export const E2E_FRAUD_REFERRAL_SOURCE_BANNED_DOMAIN =