(req: express.Request)
| 115 | * Return true if authenticated via cookies. |
| 116 | */ |
| 117 | export const authenticated = async (req: express.Request): Promise<boolean> => { |
| 118 | switch (req.args.auth) { |
| 119 | case AuthType.None: { |
| 120 | return true |
| 121 | } |
| 122 | case AuthType.Password: { |
| 123 | // The password is stored in the cookie after being hashed. |
| 124 | const hashedPasswordFromArgs = req.args["hashed-password"] |
| 125 | const passwordMethod = getPasswordMethod(hashedPasswordFromArgs) |
| 126 | const isCookieValidArgs: IsCookieValidArgs = { |
| 127 | passwordMethod, |
| 128 | cookieKey: sanitizeString(req.cookies[req.cookieSessionName]), |
| 129 | passwordFromArgs: req.args.password || "", |
| 130 | hashedPasswordFromArgs: req.args["hashed-password"], |
| 131 | } |
| 132 | |
| 133 | return await isCookieValid(isCookieValidArgs) |
| 134 | } |
| 135 | default: { |
| 136 | throw new Error(`Unsupported auth type ${req.args.auth}`) |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Get the relative path that will get us to the root of the page. For each |
no test coverage detected