Skip to content

Commit 00935ab

Browse files
h0tak88rclaude
andcommitted
test: build fake GitHub-PAT fixtures at runtime (clear GitGuardian alert)
pattern_matcher_test.go fed literal `ghp_...`-shaped strings to ScanContentForSecrets to verify the GitHub-token regex. They are synthetic test inputs, not real credentials, but the literal form tripped GitGuardian's GitHub-PAT detector on the PR. Build the token fixtures at runtime (`"ghp_" + strings.Repeat(...)`) so no token-shaped literal appears in source; the test still exercises the same regex. No secret to rotate — these were never real tokens. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 65a072b commit 00935ab

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

internal/utils/pattern_matcher_test.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,24 @@ func TestScanContentForSecretsFindsMatch(t *testing.T) {
1313
"AWS Access Key ID": {regexp.MustCompile(`AKIA[0-9A-Z]{16}`)},
1414
}
1515

16+
// GitHub-PAT-shaped fixtures built at runtime so no token literal appears in
17+
// source (these are fake test inputs, but a literal trips secret scanners).
18+
ghToken := "ghp_" + strings.Repeat("a1B2", 9) // 36 chars after the prefix
19+
ghToken2 := "ghp_" + strings.Repeat("z9Y8", 9) // distinct, also 36 chars
20+
1621
tests := []struct {
17-
name string
18-
content string
19-
source string
20-
wantMatchCount int
21-
wantContains string
22+
name string
23+
content string
24+
source string
25+
wantMatchCount int
26+
wantContains string
2227
}{
2328
{
2429
name: "github token found",
25-
content: "const token = \"ghp_1234567890abcdef1234567890abcdef1234\"",
30+
content: "const token = \"" + ghToken + "\"",
2631
source: "config.js",
2732
wantMatchCount: 1,
28-
wantContains: "ghp_1234567890abcdef1234567890abcdef1234",
33+
wantContains: ghToken,
2934
},
3035
{
3136
name: "api key with quotes",
@@ -55,7 +60,7 @@ func TestScanContentForSecretsFindsMatch(t *testing.T) {
5560
},
5661
{
5762
name: "source prefix in output",
58-
content: "ghp_abcdefghijklmnopqrstuvwxyz0123456789",
63+
content: ghToken2,
5964
source: "leaked.js",
6065
wantMatchCount: 1,
6166
wantContains: "leaked.js",

0 commit comments

Comments
 (0)