From 754f7c0e9aebe3be5aa58ad1de1e235d4c89cf38 Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Fri, 20 Dec 2024 17:45:42 +0500 Subject: [PATCH 1/4] ignore extraData and analysisInfo in mailchimp integration test. --- pkg/detectors/mailchimp/mailchimp_integration_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pkg/detectors/mailchimp/mailchimp_integration_test.go b/pkg/detectors/mailchimp/mailchimp_integration_test.go index c181fd5674da..73f7d26219a9 100644 --- a/pkg/detectors/mailchimp/mailchimp_integration_test.go +++ b/pkg/detectors/mailchimp/mailchimp_integration_test.go @@ -9,7 +9,8 @@ import ( "testing" "time" - "github.com/kylelemons/godebug/pretty" + "github.com/google/go-cmp/cmp" + "github.com/google/go-cmp/cmp/cmpopts" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" @@ -95,7 +96,9 @@ func TestMailchimp_FromChunk(t *testing.T) { got[i].Raw = nil got[i].AnalysisInfo = nil } - if diff := pretty.Compare(got, tt.want); diff != "" { + + ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "AnalysisInfo", "ExtraData") + if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" { t.Errorf("Mailchimp.FromData() %s diff: (-got +want)\n%s", tt.name, diff) } }) From b006ece0f9e3472e5a2cd728b2282902f1e66d59 Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Fri, 20 Dec 2024 17:51:18 +0500 Subject: [PATCH 2/4] Ignore ExtraData in Mailchimp and Mailgun integration test. --- pkg/detectors/mailchimp/mailchimp_integration_test.go | 8 +++----- pkg/detectors/mailgun/mailgun_integration_test.go | 1 + 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/pkg/detectors/mailchimp/mailchimp_integration_test.go b/pkg/detectors/mailchimp/mailchimp_integration_test.go index 73f7d26219a9..d524439ef7f9 100644 --- a/pkg/detectors/mailchimp/mailchimp_integration_test.go +++ b/pkg/detectors/mailchimp/mailchimp_integration_test.go @@ -9,8 +9,7 @@ import ( "testing" "time" - "github.com/google/go-cmp/cmp" - "github.com/google/go-cmp/cmp/cmpopts" + "github.com/kylelemons/godebug/pretty" "github.com/trufflesecurity/trufflehog/v3/pkg/common" "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" @@ -95,10 +94,9 @@ func TestMailchimp_FromChunk(t *testing.T) { } got[i].Raw = nil got[i].AnalysisInfo = nil + got[i].ExtraData = nil } - - ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "AnalysisInfo", "ExtraData") - if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" { + if diff := pretty.Compare(got, tt.want); diff != "" { t.Errorf("Mailchimp.FromData() %s diff: (-got +want)\n%s", tt.name, diff) } }) diff --git a/pkg/detectors/mailgun/mailgun_integration_test.go b/pkg/detectors/mailgun/mailgun_integration_test.go index 0b887ce2c37e..65f7934ec377 100644 --- a/pkg/detectors/mailgun/mailgun_integration_test.go +++ b/pkg/detectors/mailgun/mailgun_integration_test.go @@ -130,6 +130,7 @@ func TestMailgun_FromChunk(t *testing.T) { } got[i].Raw = nil got[i].AnalysisInfo = nil + got[i].ExtraData = nil } if diff := pretty.Compare(got, tt.want); diff != "" { t.Errorf("Mailgun.FromData() %s diff: (-got +want)\n%s", tt.name, diff) From dbeee1cb105b3a198dac39e404a7d540fa3896d9 Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Fri, 20 Dec 2024 18:05:23 +0500 Subject: [PATCH 3/4] Exclude RawV2 values from integration test of mux detector. --- .../mattermostpersonaltoken_integration_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go b/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go index b1db37b782a1..ed6702e8d270 100644 --- a/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go +++ b/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go @@ -51,6 +51,7 @@ func TestMattermostPersonalToken_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_MattermostPersonalToken, Verified: true, + RawV2: []byte(secret + server), }, }, wantErr: false, @@ -60,13 +61,14 @@ func TestMattermostPersonalToken_FromChunk(t *testing.T) { s: Scanner{}, args: args{ ctx: context.Background(), - data: []byte(fmt.Sprintf("You can find a mattermost secret %s within mattermost server %s but not valid", inactiveSecret, "test323561.cloud.mattermost.com")), // the secret would satisfy the regex but not pass validation + data: []byte(fmt.Sprintf("You can find a mattermost secret %s within mattermost server %s but not valid", inactiveSecret, server)), // the secret would satisfy the regex but not pass validation verify: true, }, want: []detectors.Result{ { DetectorType: detectorspb.DetectorType_MattermostPersonalToken, Verified: false, + RawV2: []byte(inactiveSecret + server), }, }, wantErr: false, From c65aa7eb0fb003b906c52d03518eabc260d7af59 Mon Sep 17 00:00:00 2001 From: Abdul Basit Date: Fri, 20 Dec 2024 18:10:27 +0500 Subject: [PATCH 4/4] Exclude RawV2 values from integration test of mux detector. --- .../mattermostpersonaltoken_integration_test.go | 7 +++++-- pkg/detectors/mux/mux_integration_test.go | 5 +++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go b/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go index ed6702e8d270..26b9605619d0 100644 --- a/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go +++ b/pkg/detectors/mattermostpersonaltoken/mattermostpersonaltoken_integration_test.go @@ -51,7 +51,6 @@ func TestMattermostPersonalToken_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_MattermostPersonalToken, Verified: true, - RawV2: []byte(secret + server), }, }, wantErr: false, @@ -68,7 +67,6 @@ func TestMattermostPersonalToken_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_MattermostPersonalToken, Verified: false, - RawV2: []byte(inactiveSecret + server), }, }, wantErr: false, @@ -98,6 +96,11 @@ func TestMattermostPersonalToken_FromChunk(t *testing.T) { t.Fatalf("no raw secret present: \n %+v", got[i]) } got[i].Raw = nil + + if len(got[i].RawV2) == 0 { + t.Fatalf("no RawV2 secret present: \n %+v", got[i]) + } + got[i].RawV2 = nil } if diff := pretty.Compare(got, tt.want); diff != "" { t.Errorf("MattermostPersonalToken.FromData() %s diff: (-got +want)\n%s", tt.name, diff) diff --git a/pkg/detectors/mux/mux_integration_test.go b/pkg/detectors/mux/mux_integration_test.go index 871b44a7a35d..ec8427b86542 100644 --- a/pkg/detectors/mux/mux_integration_test.go +++ b/pkg/detectors/mux/mux_integration_test.go @@ -97,6 +97,11 @@ func TestMux_FromChunk(t *testing.T) { t.Fatalf("no raw secret present: \n %+v", got[i]) } got[i].Raw = nil + + if len(got[i].RawV2) == 0 { + t.Fatalf("no rawv2 secret present: \n %+v", got[i]) + } + got[i].RawV2 = nil } if diff := pretty.Compare(got, tt.want); diff != "" { t.Errorf("Mux.FromData() %s diff: (-got +want)\n%s", tt.name, diff)