Skip to content

Commit

Permalink
update azure test files to check rawV2 (#2353)
Browse files Browse the repository at this point in the history
  • Loading branch information
roxanne-tampus authored Jan 31, 2024
1 parent 24d0680 commit 143e275
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken,
Verified: true,
RawV2: []byte(secret + org),
},
},
wantErr: false,
Expand All @@ -71,6 +72,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken,
Verified: false,
RawV2: []byte(inactiveSecret + org),
},
},
wantErr: false,
Expand Down Expand Up @@ -100,6 +102,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken,
Verified: false,
RawV2: []byte(secret + org),
},
},
wantErr: false,
Expand All @@ -117,6 +120,7 @@ func TestAzureDevopsPersonalAccessToken_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureDevopsPersonalAccessToken,
Verified: false,
RawV2: []byte(secret + org),
},
},
wantErr: false,
Expand All @@ -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)
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/detectors/azurefunctionkey/azurefunctionkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -54,6 +54,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureFunctionKey,
Verified: true,
RawV2: []byte(secret + url),
},
},
wantErr: false,
Expand All @@ -71,6 +72,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureFunctionKey,
Verified: false,
RawV2: []byte(inactiveSecret + url),
},
},
wantErr: false,
Expand Down Expand Up @@ -100,6 +102,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureFunctionKey,
Verified: false,
RawV2: []byte(secret + url),
},
},
wantErr: false,
Expand All @@ -117,6 +120,7 @@ func TestAzurefunctionkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureFunctionKey,
Verified: false,
RawV2: []byte(secret + url),
},
},
wantErr: false,
Expand All @@ -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)
}
})
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/detectors/azuresearchadminkey/azuresearchadminkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -54,6 +54,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchAdminKey,
Verified: true,
RawV2: []byte(secret + service),
},
},
wantErr: false,
Expand All @@ -71,6 +72,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchAdminKey,
Verified: false,
RawV2: []byte(inactiveSecret + service),
},
},
wantErr: false,
Expand Down Expand Up @@ -100,6 +102,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchAdminKey,
Verified: false,
RawV2: []byte(secret + service),
},
},
wantErr: false,
Expand All @@ -117,6 +120,7 @@ func TestAzuresearchadminkey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchAdminKey,
Verified: false,
RawV2: []byte(secret + service),
},
},
wantErr: false,
Expand All @@ -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)
}
})
}
Expand Down
15 changes: 11 additions & 4 deletions pkg/detectors/azuresearchquerykey/azuresearchquerykey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -54,6 +54,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchQueryKey,
Verified: true,
RawV2: []byte(secret + url),
},
},
wantErr: false,
Expand All @@ -71,6 +72,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchQueryKey,
Verified: false,
RawV2: []byte(inactiveSecret + url),
},
},
wantErr: false,
Expand Down Expand Up @@ -100,6 +102,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchQueryKey,
Verified: false,
RawV2: []byte(secret + url),
},
},
wantErr: false,
Expand All @@ -117,6 +120,7 @@ func TestAzuresearchquerykey_FromChunk(t *testing.T) {
{
DetectorType: detectorspb.DetectorType_AzureSearchQueryKey,
Verified: false,
RawV2: []byte(secret + url),
},
},
wantErr: false,
Expand All @@ -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)
}
})
}
Expand Down

0 comments on commit 143e275

Please sign in to comment.