mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Enable skew protection for all start-mode tests when Turbopack is enabled (i.e. not dev). This works by setting `NEXT_DEPLOYMENT_ID` in the test infra - When running the tests, `packages/next/src/server/lib/router-utils/resolve-routes.ts` now validates that all static asset requests have the correct `?dpl=...` query param value, and returns a 404 if missing. - It can be disabled with `disableAutoSkewProtection: true` in the test options - There were various tests that were asserting URLs and were missing the optional `?dpl` at the end. - `next.getDeploymentIdQuery()` can be used to get the `?dpl=dpl_123912js` string (or an empty string) - `next.getAssetQuery()` currently behaves like `getDeploymentIdQuery`, but will switch to prefer the immutable static token in #88607
74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { nextTestSetup } from 'e2e-utils'
|
|
import { retry } from 'next-test-utils'
|
|
import { join } from 'node:path'
|
|
|
|
describe('deployment-id-handling disabled', () => {
|
|
const deploymentId = Date.now() + ''
|
|
const { next } = nextTestSetup({
|
|
files: join(__dirname, 'app'),
|
|
env: {
|
|
COOKIE_SKEW: '1',
|
|
NEXT_DEPLOYMENT_ID: 'thankyounext',
|
|
},
|
|
disableAutoSkewProtection: true,
|
|
})
|
|
|
|
it('should set set-cookie header correctly', async () => {
|
|
const res = await next.fetch('/')
|
|
expect(res.headers.get('set-cookie')).toBe(
|
|
'__vdpl=thankyounext; Path=/; HttpOnly'
|
|
)
|
|
})
|
|
|
|
it.each([
|
|
{ urlPath: '/' },
|
|
{ urlPath: '/pages-edge' },
|
|
{ urlPath: '/from-app' },
|
|
{ urlPath: '/from-app/edge' },
|
|
])(
|
|
'should not append dpl query to all assets for $urlPath',
|
|
async ({ urlPath }) => {
|
|
const $ = await next.render$(urlPath)
|
|
|
|
expect($('#deploymentId').text()).not.toBe(deploymentId)
|
|
|
|
const scripts = Array.from($('script'))
|
|
expect(scripts.length).toBeGreaterThan(0)
|
|
|
|
for (const script of scripts) {
|
|
if (script.attribs.src) {
|
|
expect(script.attribs.src).not.toContain('dpl=' + deploymentId)
|
|
}
|
|
}
|
|
|
|
const links = Array.from($('link'))
|
|
expect(links.length).toBeGreaterThan(0)
|
|
|
|
for (const link of links) {
|
|
if (link.attribs.href) {
|
|
expect(link.attribs.href).not.toContain('dpl=' + deploymentId)
|
|
}
|
|
}
|
|
|
|
const browser = await next.browser(urlPath)
|
|
const requests = []
|
|
|
|
browser.on('request', (req) => {
|
|
requests.push(req.url())
|
|
})
|
|
|
|
await browser.elementByCss('#dynamic-import').click()
|
|
|
|
await retry(() => expect(requests).not.toBeEmpty())
|
|
|
|
try {
|
|
expect(
|
|
requests.every((item) => !item.includes('dpl=' + deploymentId))
|
|
).toBe(true)
|
|
} finally {
|
|
require('console').error('requests', requests)
|
|
}
|
|
}
|
|
)
|
|
})
|