|
| 1 | +import { removePassword } from "builder-util" |
| 2 | +import { describe, it } from "vitest" |
| 3 | + |
| 4 | +const testValue = "secretValue" |
| 5 | +const testQuoted = "secret with spaces" |
| 6 | + |
| 7 | +const keys = ["--accessKey", "--secretKey", "-P", "-p", "-pass", "-String", "/p", "pass:"] |
| 8 | + |
| 9 | +keys.forEach(key => { |
| 10 | + describe(`removePassword: ${key}`, () => { |
| 11 | + it("handles unquoted value (snapshot)", ({ expect }) => { |
| 12 | + const input = `${key} ${testValue}` |
| 13 | + const output = removePassword(input) |
| 14 | + |
| 15 | + expect(output).toMatchSnapshot() |
| 16 | + }) |
| 17 | + |
| 18 | + it("handles double-quoted value (snapshot)", ({ expect }) => { |
| 19 | + const input = `${key} "${testQuoted}"` |
| 20 | + const output = removePassword(input) |
| 21 | + |
| 22 | + expect(output).toMatchSnapshot() |
| 23 | + }) |
| 24 | + |
| 25 | + it("handles single-quoted value (snapshot)", ({ expect }) => { |
| 26 | + const input = `${key} '${testQuoted}'` |
| 27 | + const output = removePassword(input) |
| 28 | + |
| 29 | + expect(output).toMatchSnapshot() |
| 30 | + }) |
| 31 | + |
| 32 | + if (key === "/p") { |
| 33 | + it("handles Mac host path without hashing (snapshot)", ({ expect }) => { |
| 34 | + const macPath = "\\\\Mac\\Host\\Users\\user" |
| 35 | + const input = `${key} ${macPath}` |
| 36 | + const output = removePassword(input) |
| 37 | + |
| 38 | + expect(output).toMatchSnapshot() |
| 39 | + }) |
| 40 | + } |
| 41 | + }) |
| 42 | +}) |
| 43 | + |
| 44 | +describe("removePassword: /b … /c block", () => { |
| 45 | + it("handles /b … /c block (snapshot)", ({ expect }) => { |
| 46 | + const secret = "blockSecret" |
| 47 | + const input = `/b ${secret} /c` |
| 48 | + const output = removePassword(input) |
| 49 | + |
| 50 | + expect(output).toMatchSnapshot() |
| 51 | + }) |
| 52 | +}) |
| 53 | + |
| 54 | +describe("removePassword: multiple keys in one string", () => { |
| 55 | + it("handles two keys unquoted (snapshot)", ({ expect }) => { |
| 56 | + const input = `--accessKey key1 --secretKey key2` |
| 57 | + const output = removePassword(input) |
| 58 | + |
| 59 | + expect(output).toMatchSnapshot() |
| 60 | + }) |
| 61 | + |
| 62 | + it("handles mixed quoted and unquoted keys (snapshot)", ({ expect }) => { |
| 63 | + const input = `-p 'quoted secret' -pass unquoted` |
| 64 | + const output = removePassword(input) |
| 65 | + |
| 66 | + expect(output).toMatchSnapshot() |
| 67 | + }) |
| 68 | + |
| 69 | + it("handles several keys and /b … /c block (snapshot)", ({ expect }) => { |
| 70 | + const input = `pass: val1 --accessKey "val two" /b blockpass /c` |
| 71 | + const output = removePassword(input) |
| 72 | + |
| 73 | + expect(output).toMatchSnapshot() |
| 74 | + }) |
| 75 | +}) |
0 commit comments