The plugin's version is a constant: no package.json among a site's public assets
pluginVersion() named package.json relative to its own module. A bundler takes such a file for an asset: a Turbopack build of a site copied the plugin's whole package.json (dependency lists, scripts, the registry and repository addresses; no secret) to /_next/static/media/package.<hash>.json, served to anyone. Webpack kept it on the server side. The version now comes from src/version.ts (scripts/write-version.mjs, run by the `version` script; a test fails when it differs from package.json). A smoke test of the built site: nothing under .next/static is a package manifest. Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
bc0fa65fd7
commit
9a648b0498
@@ -1,4 +1,6 @@
|
||||
import { expect, type Page, test } from '@playwright/test'
|
||||
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs'
|
||||
import path from 'node:path'
|
||||
|
||||
import { attachmentOf, startSmtpSink } from './smtp-sink'
|
||||
import { totp } from './totp'
|
||||
@@ -176,6 +178,24 @@ test('SEO and GEO routes respond', async ({ request }) => {
|
||||
expect(await mcp.text()).toContain('get_page')
|
||||
})
|
||||
|
||||
// A bundler turns a file that server code names relative to its own module into an ASSET. Turbopack published the
|
||||
// plugin's whole package.json that way (dependency lists, scripts, the registry address) under /_next/static/media/.
|
||||
test('no package.json is published: nothing under .next/static holds one, and the obvious addresses answer 404', async ({ request }) => {
|
||||
const statics = path.resolve('.next/static')
|
||||
const walk = (dir: string): string[] => (existsSync(dir) ? readdirSync(dir).flatMap((name) => {
|
||||
const file = path.join(dir, name)
|
||||
return statSync(file).isDirectory() ? walk(file) : [file]
|
||||
}) : [])
|
||||
const files = walk(statics)
|
||||
expect(files.length, 'the built site\'s .next/static (run from the site folder)').toBeGreaterThan(0)
|
||||
// by name, and by content (a manifest of a package: its dependency lists)
|
||||
const manifests = files.filter((file) => /package[^/]*\.json$/.test(file) || (file.endsWith('.json') && /"(?:devDependencies|peerDependencies|publishConfig)"\s*:/.test(readFileSync(file, 'utf8'))))
|
||||
expect(manifests.map((file) => path.relative(statics, file))).toEqual([])
|
||||
for (const address of ['/package.json', '/_next/package.json', '/_next/static/package.json', '/_next/static/media/package.json']) {
|
||||
expect((await request.get(address)).status(), address).toBe(404)
|
||||
}
|
||||
})
|
||||
|
||||
test('security headers: CSP enforced, no X-Powered-By', async ({ request }) => {
|
||||
const headers = (await request.get('/pl')).headers()
|
||||
expect(headers['content-security-policy']).toBeTruthy()
|
||||
|
||||
Reference in New Issue
Block a user