Archived
1
0

cli: hashedPassword -> hashed-password (#2454)

Capital letters in the CLI are evil.

cc @code-asher
This commit is contained in:
Anmol Sethi
2020-12-18 12:20:38 -05:00
committed by GitHub
parent 386af14a77
commit 60c270aef5
7 changed files with 14 additions and 14 deletions

View File

@ -29,7 +29,7 @@ export interface Args extends VsArgs {
config?: string
auth?: AuthType
password?: string
hashedPassword?: string
"hashed-password"?: string
cert?: OptionalString
"cert-host"?: string
"cert-key"?: string
@ -106,7 +106,7 @@ const options: Options<Required<Args>> = {
type: "string",
description: "The password for password authentication (can only be passed in via $PASSWORD or the config file).",
},
hashedPassword: {
"hashed-password": {
type: "string",
description:
"The password hashed with SHA-256 for password authentication (can only be passed in via $HASHED_PASSWORD or the config file). \n" +
@ -285,8 +285,8 @@ export const parse = (
throw new Error("--password can only be set in the config file or passed in via $PASSWORD")
}
if (key === "hashedPassword" && !opts?.configFile) {
throw new Error("--hashedPassword can only be set in the config file or passed in via $HASHED_PASSWORD")
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")
}
const option = options[key]
@ -466,7 +466,7 @@ export async function setDefaults(cliArgs: Args, configArgs?: ConfigArgs): Promi
const usingEnvHashedPassword = !!process.env.HASHED_PASSWORD
if (process.env.HASHED_PASSWORD) {
args.hashedPassword = process.env.HASHED_PASSWORD
args["hashed-password"] = process.env.HASHED_PASSWORD
usingEnvPassword = false
}

View File

@ -99,7 +99,7 @@ const main = async (args: DefaultedArgs): Promise<void> => {
logger.info(`Using user-data-dir ${humanPath(args["user-data-dir"])}`)
logger.trace(`Using extensions-dir ${humanPath(args["extensions-dir"])}`)
if (args.auth === AuthType.Password && !args.password && !args.hashedPassword) {
if (args.auth === AuthType.Password && !args.password && !args["hashed-password"]) {
throw new Error(
"Please pass in a password via the config file or environment variable ($PASSWORD or $HASHED_PASSWORD)",
)

View File

@ -54,8 +54,8 @@ export const authenticated = (req: express.Request): boolean => {
// The password is stored in the cookie after being hashed.
return !!(
req.cookies.key &&
(req.args.hashedPassword
? safeCompare(req.cookies.key, req.args.hashedPassword)
(req.args["hashed-password"]
? safeCompare(req.cookies.key, req.args["hashed-password"])
: req.args.password && safeCompare(req.cookies.key, hash(req.args.password)))
)
default:

View File

@ -68,8 +68,8 @@ router.post("/", async (req, res) => {
}
if (
req.args.hashedPassword
? safeCompare(hash(req.body.password), req.args.hashedPassword)
req.args["hashed-password"]
? safeCompare(hash(req.body.password), req.args["hashed-password"])
: req.args.password && safeCompare(req.body.password, req.args.password)
) {
// The hash does not add any actual security but we do it for