-
Notifications
You must be signed in to change notification settings - Fork 9
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
test: e2e subdomain redirect tests #151
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #151 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 1 1
Lines 35 35
Branches 5 5
=========================================
Hits 35 35
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self review
serviceWorkers: 'allow' | ||
serviceWorkers: 'allow', | ||
|
||
ignoreHTTPSErrors: true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't actually need this anymore
ignoreHTTPSErrors: true |
@@ -460,7 +465,7 @@ async function fetchHandler ({ path, request, event }: FetchHandlerArg): Promise | |||
const response = await verifiedFetch(verifiedFetchUrl, { | |||
signal, | |||
headers, | |||
// TODO redirect: 'manual', // enable when http urls are supported by verified-fetch: https://github.com/ipfs-shipyard/helia-service-worker-gateway/issues/62#issuecomment-1977661456 | |||
redirect: 'manual', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally done with this todo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would close #62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'll add an e2e test prior to closing #62
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one last thing blocking fix of #62: ipfs/helia-verified-fetch#33
it was previously only working for subpath directories.
channel.postMessage({ target: 'SW', action: 'RELOAD_CONFIG', source: 'WINDOW' }) | ||
await swResponsePromise | ||
// TODO: we shouldn't need this. We should be able to just post a message to the service worker to reload it's config. | ||
window.postMessage({ source: 'helia-sw-config-iframe', target: 'PARENT', action: 'RELOAD_CONFIG', config: configInPage }, { targetOrigin: window.location.origin }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is actually the only part that works triggers the config reload on subdomains.. without this, it doesn't work in the autoreload test, however, the above is needed to set the config on origin domain.
I confirmed that origin is getting indexedDB set properly, but autoreload doesn't get picked up by subdomain for some reason.
@@ -0,0 +1,33 @@ | |||
/** | |||
* This is a simple reverse proxy that makes sure that any request to localhost:3333 is forwarded to localhost:3000. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should also make it easier for devs to contribute without having to install traefik/nginx/caddy or do anything fancy
expect(initialResponse?.request()?.redirectedFrom()?.url()).toBe('http://localhost:3333/ipfs/bafkqablimvwgy3y') | ||
|
||
await page.waitForURL('http://bafkqablimvwgy3y.ipfs.localhost:3333') | ||
await setConfig({ page, config: { autoReload: true } }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ideally, setConfig
would occur immediately after line 30, but.. alas, subdomains in playwright are not picking up the config for some reason.
const channel = new BroadcastChannel('helia:sw') | ||
const swResponsePromise = new Promise<void>((resolve, reject) => { | ||
const onSuccess = (e: MessageEvent): void => { | ||
if (e.data.action === 'RELOAD_CONFIG_SUCCESS') { | ||
resolve() | ||
channel.removeEventListener('message', onSuccess) | ||
} | ||
} | ||
channel.addEventListener('message', onSuccess) | ||
}) | ||
channel.postMessage({ target: 'SW', action: 'RELOAD_CONFIG', source: 'WINDOW' }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope this code here helps people understand the benefit of HeliaServiceWorkerCommsChannel
, even if it does need cleaned up further.
} | ||
webServer: [ | ||
{ | ||
command: 'node test-e2e/reverse-proxy.js', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the reverse proxy needed? Currently it only seems to add CORS headers and allow OPTIONS requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
without the reverse proxy, the subdomain origin isolation check will fail:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
╰─ ✔ ❯ npm run test:chrome -- -g 'subdomain-detection' --max-failures 5
> helia-service-worker-gateway@1.0.0 test:chrome
> playwright test -c playwright.config.js --project chromium -g subdomain-detection --max-failures 5
[WebServer] (node:14358) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
Running 2 tests using 1 worker
✘ 1 [chromium] › subdomain-detection.test.ts:6:3 › subdomain-detection › path requests are redirected to subdomains (898ms)
✘ 2 [chromium] › subdomain-detection.test.ts:28:3 › subdomain-detection › path requests are redirected to subdomains automatically with autoreload enabled (893ms)
1) [chromium] › subdomain-detection.test.ts:6:3 › subdomain-detection › path requests are redirected to subdomains
Error: expect(received).toBe(expected) // Object.is equality
Expected: "http://bafkqablimvwgy3y.ipfs.localhost:3333/"
Received: "http://localhost:3000/ipfs/bafkqablimvwgy3y"
11 | const initialResponse = await page.goto('/ipfs/bafkqablimvwgy3y', { waitUntil: 'commit' })
12 |
> 13 | expect(initialResponse?.url()).toBe('http://bafkqablimvwgy3y.ipfs.localhost:3333/')
| ^
14 | expect(initialResponse?.request()?.redirectedFrom()?.url()).toBe('http://localhost:3333/ipfs/bafkqablimvwgy3y')
15 |
16 | await page.waitForURL('http://bafkqablimvwgy3y.ipfs.localhost:3333')
at /Users/sgtpooki/code/work/protocol.ai/ipfs-shipyard/helia-service-worker-gateway/test-e2e/subdomain-detection.test.ts:13:36
2) [chromium] › subdomain-detection.test.ts:28:3 › subdomain-detection › path requests are redirected to subdomains automatically with autoreload enabled
Error: expect(received).toBe(expected) // Object.is equality
Expected: "http://bafkqablimvwgy3y.ipfs.localhost:3333/"
Received: "http://localhost:3000/ipfs/bafkqablimvwgy3y"
32 | const initialResponse = await page.goto('/ipfs/bafkqablimvwgy3y', { waitUntil: 'commit' })
33 |
> 34 | expect(initialResponse?.url()).toBe('http://bafkqablimvwgy3y.ipfs.localhost:3333/')
| ^
35 | expect(initialResponse?.request()?.redirectedFrom()?.url()).toBe('http://localhost:3333/ipfs/bafkqablimvwgy3y')
36 |
37 | await page.waitForURL('http://bafkqablimvwgy3y.ipfs.localhost:3333')
at /Users/sgtpooki/code/work/protocol.ai/ipfs-shipyard/helia-service-worker-gateway/test-e2e/subdomain-detection.test.ts:34:36
2 failed
[chromium] › subdomain-detection.test.ts:6:3 › subdomain-detection › path requests are redirected to subdomains
[chromium] › subdomain-detection.test.ts:28:3 › subdomain-detection › path requests are redirected to subdomains automatically with autoreload enabled
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the ports are wrong, but you can see that it's not on a subdomain
Title
test: e2e subdomain redirect tests
Description
subdomain redirect tests related to #134
Summary of changes
Notes & open questions
Change checklist