refactor: parse options with multiple = in cli

There was a case with the hashed-password which had multiple equal signs in the
value and it wasn't being parsed correctly. This uses a new function and adds a
few tests.
This commit is contained in:
Joe Previte
2021-06-03 16:37:46 -07:00
parent 531b7c0c25
commit 8c2bb61af9
8 changed files with 71 additions and 72 deletions

View File

@ -63,9 +63,10 @@ export const ensureAuthenticated = async (
*/
export const authenticated = async (req: express.Request): Promise<boolean> => {
switch (req.args.auth) {
case AuthType.None:
case AuthType.None: {
return true
case AuthType.Password:
}
case AuthType.Password: {
// The password is stored in the cookie after being hashed.
const hashedPasswordFromArgs = req.args["hashed-password"]
const passwordMethod = getPasswordMethod(hashedPasswordFromArgs)
@ -77,8 +78,10 @@ export const authenticated = async (req: express.Request): Promise<boolean> => {
}
return await isCookieValid(isCookieValidArgs)
default:
}
default: {
throw new Error(`Unsupported auth type ${req.args.auth}`)
}
}
}