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.

Add case-sensitivity E2E tests

Steven Tey45d6dbb4022c
diff --git a/apps/web/lib/middleware/utils/parse.ts b/apps/web/lib/middleware/utils/parse.ts
index 3aac8cf850..e5c1b07908 100644
--- a/apps/web/lib/middleware/utils/parse.ts
+++ b/apps/web/lib/middleware/utils/parse.ts
@@ -3,16 +3,21 @@ import { NextRequest } from "next/server";
export const parse = (req: NextRequest) => {
let domain = req.headers.get("host") as string;
+ // path is the path of the URL (e.g. dub.sh/stats/github -> /stats/github)
+ let path = req.nextUrl.pathname;
+
// remove www. from domain and convert to lowercase
domain = domain.replace(/^www./, "").toLowerCase();
if (domain === "dub.localhost:8888" || domain.endsWith(".vercel.app")) {
- // for local development and preview URLs
- domain = SHORT_DOMAIN;
+ if (path === "cAsE") {
+ // special case for case-sensitive link test
+ domain = "dub-internal-test.com";
+ } else {
+ // for local development and preview URLs
+ domain = SHORT_DOMAIN;
+ }
}
- // path is the path of the URL (e.g. dub.sh/stats/github -> /stats/github)
- let path = req.nextUrl.pathname;
-
// fullPath is the full URL path (along with search params)
const searchParams = req.nextUrl.searchParams.toString();
const searchParamsObj = Object.fromEntries(req.nextUrl.searchParams);
diff --git a/apps/web/tests/redirects/index.test.ts b/apps/web/tests/redirects/index.test.ts
index 9d4a90511b..36e977c817 100644
--- a/apps/web/tests/redirects/index.test.ts
+++ b/apps/web/tests/redirects/index.test.ts
@@ -108,6 +108,24 @@ describe.runIf(env.CI)("Link Redirects", async () => {
expect(response.status).toBe(302);
});
+ test("with case-sensitive (correct) key", async () => {
+ const response = await fetch(`${h.baseUrl}/cAsE`, fetchOptions);
+
+ expect(response.headers.get("location")).toBe(
+ "https://dub.co/changelog/case-insensitive-links",
+ );
+ expect(response.headers.get("x-powered-by")).toBe(poweredBy);
+ expect(response.status).toBe(302);
+ });
+
+ test("with case-sensitive (incorrect) key", async () => {
+ const response = await fetch(`${h.baseUrl}/case`, fetchOptions);
+
+ expect(response.headers.get("location")).toBe("https://dub.co");
+ expect(response.headers.get("x-powered-by")).toBe(poweredBy);
+ expect(response.status).toBe(302);
+ });
+
test("with password", async () => {
const response = await fetch(
`${h.baseUrl}/password/check?pw=dub`,