Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand keyword checks, and add collection name to keyword #2602

Merged
merged 1 commit into from Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/sources/postman/postman.go
Expand Up @@ -60,8 +60,18 @@ func (s *Source) addKeywords(keywords []string) {
}

func (s *Source) addKeyword(keyword string) {
// fast check
if _, ok := s.DetectorKeywords[keyword]; ok {
s.keywords[keyword] = struct{}{}
return
}

// slow check. This is to handle the case where the keyword is a substring of a detector keyword
// e.g. "datadog-token" is a variable key in postman, but "datadog" is a detector keyword
for k := range s.DetectorKeywords {
if strings.Contains(keyword, k) {
s.keywords[k] = struct{}{}
joeleonjr marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

Expand Down Expand Up @@ -325,6 +335,7 @@ func (s *Source) scanCollection(ctx context.Context, chunksChan chan *sources.Ch
ctx.Logger().V(2).Info("starting scanning collection", collection.Info.Name, "uuid", collection.Info.UID)
metadata.CollectionInfo = collection.Info
metadata.Type = COLLECTION_TYPE
s.addKeyword(collection.Info.Name)

if !metadata.fromLocal {
metadata.FullID = metadata.CollectionInfo.UID
Expand Down
1 change: 0 additions & 1 deletion pkg/sources/postman/substitution_test.go
Expand Up @@ -145,7 +145,6 @@ func TestSource_FormatAndInjectKeywords(t *testing.T) {
expected := strings.Split(tc.expected, "\n")
sort.Strings(got)
sort.Strings(expected)
// CHATGPT CHECK HERE

if !reflect.DeepEqual(got, expected) {
t.Errorf("Expected result: %q, got: %q", tc.expected, result)
Expand Down