fix(test): restrict storage fixture to loopback (#8582)

This commit is contained in:
gensokyo-dev authored and GitHub committed 2026-11-02 02:52:20 +08:00
1 parent 0354145a2a
commit 6d60db1951
3 files changed
+59 -1

No files matched your search

+1 -1
View File
@@ -171,7 +171,7 @@ export const startStorageSite = async () => {
response.end(storagePage(kind, port));
},
);
server.listen(0, "::");
server.listen(0, "127.0.0.1");
await once(server, "listening");
port = server.address().port;
return {
@@ -0,0 +1,36 @@
import { networkInterfaces } from "node:os";
import { fileURLToPath } from "node:url";
import { expect } from "vitest";
import { processTest } from "../../support/process/processFixture.js";
const hasNonLoopbackIpv4 = Object.values(networkInterfaces())
.flatMap((entries) => entries ?? [])
.some((entry) => entry.family === "IPv4" && !entry.internal);
processTest.skipIf(!hasNonLoopbackIpv4)(
"storage fixture serves localhost and refuses this host's non-loopback interface",
async ({ processes }) => {
const result = await processes.run(
process.execPath,
[
fileURLToPath(
new URL(
"../../fixtures/browserFixtureHttpTargets.mjs",
import.meta.url,
),
),
"storage",
"listener-scope",
],
{ timeoutMs: 15_000 },
);
expect(result.signal, result.stderr).toBeNull();
expect(result.exitCode, result.stderr).toBe(0);
expect(result.stderr).toBe("");
expect(result.stdout).toBe(
"storage: localhost served; non-loopback connection refused\n" +
"storage: target routing, invalid-target recovery and physical close passed\n",
);
},
);
+22
View File
@@ -1,6 +1,7 @@
import assert from "node:assert/strict";
import { once } from "node:events";
import { createServer, request } from "node:http";
import { networkInterfaces } from "node:os";
import {
closeVerifierResources,
withVerifierCleanup,
@@ -106,6 +107,27 @@ await withVerifierCleanup(async () => {
else assert(reply.body.includes('id="main-report"'));
};
await checkOrdinary();
if (process.argv[3] === "listener-scope") {
assert.equal(kind, "storage");
const named = new URL(origin);
named.hostname = "localhost";
const localhost = await send(named.href, ordinary);
assert.equal(localhost.status, 200);
assert(localhost.body.includes('id="main-report"'));
const address = Object.values(networkInterfaces())
.flatMap((entries) => entries ?? [])
.find((entry) => entry.family === "IPv4" && !entry.internal);
assert(
address,
"Listener scope probe requires an owned non-loopback IPv4 interface",
);
const nonLoopback = new URL(origin);
nonLoopback.hostname = address.address;
await assert.rejects(send(nonLoopback.href, ordinary), {
code: "ECONNREFUSED",
});
console.log("storage: localhost served; non-loopback connection refused");
}
for (const target of [
"http://[",
"ftp://127.0.0.1/probe",