From 4fa61f951c43366e2680cb2236fbbbb2c79dce6e Mon Sep 17 00:00:00 2001 From: Muneeb Ullah Khan Date: Tue, 24 Mar 2026 14:43:58 +0500 Subject: [PATCH 1/4] Added tests to ensure that custom endpoint configuration works in artifactory detectors --- .../artifactory_integration_test.go | 25 ++++++++++ pkg/detectors/artifactory/artifactory_test.go | 12 +++++ ...ifactoryreferencetoken_integration_test.go | 46 +++++++++++++++++++ .../artifactoryreferencetoken_test.go | 12 +++++ 4 files changed, 95 insertions(+) diff --git a/pkg/detectors/artifactory/artifactory_integration_test.go b/pkg/detectors/artifactory/artifactory_integration_test.go index a06a77828b3f..a23bf22e35df 100644 --- a/pkg/detectors/artifactory/artifactory_integration_test.go +++ b/pkg/detectors/artifactory/artifactory_integration_test.go @@ -7,6 +7,7 @@ import ( "context" "fmt" "testing" + "time" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" @@ -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{} diff --git a/pkg/detectors/artifactory/artifactory_test.go b/pkg/detectors/artifactory/artifactory_test.go index 6c9eed790353..a12e4c6b95a4 100644 --- a/pkg/detectors/artifactory/artifactory_test.go +++ b/pkg/detectors/artifactory/artifactory_test.go @@ -190,3 +190,15 @@ func TestArtifactory_Pattern(t *testing.T) { }) } } + +func TestArtifactory_Endpoint_Contains_CustomEndpoint(t *testing.T) { + appURL := "example.com" + s := Scanner{} + s.UseFoundEndpoints(true) + s.SetConfiguredEndpoints(appURL) + for _, ep := range s.Endpoints() { + if ep != appURL { + t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep) + } + } +} diff --git a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go index 2bb1daa226b7..b66617096db9 100644 --- a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go +++ b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go @@ -6,6 +6,7 @@ package artifactoryreferencetoken import ( "context" "fmt" + "strings" "testing" "time" @@ -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{} diff --git a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go index 39be5e0fabb8..adef0544f6a8 100644 --- a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go +++ b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go @@ -204,3 +204,15 @@ func TestArtifactoryReferenceToken_Pattern(t *testing.T) { }) } } + +func TestArtifactory_Endpoint_Contains_CustomEndpoint(t *testing.T) { + appURL := "example.com" + s := Scanner{} + s.UseFoundEndpoints(true) + s.SetConfiguredEndpoints(appURL) + for _, ep := range s.Endpoints() { + if ep != appURL { + t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep) + } + } +} From cd3120dd44aade0714a6951c2645d5046381b4ad Mon Sep 17 00:00:00 2001 From: Muneeb Ullah Khan Date: Tue, 24 Mar 2026 14:52:42 +0500 Subject: [PATCH 2/4] fix function name --- .../artifactoryreferencetoken/artifactoryreferencetoken_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go index adef0544f6a8..6165d6743ae2 100644 --- a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go +++ b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go @@ -205,7 +205,7 @@ func TestArtifactoryReferenceToken_Pattern(t *testing.T) { } } -func TestArtifactory_Endpoint_Contains_CustomEndpoint(t *testing.T) { +func TestArtifactoryreferencetoken_Endpoint_Contains_CustomEndpoint(t *testing.T) { appURL := "example.com" s := Scanner{} s.UseFoundEndpoints(true) From 025f36b1e5f86ddc12a844c3b379762bc5db9101 Mon Sep 17 00:00:00 2001 From: Muneeb Ullah Khan Date: Tue, 24 Mar 2026 15:01:01 +0500 Subject: [PATCH 3/4] fixed linter issues --- pkg/detectors/artifactory/artifactory_integration_test.go | 5 ++++- pkg/detectors/artifactory/artifactory_test.go | 5 ++++- .../artifactoryreferencetoken_integration_test.go | 5 ++++- .../artifactoryreferencetoken_test.go | 5 ++++- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/pkg/detectors/artifactory/artifactory_integration_test.go b/pkg/detectors/artifactory/artifactory_integration_test.go index a23bf22e35df..78813d5df3c1 100644 --- a/pkg/detectors/artifactory/artifactory_integration_test.go +++ b/pkg/detectors/artifactory/artifactory_integration_test.go @@ -105,7 +105,10 @@ func TestArtifactory_FromChunk_WithCustomEndpoint(t *testing.T) { s := Scanner{} s.UseFoundEndpoints(true) - s.SetConfiguredEndpoints(appURL) + err := s.SetConfiguredEndpoints(appURL) + if err != nil { + t.Fatal("Error in setting configured endpoint") + } data := []byte(fmt.Sprintf("You can find a artifactory secret %s ", mockSecret)) got, err := s.FromData(ctx, true, data) diff --git a/pkg/detectors/artifactory/artifactory_test.go b/pkg/detectors/artifactory/artifactory_test.go index a12e4c6b95a4..17c9a286d1da 100644 --- a/pkg/detectors/artifactory/artifactory_test.go +++ b/pkg/detectors/artifactory/artifactory_test.go @@ -195,7 +195,10 @@ func TestArtifactory_Endpoint_Contains_CustomEndpoint(t *testing.T) { appURL := "example.com" s := Scanner{} s.UseFoundEndpoints(true) - s.SetConfiguredEndpoints(appURL) + err := s.SetConfiguredEndpoints(appURL) + if err != nil { + t.Fatal("Error in setting configured endpoint") + } for _, ep := range s.Endpoints() { if ep != appURL { t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep) diff --git a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go index b66617096db9..f9460827ce02 100644 --- a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go +++ b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go @@ -162,7 +162,10 @@ func TestArtifactoryreferencetoken_FromChunk_WithCustomEndpoint(t *testing.T) { s := Scanner{} s.UseFoundEndpoints(true) - s.SetConfiguredEndpoints(instanceURL) + err = s.SetConfiguredEndpoints(instanceURL) + if err != nil { + t.Fatal("Error in setting configured endpoint") + } data := []byte(fmt.Sprintf("You can find a artifactory secret %s ", secret)) want := []detectors.Result{ { diff --git a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go index 6165d6743ae2..d2cdf75c5d8d 100644 --- a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go +++ b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go @@ -209,7 +209,10 @@ func TestArtifactoryreferencetoken_Endpoint_Contains_CustomEndpoint(t *testing.T appURL := "example.com" s := Scanner{} s.UseFoundEndpoints(true) - s.SetConfiguredEndpoints(appURL) + err := s.SetConfiguredEndpoints(appURL) + if err != nil { + t.Fatal("Error in setting configured endpoint") + } for _, ep := range s.Endpoints() { if ep != appURL { t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep) From 89069aee77b4b5062af3d991af357855c500b388 Mon Sep 17 00:00:00 2001 From: Muneeb Ullah Khan Date: Tue, 24 Mar 2026 15:05:58 +0500 Subject: [PATCH 4/4] fixed bugbot comments --- pkg/detectors/artifactory/artifactory_test.go | 6 +++++- .../artifactoryreferencetoken_integration_test.go | 3 +++ .../artifactoryreferencetoken_test.go | 6 +++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/detectors/artifactory/artifactory_test.go b/pkg/detectors/artifactory/artifactory_test.go index 17c9a286d1da..e3dced4ae879 100644 --- a/pkg/detectors/artifactory/artifactory_test.go +++ b/pkg/detectors/artifactory/artifactory_test.go @@ -199,7 +199,11 @@ func TestArtifactory_Endpoint_Contains_CustomEndpoint(t *testing.T) { if err != nil { t.Fatal("Error in setting configured endpoint") } - for _, ep := range s.Endpoints() { + configuredEndpoints := s.Endpoints() + if len(configuredEndpoints) == 0 { + t.Fatal("No Confiured endpoint found") + } + for _, ep := range configuredEndpoints { if ep != appURL { t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep) } diff --git a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go index f9460827ce02..675bd8460ca4 100644 --- a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go +++ b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_integration_test.go @@ -181,6 +181,9 @@ func TestArtifactoryreferencetoken_FromChunk_WithCustomEndpoint(t *testing.T) { if len(got) == 0 { t.Fatal("expected at least one result from FromData, got 0") } + if len(got) != len(want) { + t.Fatalf("expected %d results", len(want)) + } for i := range got { if len(got[i].RawV2) == 0 { t.Fatalf("no raw secret present: \n %+v", got[i]) diff --git a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go index d2cdf75c5d8d..ea80471cd2f1 100644 --- a/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go +++ b/pkg/detectors/artifactoryreferencetoken/artifactoryreferencetoken_test.go @@ -213,7 +213,11 @@ func TestArtifactoryreferencetoken_Endpoint_Contains_CustomEndpoint(t *testing.T if err != nil { t.Fatal("Error in setting configured endpoint") } - for _, ep := range s.Endpoints() { + configuredEndpoints := s.Endpoints() + if len(configuredEndpoints) == 0 { + t.Fatal("No Confiured endpoint found") + } + for _, ep := range configuredEndpoints { if ep != appURL { t.Fatalf("expected endpoint %s to be present in endpoints list, got %s", appURL, ep) }