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:
bchanot committed 2026-11-18 13:46:55 +01:00
1 parent a75c2999de
commit 059764ec60
2 files changed
+18 -5

No files matched your search

+1
View File
@@ -21,5 +21,6 @@ logos/
target/ target/
packages/core-wasm/pkg/ packages/core-wasm/pkg/
packages/core-wasm/pkg-proofs/ packages/core-wasm/pkg-proofs/
apps/app/e2e/test-results/
docker/dev-gateway/htpasswd docker/dev-gateway/htpasswd
docker/dev-gateway/mailpit-password docker/dev-gateway/mailpit-password
+17 -5
View File
@@ -8,6 +8,7 @@
* uses it. * uses it.
*/ */
import { spawn, type ChildProcess } from 'node:child_process' import { spawn, type ChildProcess } from 'node:child_process'
import { createConnection } from 'node:net'
import { join } from 'node:path' import { join } from 'node:path'
import { FAKE_SUPABASE_ORIGIN } from './sandbox' 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> { async function ready(child: ChildProcess): Promise<void> {
const port = Number(new URL(PREVIEW_ORIGIN).port)
for (let tries = 0; tries < 100; tries++) { for (let tries = 0; tries < 100; tries++) {
if (child.exitCode !== null) throw new Error('vite preview stopped') if (child.exitCode !== null) throw new Error('vite preview stopped')
const up = await fetch(`${PREVIEW_ORIGIN}/`).then( if (await portOpen(port)) return
(r) => r.ok,
() => false,
)
if (up) return
await new Promise((wait) => setTimeout(wait, 200)) await new Promise((wait) => setTimeout(wait, 200))
} }
throw new Error('vite preview did not answer') throw new Error('vite preview did not answer')