Skip to content

Commit 431ace2

Browse files
committed
Add e2e tests for link-shortener resolution
Alias the nginx fixture container as search.app (a known shortener) and allow-list it for the crawler, with /shortlink and /shortlink-image redirect endpoints. Covers both the HTML crawl path (stored url resolved) and the asset path (sourceUrl resolved).
1 parent b2564fb commit 431ace2

3 files changed

Lines changed: 65 additions & 1 deletion

File tree

packages/e2e_tests/docker-compose.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ services:
1515
MEILI_ADDR: http://meilisearch:7700
1616
BROWSER_WEB_URL: http://chrome:9222
1717
CRAWLER_NUM_WORKERS: 6
18-
CRAWLER_ALLOWED_INTERNAL_HOSTNAMES: nginx
18+
CRAWLER_ALLOWED_INTERNAL_HOSTNAMES: nginx,search.app
1919
CRAWLER_VIDEO_DOWNLOAD: "true"
2020
CRAWLER_VIDEO_DOWNLOAD_MAX_SIZE: -1
2121
OPENAI_API_KEY: aimock-test-key
@@ -44,6 +44,11 @@ services:
4444
nginx:
4545
image: nginx:alpine
4646
restart: unless-stopped
47+
networks:
48+
# Alias so the crawler can reach a "known link shortener" host in tests.
49+
default:
50+
aliases:
51+
- search.app
4752
volumes:
4853
- ./setup/html:/usr/share/nginx/html
4954
- ./setup/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro

packages/e2e_tests/setup/nginx/default.conf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ server {
77
return 302 http://127.0.0.1:80/hello.html;
88
}
99

10+
# Simulate a link-shortener redirect (reached via the search.app alias).
11+
location = /shortlink {
12+
return 302 http://nginx:80/hello.html;
13+
}
14+
15+
location = /shortlink-image {
16+
return 302 http://nginx:80/image.png;
17+
}
18+
1019
location / {
1120
try_files $uri =404;
1221
}

packages/e2e_tests/tests/workers/crawler.test.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,56 @@ describe("Crawler Tests", () => {
143143
expect(bookmark.content.htmlContent).toBeNull();
144144
});
145145

146+
it("resolves a known link-shortener URL to its destination", async () => {
147+
// search.app is aliased to the nginx container and allow-listed as a
148+
// known shortener, so /shortlink 302s to the real hello.html page.
149+
let { data: bookmark } = await client.POST("/bookmarks", {
150+
body: {
151+
type: "link",
152+
url: "http://search.app/shortlink",
153+
},
154+
});
155+
assert(bookmark);
156+
157+
await waitUntil(async () => {
158+
const data = await getBookmark(bookmark!.id);
159+
assert(data);
160+
assert(data.content.type === "link");
161+
return data.content.crawledAt !== null;
162+
}, "Shortened bookmark is crawled");
163+
164+
bookmark = await getBookmark(bookmark.id);
165+
assert(bookmark && bookmark.content.type === "link");
166+
// The stored URL should now be the resolved destination, not the short link.
167+
expect(bookmark.content.url).not.toContain("search.app");
168+
expect(bookmark.content.url).toContain("hello.html");
169+
expect(bookmark.content.htmlContent).toContain("Hello World");
170+
});
171+
172+
it("resolves a shortener that points directly to an asset", async () => {
173+
let { data: bookmark } = await client.POST("/bookmarks", {
174+
body: {
175+
type: "link",
176+
url: "http://search.app/shortlink-image",
177+
},
178+
});
179+
assert(bookmark);
180+
181+
await waitUntil(async () => {
182+
const data = await getBookmark(bookmark!.id);
183+
assert(data);
184+
return data.content.type === "asset";
185+
}, "Shortened asset bookmark is converted to an image");
186+
187+
bookmark = await getBookmark(bookmark.id);
188+
assert(bookmark && bookmark.content.type === "asset");
189+
expect(bookmark.content.assetType).toBe("image");
190+
// sourceUrl should be the resolved destination, not the short link.
191+
expect(bookmark.content.sourceUrl).not.toContain("search.app");
192+
expect(bookmark.content.sourceUrl).toContain("image.png");
193+
expect(bookmark.content.fileName).toBe("image.png");
194+
});
195+
146196
it("image lings jobs be converted into images", async () => {
147197
let { data: bookmark } = await client.POST("/bookmarks", {
148198
body: {

0 commit comments

Comments
 (0)