Some checks failed
Test examples / Test Examples (20) (push) Has been cancelled
Test examples / Test Examples (22) (push) Has been cancelled
Lock Threads / action (push) Has been cancelled
Trigger Release / start (push) Has been cancelled
Stale issue handler / stale (push) Has been cancelled
Update Font Data / create-pull-request (push) Has been cancelled
build-and-deploy / deploy-target (push) Has been cancelled
build-and-deploy / build (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-musl - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-unknown-linux-gnu - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-pc-windows-msvc - node@16 (push) Has been cancelled
build-and-deploy / stable - aarch64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / stable - x86_64-apple-darwin - node@16 (push) Has been cancelled
build-and-deploy / build-wasm (nodejs) (push) Has been cancelled
build-and-deploy / build-wasm (web) (push) Has been cancelled
build-and-deploy / Deploy preview tarball (push) Has been cancelled
build-and-deploy / Potentially publish release (push) Has been cancelled
build-and-deploy / publish-turbopack-npm-packages (push) Has been cancelled
build-and-deploy / Deploy examples (push) Has been cancelled
build-and-deploy / thank you, build (push) Has been cancelled
build-and-deploy / Upload Turbopack Bytesize metrics to Datadog (push) Has been cancelled
Rspack Next.js development integration tests / Rspack integration tests (push) Has been cancelled
Rspack Next.js production integration tests / Rspack integration tests (push) Has been cancelled
Turbopack Next.js development integration tests / Next.js integration tests (push) Has been cancelled
Turbopack Next.js production integration tests / Next.js integration tests (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack development test manifest (push) Has been cancelled
Update Rspack test manifest / Update and upload Rspack production test manifest (push) Has been cancelled
Upload bundler test manifests to areweturboyet.com / Upload test results (push) Has been cancelled
Update React / create-pull-request (push) Has been cancelled
test-e2e-project-reset-cron / reset-test-project (push) Has been cancelled
Notify about the top 15 issues/PRs/feature requests (most reacted) in the last 90 days / run (push) Has been cancelled
144 lines
4.3 KiB
TypeScript
144 lines
4.3 KiB
TypeScript
import type * as Playwright from 'playwright'
|
|
import webdriver from 'next-webdriver'
|
|
import { createRouterAct } from 'router-act'
|
|
import { findPort, nextBuild } from 'next-test-utils'
|
|
import { isNextDeploy, isNextDev } from 'e2e-utils'
|
|
import { start } from './server.mjs'
|
|
|
|
describe('segment cache (CDN cache busting)', () => {
|
|
if (isNextDev || isNextDeploy) {
|
|
test('should not run during dev or deploy test runs', () => {})
|
|
return
|
|
}
|
|
|
|
// TODO(runtime-ppr): add tests for runtime prefetches
|
|
|
|
// To debug these tests locally, run:
|
|
// node start.mjs
|
|
//
|
|
// This will start the Next app and also a proxy server that simulates a CDN.
|
|
// Like certain real-world CDNs, our fake CDN doesn't respect the Vary header.
|
|
// It only uses the URL.
|
|
let cleanup: () => Promise<void>
|
|
let port: number
|
|
|
|
beforeAll(async () => {
|
|
const appDir = __dirname
|
|
await nextBuild(appDir, undefined, { cwd: appDir })
|
|
const proxyPort = (port = await findPort())
|
|
const nextPort = await findPort()
|
|
cleanup = await start(proxyPort, nextPort)
|
|
})
|
|
|
|
afterAll(async () => {
|
|
await cleanup()
|
|
})
|
|
|
|
it(
|
|
"perform fully prefetched navigation with a CDN that doesn't respect " +
|
|
'the Vary header',
|
|
async () => {
|
|
let act
|
|
const browser = await webdriver(port, '/', {
|
|
beforePageLoad(p: Playwright.Page) {
|
|
act = createRouterAct(p)
|
|
},
|
|
})
|
|
|
|
// Initiate a prefetch. Each segment will be prefetched individually,
|
|
// using the pathname of the target page and a custom header specifying
|
|
// the segment. If we didn't also set a cache-busting search param, then
|
|
// the fake CDN used by this test suite would incorrectly use the same
|
|
// entry for every segment, poisoning the cache.
|
|
await act(
|
|
async () => {
|
|
const linkToggle = await browser.elementByCss(
|
|
'[data-link-accordion="/target-page"]'
|
|
)
|
|
await linkToggle.click()
|
|
},
|
|
{
|
|
includes: 'Target page',
|
|
}
|
|
)
|
|
|
|
// Navigate to the prefetched target page.
|
|
await act(async () => {
|
|
const link = await browser.elementByCss('a[href="/target-page"]')
|
|
await link.click()
|
|
|
|
// The page was prefetched, so we're able to render the target
|
|
// page immediately.
|
|
const div = await browser.elementById('target-page')
|
|
expect(await div.text()).toBe('Target page')
|
|
}, 'no-requests')
|
|
}
|
|
)
|
|
|
|
it(
|
|
'prevent cache poisoning attacks by responding with a redirect to correct ' +
|
|
'cache busting query param if a custom header is sent during a prefetch ' +
|
|
'without a corresponding cache-busting search param',
|
|
async () => {
|
|
const browser = await webdriver(port, '/')
|
|
const { status, responseUrl, redirected } = await browser.eval(
|
|
async () => {
|
|
const res = await fetch('/target-page', {
|
|
headers: {
|
|
rsc: '1',
|
|
'next-router-prefetch': '1',
|
|
'next-router-segment-prefetch': '/_tree',
|
|
},
|
|
})
|
|
return {
|
|
status: res.status,
|
|
responseUrl: res.url,
|
|
redirected: res.redirected,
|
|
}
|
|
}
|
|
)
|
|
expect(status).toBe(200)
|
|
expect(responseUrl).toContain('_rsc=')
|
|
expect(redirected).toBe(true)
|
|
}
|
|
)
|
|
|
|
it(
|
|
'perform fully prefetched navigation when a third-party proxy ' +
|
|
'performs a redirect',
|
|
async () => {
|
|
let act
|
|
const browser = await webdriver(port, '/', {
|
|
beforePageLoad(p: Playwright.Page) {
|
|
act = createRouterAct(p)
|
|
},
|
|
})
|
|
|
|
await act(
|
|
async () => {
|
|
const linkToggle = await browser.elementByCss(
|
|
'[data-link-accordion="/redirect-to-target-page"]'
|
|
)
|
|
await linkToggle.click()
|
|
},
|
|
{
|
|
includes: 'Target page',
|
|
}
|
|
)
|
|
|
|
// Navigate to the prefetched target page.
|
|
await act(async () => {
|
|
const link = await browser.elementByCss(
|
|
'a[href="/redirect-to-target-page"]'
|
|
)
|
|
await link.click()
|
|
|
|
// The page was prefetched, so we're able to render the target
|
|
// page immediately.
|
|
const div = await browser.elementById('target-page')
|
|
expect(await div.text()).toBe('Target page')
|
|
}, 'no-requests')
|
|
}
|
|
)
|
|
})
|