From 46d359237e1b0a0510c4a25498978fc374fbfdff Mon Sep 17 00:00:00 2001 From: Vincent Koc Date: Thu, 18 Jun 2026 19:38:58 +0200 Subject: [PATCH] fix(qa): reject invalid qa lab ports --- scripts/qa-lab-up.ts | 3 +++ test/scripts/qa-lab-up.test.ts | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/scripts/qa-lab-up.ts b/scripts/qa-lab-up.ts index 1316fcbb678..24b1353f169 100644 --- a/scripts/qa-lab-up.ts +++ b/scripts/qa-lab-up.ts @@ -73,6 +73,9 @@ async function runQaLabUp(argv: readonly string[], deps: QaLabUpDeps = {}): Prom if (parsed === undefined) { throw new Error(`${flag} must be a positive integer.`); } + if (parsed > 65535) { + throw new Error(`${flag} must be a TCP port from 1 to 65535.`); + } return parsed; }; diff --git a/test/scripts/qa-lab-up.test.ts b/test/scripts/qa-lab-up.test.ts index abf02601562..80725a86dd0 100644 --- a/test/scripts/qa-lab-up.test.ts +++ b/test/scripts/qa-lab-up.test.ts @@ -34,12 +34,29 @@ describe("scripts/qa-lab-up", () => { ); }); + it("accepts the maximum TCP port before loading the Docker runtime", async () => { + const runQaDockerUpCommand = vi.fn(async () => {}); + const loadRuntime = vi.fn(async () => ({ runQaDockerUpCommand })); + + await expect( + qaLabUpTesting.runQaLabUp(["--gateway-port", "65535", "--qa-lab-port", "65535"], { + loadRuntime, + }), + ).resolves.toBe(0); + + expect(runQaDockerUpCommand).toHaveBeenCalledWith( + expect.objectContaining({ gatewayPort: 65535, qaLabPort: 65535 }), + ); + }); + it.each([ [["--gateway-port", "1.5"], "--gateway-port must be a positive integer."], [["--gateway-port", "0x1000"], "--gateway-port must be a positive integer."], [["--gateway-port", "0"], "--gateway-port must be a positive integer."], + [["--gateway-port", "65536"], "--gateway-port must be a TCP port from 1 to 65535."], [["--qa-lab-port", "1e4"], "--qa-lab-port must be a positive integer."], - ])("rejects non-decimal positive integer ports: %j", async (args, errorMessage) => { + [["--qa-lab-port", "65536"], "--qa-lab-port must be a TCP port from 1 to 65535."], + ])("rejects invalid TCP ports: %j", async (args, errorMessage) => { const loadRuntime = vi.fn(async () => ({ runQaDockerUpCommand: vi.fn(async () => {}) })); await expect(qaLabUpTesting.runQaLabUp(args, { loadRuntime })).rejects.toThrow(errorMessage);