Move argument defaults into setDefaults
This commit is contained in:
@ -14,17 +14,23 @@ type Mutable<T> = {
|
||||
describe("parser", () => {
|
||||
beforeEach(() => {
|
||||
delete process.env.LOG_LEVEL
|
||||
delete process.env.PASSWORD
|
||||
})
|
||||
|
||||
// The parser should not set any defaults so the caller can determine what
|
||||
// values the user actually set. These are only set after explicitly calling
|
||||
// `setDefaults`.
|
||||
const defaults = {
|
||||
auth: "password",
|
||||
host: "localhost",
|
||||
port: 8080,
|
||||
"proxy-domain": [],
|
||||
usingEnvPassword: false,
|
||||
"extensions-dir": path.join(paths.data, "extensions"),
|
||||
"user-data-dir": paths.data,
|
||||
}
|
||||
|
||||
it("should set defaults", () => {
|
||||
it("should parse nothing", () => {
|
||||
assert.deepEqual(parse([]), { _: [] })
|
||||
})
|
||||
|
||||
@ -232,6 +238,71 @@ describe("parser", () => {
|
||||
"proxy-domain": ["*.coder.com", "test.com"],
|
||||
})
|
||||
})
|
||||
|
||||
it("should enforce cert-key with cert value or otherwise generate one", async () => {
|
||||
const args = parse(["--cert"])
|
||||
assert.deepEqual(args, {
|
||||
_: [],
|
||||
cert: {
|
||||
value: undefined,
|
||||
},
|
||||
})
|
||||
assert.throws(() => parse(["--cert", "test"]), /--cert-key is missing/)
|
||||
assert.deepEqual(await setDefaults(args), {
|
||||
_: [],
|
||||
...defaults,
|
||||
cert: {
|
||||
value: path.join(tmpdir, "self-signed.cert"),
|
||||
},
|
||||
"cert-key": path.join(tmpdir, "self-signed.key"),
|
||||
})
|
||||
})
|
||||
|
||||
it("should override with --link", async () => {
|
||||
const args = parse("--cert test --cert-key test --socket test --host 0.0.0.0 --port 8888 --link test".split(" "))
|
||||
assert.deepEqual(await setDefaults(args), {
|
||||
_: [],
|
||||
...defaults,
|
||||
auth: "none",
|
||||
host: "localhost",
|
||||
link: {
|
||||
value: "test",
|
||||
},
|
||||
port: 0,
|
||||
cert: undefined,
|
||||
"cert-key": path.resolve("test"),
|
||||
socket: undefined,
|
||||
})
|
||||
})
|
||||
|
||||
it("should use env var password", async () => {
|
||||
process.env.PASSWORD = "test"
|
||||
const args = parse([])
|
||||
assert.deepEqual(args, {
|
||||
_: [],
|
||||
})
|
||||
|
||||
assert.deepEqual(await setDefaults(args), {
|
||||
...defaults,
|
||||
_: [],
|
||||
password: "test",
|
||||
usingEnvPassword: true,
|
||||
})
|
||||
})
|
||||
|
||||
it("should filter proxy domains", async () => {
|
||||
const args = parse(["--proxy-domain", "*.coder.com", "--proxy-domain", "coder.com", "--proxy-domain", "coder.org"])
|
||||
assert.deepEqual(args, {
|
||||
_: [],
|
||||
"proxy-domain": ["*.coder.com", "coder.com", "coder.org"],
|
||||
})
|
||||
|
||||
assert.deepEqual(await setDefaults(args), {
|
||||
...defaults,
|
||||
_: [],
|
||||
"proxy-domain": ["coder.com", "coder.org"],
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe("cli", () => {
|
||||
|
Reference in New Issue
Block a user