From e588f8b0b0d868ea08a7e0222b024981393113c4 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 4 Oct 2021 14:51:14 -0700 Subject: [PATCH 1/2] feat(cli): add tests for password, hashed-password --- src/node/cli.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/node/cli.ts b/src/node/cli.ts index fe9b3fc1..b3f4a820 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -310,10 +310,12 @@ export const parse = ( throw error(`Unknown option ${arg}`) } + // TODO@jsjoeio add test for this if block if (key === "password" && !opts?.configFile) { throw new Error("--password can only be set in the config file or passed in via $PASSWORD") } + // TODO@jsjoeio add test for this if block if (key === "hashed-password" && !opts?.configFile) { throw new Error("--hashed-password can only be set in the config file or passed in via $HASHED_PASSWORD") } From 45319ec648522920925b54ee530086180ac541d7 Mon Sep 17 00:00:00 2001 From: Joe Previte Date: Mon, 4 Oct 2021 15:04:07 -0700 Subject: [PATCH 2/2] woo! --- src/node/cli.ts | 2 -- test/unit/node/cli.test.ts | 12 ++++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/node/cli.ts b/src/node/cli.ts index b3f4a820..fe9b3fc1 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -310,12 +310,10 @@ export const parse = ( throw error(`Unknown option ${arg}`) } - // TODO@jsjoeio add test for this if block if (key === "password" && !opts?.configFile) { throw new Error("--password can only be set in the config file or passed in via $PASSWORD") } - // TODO@jsjoeio add test for this if block if (key === "hashed-password" && !opts?.configFile) { throw new Error("--hashed-password can only be set in the config file or passed in via $HASHED_PASSWORD") } diff --git a/test/unit/node/cli.test.ts b/test/unit/node/cli.test.ts index 97b64878..94321dd0 100644 --- a/test/unit/node/cli.test.ts +++ b/test/unit/node/cli.test.ts @@ -333,6 +333,18 @@ describe("parser", () => { }) }) + it("should error if password passed in", () => { + expect(() => parse(["--password", "supersecret123"])).toThrowError( + "--password can only be set in the config file or passed in via $PASSWORD", + ) + }) + + it("should error if hashed-password passed in", () => { + expect(() => parse(["--hashed-password", "fdas423fs8a"])).toThrowError( + "--hashed-password can only be set in the config file or passed in via $HASHED_PASSWORD", + ) + }) + it("should filter proxy domains", async () => { const args = parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"]) expect(args).toEqual({