Skip to content

Commit

Permalink
strings contain keyword check, add collection name to keywords
Browse files Browse the repository at this point in the history
  • Loading branch information
zricethezav committed Mar 21, 2024
1 parent b11ce72 commit 5e67ffc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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{}{}
}
}
}

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

0 comments on commit 5e67ffc

Please sign in to comment.