update azure test files to check rawV2 (#2353)

This commit is contained in:
roxanne-tampus 2024-02-01 00:36:52 +08:00 committed by GitHub
parent 24d0680f5c
commit 143e275272
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 41 additions and 13 deletions

View file

@ -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)
}

View file

@ -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)
}
})
}

View file

@ -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)
}
})
}

View file

@ -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)
}
})
}