Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions pkg/detectors/artifactory/artifactory_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
Expand Down Expand Up @@ -96,6 +97,30 @@ func TestArtifactory_FromChunk(t *testing.T) {
}
}

func TestArtifactory_FromChunk_WithCustomEndpoint(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
mockSecret := "AKCp5bueTFpfypEqQbGJPp7eHFi28fBivfWczrjbPb9erDff9LbXZbj6UsRExVXA8asWGc9fM"
appURL := "trufflesecurity.com"

s := Scanner{}
s.UseFoundEndpoints(true)
s.SetConfiguredEndpoints(appURL)
data := []byte(fmt.Sprintf("You can find a artifactory secret %s ", mockSecret))

got, err := s.FromData(ctx, true, data)
if err != nil {
t.Fatalf("unexpected error from FromData: %v", err)
}
if len(got) == 0 {
t.Fatal("expected at least one result from FromData, got 0")
}
expectedRawV2 := []byte(mockSecret + appURL)
if string(got[0].RawV2) != string(expectedRawV2) {
t.Errorf("Artifactory.FromData() rawV2 secret mismatch: got %s, want %s", string(got[0].RawV2), string(expectedRawV2))
}
}

func BenchmarkFromData(benchmark *testing.B) {
ctx := context.Background()
s := Scanner{}
Expand Down
12 changes: 12 additions & 0 deletions pkg/detectors/artifactory/artifactory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,15 @@
})
}
}

func TestArtifactory_Endpoint_Contains_CustomEndpoint(t *testing.T) {
appURL := "example.com"
s := Scanner{}
s.UseFoundEndpoints(true)
s.SetConfiguredEndpoints(appURL)

Check failure on line 198 in pkg/detectors/artifactory/artifactory_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `s.SetConfiguredEndpoints` is not checked (errcheck)
for _, ep := range s.Endpoints() {
if ep != appURL {
t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package artifactoryreferencetoken
import (
"context"
"fmt"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -148,6 +149,51 @@ func TestArtifactoryreferencetoken_FromChunk(t *testing.T) {
}
}

func TestArtifactoryreferencetoken_FromChunk_WithCustomEndpoint(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors6")
if err != nil {
t.Fatalf("could not get test secrets from GCP: %s", err)
}

instanceURL := testSecrets.MustGetField("ARTIFACTORY_URL")
secret := testSecrets.MustGetField("ARTIFACTORYREFERENCETOKEN")

s := Scanner{}
s.UseFoundEndpoints(true)
s.SetConfiguredEndpoints(instanceURL)
data := []byte(fmt.Sprintf("You can find a artifactory secret %s ", secret))
want := []detectors.Result{
{
DetectorType: detectorspb.DetectorType_ArtifactoryReferenceToken,
Verified: true,
RawV2: []byte(secret + strings.TrimPrefix(instanceURL, "https://")),
},
}
got, err := s.FromData(ctx, true, data)
if err != nil {
t.Fatalf("unexpected error from FromData: %v", err)
}
if len(got) == 0 {
t.Fatal("expected at least one result from FromData, got 0")
}
for i := range got {
if len(got[i].RawV2) == 0 {
t.Fatalf("no raw secret present: \n %+v", got[i])
}
if string(got[i].RawV2) != string(want[i].RawV2) {
t.Fatalf("expected rawV2 to be %s, got %s", string(want[i].RawV2), string(got[i].RawV2))
}
}

ignoreOpts := cmpopts.IgnoreFields(detectors.Result{}, "Raw", "RawV2", "verificationError", "primarySecret", "AnalysisInfo")
if diff := cmp.Diff(got, want, ignoreOpts); diff != "" {
t.Errorf("Artifactoryreferencetoken.FromData() diff: (-got +want)\n%s", diff)
}

}

func BenchmarkFromData(benchmark *testing.B) {
ctx := context.Background()
s := Scanner{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,15 @@
})
}
}

func TestArtifactoryreferencetoken_Endpoint_Contains_CustomEndpoint(t *testing.T) {
appURL := "example.com"
s := Scanner{}
s.UseFoundEndpoints(true)
s.SetConfiguredEndpoints(appURL)

Check failure on line 212 in pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go

View workflow job for this annotation

GitHub Actions / golangci-lint

Error return value of `s.SetConfiguredEndpoints` is not checked (errcheck)
for _, ep := range s.Endpoints() {
if ep != appURL {
t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep)
}
}
}
Loading