File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,6 +18,19 @@ func clearHighRiskEnv(t *testing.T) {
1818 }
1919}
2020
21+ // clearAllEnv sets every environment variable to empty for the duration of the test.
22+ // Use this in tests that assert 0 findings, since nameRegex patterns (e.g. (?i)GITHUB)
23+ // can match CI variables like GITHUB_WORKSPACE that aren't credentials.
24+ // t.Setenv restores original values after the test.
25+ func clearAllEnv (t * testing.T ) {
26+ t .Helper ()
27+ for _ , entry := range os .Environ () {
28+ if idx := strings .IndexByte (entry , '=' ); idx >= 0 {
29+ t .Setenv (entry [:idx ], "" )
30+ }
31+ }
32+ }
33+
2134// newScannerWithHome creates an APIKeyScanner with HomeDir set to home and no extras.
2235func newScannerWithHome (home string ) * scan.APIKeyScanner {
2336 s := scan .NewAPIKeyScanner ()
@@ -66,7 +79,7 @@ func TestAPIKeyScanner_NeverStoresSecretValue(t *testing.T) {
6679}
6780
6881func TestAPIKeyScanner_EmptyEnvNoFindings (t * testing.T ) {
69- clearHighRiskEnv (t )
82+ clearAllEnv (t )
7083
7184 s := newScannerWithHome (t .TempDir ())
7285 result := s .Scan ()
@@ -131,7 +144,7 @@ func TestAPIKeyScanner_CredentialFileContentNotInFindings(t *testing.T) {
131144}
132145
133146func TestAPIKeyScanner_NoCredentialFileNoFinding (t * testing.T ) {
134- clearHighRiskEnv (t )
147+ clearAllEnv (t )
135148
136149 s := newScannerWithHome (t .TempDir ())
137150 result := s .Scan ()
You can’t perform that action at this time.
0 commit comments