test(tests): probe the measure preview port without HTTP
Fixes semgrep react-insecure-request (CWE-319): ready() now checks the preview port with a node:net TCP connect instead of fetch on http://127.0.0.1. Also ignore apps/app/e2e/test-results/ in .dockerignore so the measure build, which inlines the sandbox anon key, stays out of the Docker context.
This commit is contained in:
1 parent
a75c2999de
commit
059764ec60
2 files changed
+18
-5
No files matched your search
@@ -21,5 +21,6 @@ logos/
|
||||
target/
|
||||
packages/core-wasm/pkg/
|
||||
packages/core-wasm/pkg-proofs/
|
||||
apps/app/e2e/test-results/
|
||||
docker/dev-gateway/htpasswd
|
||||
docker/dev-gateway/mailpit-password
|
||||
@@ -8,6 +8,7 @@
|
||||
* uses it.
|
||||
*/
|
||||
import { spawn, type ChildProcess } from 'node:child_process'
|
||||
import { createConnection } from 'node:net'
|
||||
import { join } from 'node:path'
|
||||
import { FAKE_SUPABASE_ORIGIN } from './sandbox'
|
||||
|
||||
@@ -45,14 +46,25 @@ function run(args: string[]): Promise<void> {
|
||||
})
|
||||
}
|
||||
|
||||
function portOpen(port: number): Promise<boolean> {
|
||||
return new Promise((done) => {
|
||||
const socket = createConnection({ host: '127.0.0.1', port })
|
||||
socket.on('connect', () => {
|
||||
socket.destroy()
|
||||
done(true)
|
||||
})
|
||||
socket.on('error', () => {
|
||||
socket.destroy()
|
||||
done(false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function ready(child: ChildProcess): Promise<void> {
|
||||
const port = Number(new URL(PREVIEW_ORIGIN).port)
|
||||
for (let tries = 0; tries < 100; tries++) {
|
||||
if (child.exitCode !== null) throw new Error('vite preview stopped')
|
||||
const up = await fetch(`${PREVIEW_ORIGIN}/`).then(
|
||||
(r) => r.ok,
|
||||
() => false,
|
||||
)
|
||||
if (up) return
|
||||
if (await portOpen(port)) return
|
||||
await new Promise((wait) => setTimeout(wait, 200))
|
||||
}
|
||||
throw new Error('vite preview did not answer')
|
||||
|
||||
Reference in new issue
Block a user