Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Fix the Fraud tests (#3171)

Kiran K3aad0471ed0f
diff --git a/apps/web/lib/middleware/utils/get-identity-hash.ts b/apps/web/lib/middleware/utils/get-identity-hash.ts
index 4ef076bd68..4609fff0fd 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 e788eec903..53b5aa38d4 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,
@@ -16,14 +15,13 @@ 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.customerEmailMatch;
// Track a click
const clickResponse = await http.post<{ clickId: string }>({
path: "/track/click",
headers: {
...E2E_TRACK_CLICK_HEADERS,
- [DUB_TEST_IDENTITY_HEADER]: randomId(10),
},
body: {
domain: clickLink.domain,
@@ -59,14 +57,13 @@ describe.concurrent("/fraud/**", async () => {
});
test("FraudRuleType = customerEmailSuspiciousDomain", async () => {
- const clickLink = E2E_FRAUD_PARTNER.link;
+ const clickLink = E2E_FRAUD_PARTNER.links.customerEmailSuspiciousDomain;
// Track a click
const clickResponse = await http.post<{ clickId: string }>({
path: "/track/click",
headers: {
...E2E_TRACK_CLICK_HEADERS,
- [DUB_TEST_IDENTITY_HEADER]: randomId(10),
},
body: {
domain: clickLink.domain,
@@ -99,7 +96,7 @@ describe.concurrent("/fraud/**", async () => {
});
test("FraudRuleType = referralSourceBanned", async () => {
- const clickLink = E2E_FRAUD_PARTNER.link;
+ const clickLink = E2E_FRAUD_PARTNER.links.referralSourceBanned;
// Track a click
const clickResponse = await http.post<{ clickId: string }>({
@@ -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,
@@ -140,14 +136,13 @@ describe.concurrent("/fraud/**", async () => {
});
test("FraudRuleType = paidTrafficDetected", async () => {
- const clickLink = E2E_FRAUD_PARTNER.link;
+ const clickLink = E2E_FRAUD_PARTNER.links.paidTrafficDetected;
// Track a click
const clickResponse = await http.post<{ clickId: string }>({
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 d942699cb5..94685c462e 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":
@@ -220,9 +210,23 @@ export const E2E_CUSTOMERS = [
export const E2E_FRAUD_PARTNER = {
id: "pn_1K8ND11BZ4XPEX39QX3YMBGY0",
- link: {
- domain: "getacme.link",
- key: "kiran-e2e-1",
+ 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;