From 143e275272680a39c85c8f976f0677239e7aa432 Mon Sep 17 00:00:00 2001 From: roxanne-tampus <51393035+roxanne-tampus@users.noreply.github.com> Date: Thu, 1 Feb 2024 00:36:52 +0800 Subject: [PATCH] update azure test files to check rawV2 (#2353) --- .../azuredevopspersonalaccesstoken_test.go | 9 ++++++++- .../azurefunctionkey/azurefunctionkey_test.go | 15 +++++++++++---- .../azuresearchadminkey_test.go | 15 +++++++++++---- .../azuresearchquerykey_test.go | 15 +++++++++++---- 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken_test.go b/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken_test.go index f4c82babe6c0..2b7c68f3fd67 100644 --- a/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken_test.go +++ b/pkg/detectors/azuredevopspersonalaccesstoken/azuredevopspersonalaccesstoken_test.go @@ -54,6 +54,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken, Verified: true, + RawV2: []byte(secret + org), }, }, wantErr: false, @@ -71,6 +72,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken, Verified: false, + RawV2: []byte(inactiveSecret + org), }, }, wantErr: false, @@ -100,6 +102,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken, Verified: false, + RawV2: []byte(secret + org), }, }, wantErr: false, @@ -117,6 +120,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken, Verified: false, + RawV2: []byte(secret + org), }, }, wantErr: false, @@ -134,11 +138,14 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) { if len(got[i].Raw) == 0 { t.Fatalf("no raw secret present: \n %+v", got[i]) } + if len(got[i].RawV2) == 0 { + t.Fatalf("no rawV2 secret present: \n %+v", got[i]) + } if (got[i].VerificationError() != nil) != tt.wantVerificationErr { t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError()) } } - ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError") + ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "RawV2", "verificationError") if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" { t.Errorf("AzureDevopsPersonalAccessToken.FromData() %s diff: (-got +want)\n%s", tt.name, diff) } diff --git a/pkg/detectors/azurefunctionkey/azurefunctionkey_test.go b/pkg/detectors/azurefunctionkey/azurefunctionkey_test.go index 564fe1ed94f3..2d9881ed72fa 100644 --- a/pkg/detectors/azurefunctionkey/azurefunctionkey_test.go +++ b/pkg/detectors/azurefunctionkey/azurefunctionkey_test.go @@ -18,7 +18,7 @@ import ( "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) -func TestAzurefunctionkey_FromChunk(t *testing.T) { +func TestAzureFunctionKey_FromChunk(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors5") @@ -54,6 +54,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureFunctionKey, Verified: true, + RawV2: []byte(secret + url), }, }, wantErr: false, @@ -71,6 +72,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureFunctionKey, Verified: false, + RawV2: []byte(inactiveSecret + url), }, }, wantErr: false, @@ -100,6 +102,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureFunctionKey, Verified: false, + RawV2: []byte(secret + url), }, }, wantErr: false, @@ -117,6 +120,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureFunctionKey, Verified: false, + RawV2: []byte(secret + url), }, }, wantErr: false, @@ -127,20 +131,23 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.s.FromData(tt.args.ctx, tt.args.verify, tt.args.data) if (err != nil) != tt.wantErr { - t.Errorf("Azurefunctionkey.FromData() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("AzureFunctionKey.FromData() error = %v, wantErr %v", err, tt.wantErr) return } for i := range got { if len(got[i].Raw) == 0 { t.Fatalf("no raw secret present: \n %+v", got[i]) } + if len(got[i].RawV2) == 0 { + t.Fatalf("no rawV2 secret present: \n %+v", got[i]) + } if (got[i].VerificationError() != nil) != tt.wantVerificationErr { t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError()) } } - ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError") + ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "RawV2", "verificationError") if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" { - t.Errorf("Azurefunctionkey.FromData() %s diff: (-got +want)\n%s", tt.name, diff) + t.Errorf("AzureFunctionKey.FromData() %s diff: (-got +want)\n%s", tt.name, diff) } }) } diff --git a/pkg/detectors/azuresearchadminkey/azuresearchadminkey_test.go b/pkg/detectors/azuresearchadminkey/azuresearchadminkey_test.go index e6b2a4d7c1d5..c59e16ceede9 100644 --- a/pkg/detectors/azuresearchadminkey/azuresearchadminkey_test.go +++ b/pkg/detectors/azuresearchadminkey/azuresearchadminkey_test.go @@ -18,7 +18,7 @@ import ( "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) -func TestAzuresearchadminkey_FromChunk(t *testing.T) { +func TestAzureSearchAdminKey_FromChunk(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors5") @@ -54,6 +54,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchAdminKey, Verified: true, + RawV2: []byte(secret + service), }, }, wantErr: false, @@ -71,6 +72,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchAdminKey, Verified: false, + RawV2: []byte(inactiveSecret + service), }, }, wantErr: false, @@ -100,6 +102,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchAdminKey, Verified: false, + RawV2: []byte(secret + service), }, }, wantErr: false, @@ -117,6 +120,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchAdminKey, Verified: false, + RawV2: []byte(secret + service), }, }, wantErr: false, @@ -127,20 +131,23 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.s.FromData(tt.args.ctx, tt.args.verify, tt.args.data) if (err != nil) != tt.wantErr { - t.Errorf("Azuresearchadminkey.FromData() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("AzureSearchAdminKey.FromData() error = %v, wantErr %v", err, tt.wantErr) return } for i := range got { if len(got[i].Raw) == 0 { t.Fatalf("no raw secret present: \n %+v", got[i]) } + if len(got[i].RawV2) == 0 { + t.Fatalf("no rawV2 secret present: \n %+v", got[i]) + } if (got[i].VerificationError() != nil) != tt.wantVerificationErr { t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError()) } } - ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError") + ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "RawV2", "verificationError") if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" { - t.Errorf("Azuresearchadminkey.FromData() %s diff: (-got +want)\n%s", tt.name, diff) + t.Errorf("AzureSearchAdminKey.FromData() %s diff: (-got +want)\n%s", tt.name, diff) } }) } diff --git a/pkg/detectors/azuresearchquerykey/azuresearchquerykey_test.go b/pkg/detectors/azuresearchquerykey/azuresearchquerykey_test.go index ef1db4b82490..1967a9b971aa 100644 --- a/pkg/detectors/azuresearchquerykey/azuresearchquerykey_test.go +++ b/pkg/detectors/azuresearchquerykey/azuresearchquerykey_test.go @@ -18,7 +18,7 @@ import ( "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) -func TestAzuresearchquerykey_FromChunk(t *testing.T) { +func TestAzureSearchQueryKey_FromChunk(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors5") @@ -54,6 +54,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchQueryKey, Verified: true, + RawV2: []byte(secret + url), }, }, wantErr: false, @@ -71,6 +72,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchQueryKey, Verified: false, + RawV2: []byte(inactiveSecret + url), }, }, wantErr: false, @@ -100,6 +102,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchQueryKey, Verified: false, + RawV2: []byte(secret + url), }, }, wantErr: false, @@ -117,6 +120,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) { { DetectorType: detectorspb.DetectorType_AzureSearchQueryKey, Verified: false, + RawV2: []byte(secret + url), }, }, wantErr: false, @@ -127,20 +131,23 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) { t.Run(tt.name, func(t *testing.T) { got, err := tt.s.FromData(tt.args.ctx, tt.args.verify, tt.args.data) if (err != nil) != tt.wantErr { - t.Errorf("Azuresearchquerykey.FromData() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("AzureSearchQueryKey.FromData() error = %v, wantErr %v", err, tt.wantErr) return } for i := range got { if len(got[i].Raw) == 0 { t.Fatalf("no raw secret present: \n %+v", got[i]) } + if len(got[i].RawV2) == 0 { + t.Fatalf("no rawV2 secret present: \n %+v", got[i]) + } if (got[i].VerificationError() != nil) != tt.wantVerificationErr { t.Fatalf("wantVerificationError = %v, verification error = %v", tt.wantVerificationErr, got[i].VerificationError()) } } - ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "verificationError") + ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "RawV2", "verificationError") if diff := cmp.Diff(got, tt.want, ignoreOpts); diff != "" { - t.Errorf("Azuresearchquerykey.FromData() %s diff: (-got +want)\n%s", tt.name, diff) + t.Errorf("AzureSearchQueryKey.FromData() %s diff: (-got +want)\n%s", tt.name, diff) } }) }