-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathfind_compromised_secrets.test.js
More file actions
61 lines (50 loc) · 1.46 KB
/
find_compromised_secrets.test.js
File metadata and controls
61 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import assert from "assert";
import {
findSecretsInLines,
base64Regex1,
} from "./find_compromised_secrets_utils.js";
function testFindSecretsInLines() {
console.log("Running test for findSecretsInLines...");
// Simulate reading lines from a file
const lines = [
"2025-03-20T12:01:00Z SW1kcGRHaDFZbDkwYjJ0bGJpSTZleUoyWVd4MVpTSTZJbWRvYzE4d01EQXdNREF3TURBd01EQXdNREF3TURBd01EQXdNREF3TURBd01EQXdNREFpTENBaWFYTlRaV055WlhRaU9pQjBjblZsZlFvPQo=",
"2025-03-20T12:00:00Z SWpBaU9uc2lkbUZzZFdVaU9pSmhJaXdnSW1selUyVmpjbVYwSWpwMGNuVmxmUW89Cg==",
"2025-03-20T12:00:00Z Some log message",
"2025-03-20T12:02:00Z Another log message",
"",
];
const data =
"SWAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
const match = base64Regex1.exec(data);
assert(match, "Failed to match base64 data");
// Expected secrets after decoding
const expectedSecrets = [
{
github_token: {
isSecret: true,
value: "ghs_000000000000000000000000000000000",
},
},
{
0: {
isSecret: true,
value: "a",
},
},
];
// Call the function
const secrets = findSecretsInLines(lines);
// Assert the results
assert.deepStrictEqual(
secrets,
expectedSecrets,
"The secrets extracted from the lines do not match the expected output."
);
console.log("Test passed!");
}
// Run the test
function main() {
console.log("Running tests...");
testFindSecretsInLines();
}
main();