From 1216fa23c9bce3af399d5966dc6c62645971aadb Mon Sep 17 00:00:00 2001 From: Zachary Rice Date: Thu, 21 Mar 2024 09:35:38 -0500 Subject: [PATCH] strings contain keyword check, add collection name to keywords (#2602) --- pkg/sources/postman/postman.go | 11 +++++++++++ pkg/sources/postman/substitution_test.go | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/sources/postman/postman.go b/pkg/sources/postman/postman.go index cde6b3bc4..d1b86a582 100644 --- a/pkg/sources/postman/postman.go +++ b/pkg/sources/postman/postman.go @@ -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{}{} + } } } @@ -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 diff --git a/pkg/sources/postman/substitution_test.go b/pkg/sources/postman/substitution_test.go index 7b24c53b8..234e93400 100644 --- a/pkg/sources/postman/substitution_test.go +++ b/pkg/sources/postman/substitution_test.go @@ -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)