-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update/gcpapplicationdefaultcreds-detector
- Loading branch information
Showing
13 changed files
with
179 additions
and
471 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ import ( | |
var ( | ||
validPattern = "wdvn-usa87a-fxp9ioas/[email protected]" | ||
validSpecialCharPattern = "wdvn-usa87a-fxp9ioas / [email protected]" | ||
invalidPattern = "wdvn-usa87a-fxp9ioas/testUser$1005@example.com" | ||
invalidPattern = "wdvn-usa87a-fxp9ioasQQsstestUsQQ@example" | ||
) | ||
|
||
func TestAlegra_Pattern(t *testing.T) { | ||
|
@@ -28,30 +28,30 @@ func TestAlegra_Pattern(t *testing.T) { | |
}{ | ||
{ | ||
name: "valid pattern", | ||
input: fmt.Sprintf("alegra: '%s'", validPattern), | ||
want: []string{"wdvn-usa87a-fxp9ioastestUser[email protected]"}, | ||
input: fmt.Sprintf("alegra: %s", validPattern), | ||
want: []string{"wdvn-usa87a-fxp9ioas:wdvn-usa87a-fxp9ioas/testUser[email protected]"}, | ||
}, | ||
{ | ||
name: "valid pattern - with special characters", | ||
input: fmt.Sprintf("alegra: '%s'", validSpecialCharPattern), | ||
want: []string{"wdvn-usa87a-fxp9ioastest[email protected]"}, | ||
input: fmt.Sprintf("alegra: %s", validSpecialCharPattern), | ||
want: []string{"wdvn-usa87a-fxp9ioas:test[email protected]"}, | ||
}, | ||
{ | ||
name: "valid pattern - key out of prefix range", | ||
input: fmt.Sprintf("alegra keyword is not close to the real key and id = '%s'", validPattern), | ||
input: fmt.Sprintf("alegra keyword is not close to the real key and id = %s", validPattern), | ||
want: nil, | ||
}, | ||
{ | ||
name: "invalid pattern", | ||
input: fmt.Sprintf("alegra: '%s'", invalidPattern), | ||
input: fmt.Sprintf("alegra: %s", invalidPattern), | ||
want: nil, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
matchedDetectors := ahoCorasickCore.FindDetectorMatches([]byte(test.input)) | ||
if len(matchedDetectors) == 0 { | ||
if len(matchedDetectors) == 0 && test.want != nil { | ||
t.Errorf("keywords '%v' not matched by: %s", d.Keywords(), test.input) | ||
return | ||
} | ||
|
@@ -63,11 +63,7 @@ func TestAlegra_Pattern(t *testing.T) { | |
} | ||
|
||
if len(results) != len(test.want) { | ||
if len(results) == 0 { | ||
t.Errorf("did not receive result") | ||
} else { | ||
t.Errorf("expected %d results, only received %d", len(test.want), len(results)) | ||
} | ||
t.Errorf("expected %d results, got %d", len(test.want), len(results)) | ||
return | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.