fix(matrix): reject malformed integer cli values

This commit is contained in:
Peter Steinberger
2026-05-26 02:05:58 +01:00
parent 884d346999
commit cb34175dfd
2 changed files with 17 additions and 0 deletions

View File

@@ -386,6 +386,20 @@ describe("matrix CLI verification commands", () => {
expect(consoleLogMock).toHaveBeenCalledWith("Backup: active and trusted on this device");
});
it("rejects malformed Matrix self-verification timeout values", async () => {
const program = buildProgram();
await program.parseAsync(["matrix", "verify", "self", "--timeout-ms", "5000ms"], {
from: "user",
});
expect(process.exitCode).toBe(1);
expect(consoleErrorMock).toHaveBeenCalledWith(
"Self-verification failed: --timeout-ms must be an integer",
);
expect(runMatrixSelfVerificationMock).not.toHaveBeenCalled();
});
it("requests Matrix self-verification and prints the follow-up SAS commands", async () => {
requestMatrixVerificationMock.mockResolvedValue(
mockMatrixVerificationSummary({

View File

@@ -234,6 +234,9 @@ function parseOptionalInt(value: string | undefined, fieldName: string): number
if (!trimmed) {
return undefined;
}
if (!/^-?\d+$/.test(trimmed)) {
throw new Error(`${fieldName} must be an integer`);
}
const parsed = Number.parseInt(trimmed, 10);
if (!Number.isFinite(parsed)) {
throw new Error(`${fieldName} must be an integer`);