|
1 |
| -import { hash, isHashMatch, hashLegacy, isHashLegacyMatch } from "../../../src/node/util" |
| 1 | +import { |
| 2 | + hash, |
| 3 | + isHashMatch, |
| 4 | + PasswordMethod, |
| 5 | + getPasswordMethod, |
| 6 | + hashLegacy, |
| 7 | + isHashLegacyMatch, |
| 8 | +} from "../../../src/node/util" |
2 | 9 |
|
3 | 10 | describe("getEnvPaths", () => {
|
4 | 11 | describe("on darwin", () => {
|
@@ -203,3 +210,25 @@ describe("isHashLegacyMatch", () => {
|
203 | 210 | expect(isHashLegacyMatch(password, _hash)).toBe(true)
|
204 | 211 | })
|
205 | 212 | })
|
| 213 | + |
| 214 | +describe("getPasswordMethod", () => { |
| 215 | + it("should return PLAIN_TEXT for no hashed password", () => { |
| 216 | + const hashedPassword = undefined |
| 217 | + const passwordMethod = getPasswordMethod(hashedPassword) |
| 218 | + const expected: PasswordMethod = "PLAIN_TEXT" |
| 219 | + expect(passwordMethod).toEqual(expected) |
| 220 | + }) |
| 221 | + it("should return ARGON2 for password with 'argon2'", () => { |
| 222 | + const hashedPassword = |
| 223 | + "$argon2i$v=19$m=4096,t=3,p=1$0qR/o+0t00hsbJFQCKSfdQ$oFcM4rL6o+B7oxpuA4qlXubypbBPsf+8L531U7P9HYY" |
| 224 | + const passwordMethod = getPasswordMethod(hashedPassword) |
| 225 | + const expected: PasswordMethod = "ARGON2" |
| 226 | + expect(passwordMethod).toEqual(expected) |
| 227 | + }) |
| 228 | + it("should return SHA256 for password with legacy hash", () => { |
| 229 | + const hashedPassword = "936a185caaa266bb9cbe981e9e05cb78cd732b0b3280eb944412bb6f8f8f07af" |
| 230 | + const passwordMethod = getPasswordMethod(hashedPassword) |
| 231 | + const expected: PasswordMethod = "SHA256" |
| 232 | + expect(passwordMethod).toEqual(expected) |
| 233 | + }) |
| 234 | +}) |
0 commit comments