From f7da4880c7a1b43acac6a2d111b401dc14525cd7 Mon Sep 17 00:00:00 2001 From: Richard Gomez Date: Thu, 12 Dec 2024 17:18:54 -0500 Subject: [PATCH] chore: run unit tests --- Makefile | 8 ++++---- pkg/detectors/aws/access_keys/accesskey_test.go | 2 +- pkg/detectors/gcp/gcp_test.go | 14 +++++++------- pkg/detectors/hubspot_apikey/v1/apikey_test.go | 4 ++-- .../kanbantool/kanbantool_integration_test.go | 3 +++ pkg/detectors/lemlist/lemlist_integration_test.go | 4 ++++ pkg/detectors/meraki/meraki_integration_test.go | 3 +++ .../monkeylearn/monkeylearn_integration_test.go | 5 ++++- .../opsgenie/opsgenie_integration_test.go | 5 ++++- .../privatekey/{ssh.go => ssh_integration.go} | 0 .../{ssh_test.go => ssh_integration_test.go} | 3 +++ pkg/detectors/prodpad/prodpad_integration_test.go | 5 ++++- .../salesmate/salesmate_integration_test.go | 3 +++ pkg/detectors/scalr/scalr_integration_test.go | 3 +++ pkg/detectors/shopify/shopify_integration_test.go | 3 +++ pkg/detectors/tokeet/tokeet_integration_test.go | 5 ++++- .../transferwise/transferwise_integration_test.go | 5 ++++- pkg/detectors/twist/twist_integration_test.go | 5 ++++- .../websitepulse/websitepulse_integration_test.go | 3 +++ 19 files changed, 63 insertions(+), 20 deletions(-) rename pkg/detectors/privatekey/{ssh.go => ssh_integration.go} (100%) rename pkg/detectors/privatekey/{ssh_test.go => ssh_integration_test.go} (95%) diff --git a/Makefile b/Makefile index c2dd418694c2..b0c875900bb1 100644 --- a/Makefile +++ b/Makefile @@ -28,19 +28,19 @@ test-failing: CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/) | grep FAIL test: - CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/ | grep -v pkg/detectors) + CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/) test-integration: - CGO_ENABLED=0 go test -timeout=5m -tags=integration $(shell go list ./... | grep -v /vendor/ | grep -v pkg/detectors) + CGO_ENABLED=0 go test -timeout=5m -tags=integration $(shell go list ./... | grep -v /vendor/) test-race: - CGO_ENABLED=1 go test -timeout=5m -race $(shell go list ./... | grep -v /vendor/ | grep -v pkg/detectors) + CGO_ENABLED=1 go test -timeout=5m -race $(shell go list ./... | grep -v /vendor/) test-detectors: CGO_ENABLED=0 go test -tags=detectors -timeout=5m $(shell go list ./... | grep pkg/detectors) test-community: - CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/ | grep -v pkg/detectors | grep -v pkg/sources | grep -v pkg/analyzer/analyzers) + CGO_ENABLED=0 go test -timeout=5m $(shell go list ./... | grep -v /vendor/ | grep -v pkg/sources | grep -v pkg/analyzer/analyzers) bench: CGO_ENABLED=0 go test $(shell go list ./pkg/secrets/... | grep -v /vendor/) -benchmem -run=xxx -bench . diff --git a/pkg/detectors/aws/access_keys/accesskey_test.go b/pkg/detectors/aws/access_keys/accesskey_test.go index 2276958562ae..96c44b2fb6b1 100644 --- a/pkg/detectors/aws/access_keys/accesskey_test.go +++ b/pkg/detectors/aws/access_keys/accesskey_test.go @@ -37,7 +37,7 @@ func TestAWS_Pattern(t *testing.T) { { name: "valid pattern", input: validPattern, - want: []string{"ABIAS9L8MS5IPHTZPPUQv2QPKHl7LcdVYsjaR4LgQiZ1zw3MAnMyiondXC63"}, + want: []string{"ABIAS9L8MS5IPHTZPPUQ:v2QPKHl7LcdVYsjaR4LgQiZ1zw3MAnMyiondXC63"}, }, { name: "invalid pattern", diff --git a/pkg/detectors/gcp/gcp_test.go b/pkg/detectors/gcp/gcp_test.go index 3b9d1129f9d8..0c392cb0a2c6 100644 --- a/pkg/detectors/gcp/gcp_test.go +++ b/pkg/detectors/gcp/gcp_test.go @@ -67,7 +67,7 @@ func TestGCP_Pattern(t *testing.T) { { name: "escaped JSON", input: `{"credentials":"{\n \"type\": \"service_account\",\n \"project_id\": \"unit-test\",\n \"private_key_id\": \"10f922eb17fba903dc59f7baf753976233520012\",\n \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCgyAZHbtJu1MRf\\ng9+Wg==\\n-----END PRIVATE KEY-----\\n\",\n \"client_email\": \"fake-value@unit-test.iam.gserviceaccount.com\",\n \"client_id\": \"123456476766156356779\",\n \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n \"token_uri\": \"https://oauth2.googleapis.com/token\",\n \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n \"client_x509_cert_url\": \"https://www.googleapis.com/robot/v1/metadata/x509/fake-value%40unit-test.iam.gserviceaccount.com\"\n}\n"}`, - want: []string{"{\"type\":\"service_account\",\"project_id\":\"unit-test\",\"private_key_id\":\"10f922eb17fba903dc59f7baf753976233520012\",\"private_key\":\"-----BEGIN PRIVATE KEY-----\\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCgyAZHbtJu1MRf\\ng9+Wg==\\n-----END PRIVATE KEY-----\\n\",\"client_email\":\"fake-value@unit-test.iam.gserviceaccount.com\",\"client_id\":\"123456476766156356779\",\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"token_uri\":\"https://oauth2.googleapis.com/token\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\",\"client_x509_cert_url\":\"https://www.googleapis.com/robot/v1/metadata/x509/fake-value%40unit-test.iam.gserviceaccount.com\"}g"}, + want: []string{"{\"type\":\"service_account\",\"project_id\":\"unit-test\",\"private_key_id\":\"10f922eb17fba903dc59f7baf753976233520012\",\"private_key\":\"-----BEGIN PRIVATE KEY-----\\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCgyAZHbtJu1MRf\\ng9+Wg==\\n-----END PRIVATE KEY-----\\n\",\"client_email\":\"fake-value@unit-test.iam.gserviceaccount.com\",\"client_id\":\"123456476766156356779\",\"auth_uri\":\"https://accounts.google.com/o/oauth2/auth\",\"token_uri\":\"https://oauth2.googleapis.com/token\",\"auth_provider_x509_cert_url\":\"https://www.googleapis.com/oauth2/v1/certs\",\"client_x509_cert_url\":\"https://www.googleapis.com/robot/v1/metadata/x509/fake-value%40unit-test.iam.gserviceaccount.com\"}"}, }, { name: "no private_key_id (1)", @@ -103,21 +103,21 @@ GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEvAIBADANBgk skip: true, }, // TODO: Create an example of these. - //{ + // { // name: "Slack mangled email", // input: ``, // want: []string{""}, - //}, - //{ + // }, + // { // name: "Empty client email", // input: ``, // want: []string{""}, - //}, - //{ + // }, + // { // name: "Carets", // input: ``, // want: []string{""}, - //}, + // }, } for _, test := range tests { diff --git a/pkg/detectors/hubspot_apikey/v1/apikey_test.go b/pkg/detectors/hubspot_apikey/v1/apikey_test.go index 30273e3408a0..51dfb09e3a7b 100644 --- a/pkg/detectors/hubspot_apikey/v1/apikey_test.go +++ b/pkg/detectors/hubspot_apikey/v1/apikey_test.go @@ -29,7 +29,7 @@ const hs = new HubSpotAPI({ hapikey: HAPI_KEY });`, // { // name: "hubapi", // input: `curl https://api.hubapi.com/contacts/v1/lists/all/contacts/all \ - //--header "Authorization: Bearer b71aa2ed-9c76-417d-bd8e-c5f4980d21ef"`, + // --header "Authorization: Bearer b71aa2ed-9c76-417d-bd8e-c5f4980d21ef"`, // want: []string{"b71aa2ed-9c76-417d-bd8e-c5f4980d21ef"}, // }, { @@ -61,7 +61,7 @@ const blogPosts = hs.blog.getPosts({ name: 'Inbound' });`, "method": "GET", "deprecated": false }]`, - want: []string{""}, + want: []string{"hDNxPGyQ-AOMZ-w9Sp-aw5t-TwKLBQjQ85go"}, }, } diff --git a/pkg/detectors/kanbantool/kanbantool_integration_test.go b/pkg/detectors/kanbantool/kanbantool_integration_test.go index 12afd2958f87..9562cad657dd 100644 --- a/pkg/detectors/kanbantool/kanbantool_integration_test.go +++ b/pkg/detectors/kanbantool/kanbantool_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package kanbantool import ( diff --git a/pkg/detectors/lemlist/lemlist_integration_test.go b/pkg/detectors/lemlist/lemlist_integration_test.go index 772dfb0135fd..e8a0fdecb743 100644 --- a/pkg/detectors/lemlist/lemlist_integration_test.go +++ b/pkg/detectors/lemlist/lemlist_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package lemlist import ( @@ -7,6 +10,7 @@ import ( "time" "github.com/kylelemons/godebug/pretty" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/common" diff --git a/pkg/detectors/meraki/meraki_integration_test.go b/pkg/detectors/meraki/meraki_integration_test.go index 030a9dfcf8ee..3f6fb92e8d74 100644 --- a/pkg/detectors/meraki/meraki_integration_test.go +++ b/pkg/detectors/meraki/meraki_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package meraki import ( diff --git a/pkg/detectors/monkeylearn/monkeylearn_integration_test.go b/pkg/detectors/monkeylearn/monkeylearn_integration_test.go index d846f5862594..95083c2269af 100644 --- a/pkg/detectors/monkeylearn/monkeylearn_integration_test.go +++ b/pkg/detectors/monkeylearn/monkeylearn_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package monkeylearn import ( @@ -7,9 +10,9 @@ import ( "time" "github.com/kylelemons/godebug/pretty" - "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/common" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) diff --git a/pkg/detectors/opsgenie/opsgenie_integration_test.go b/pkg/detectors/opsgenie/opsgenie_integration_test.go index 31d5b834b2ac..b480195767a9 100644 --- a/pkg/detectors/opsgenie/opsgenie_integration_test.go +++ b/pkg/detectors/opsgenie/opsgenie_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package opsgenie import ( @@ -7,9 +10,9 @@ import ( "time" "github.com/kylelemons/godebug/pretty" - "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/common" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) diff --git a/pkg/detectors/privatekey/ssh.go b/pkg/detectors/privatekey/ssh_integration.go similarity index 100% rename from pkg/detectors/privatekey/ssh.go rename to pkg/detectors/privatekey/ssh_integration.go diff --git a/pkg/detectors/privatekey/ssh_test.go b/pkg/detectors/privatekey/ssh_integration_test.go similarity index 95% rename from pkg/detectors/privatekey/ssh_test.go rename to pkg/detectors/privatekey/ssh_integration_test.go index bd90968b4036..f77e1b31fbc4 100644 --- a/pkg/detectors/privatekey/ssh_test.go +++ b/pkg/detectors/privatekey/ssh_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package privatekey import ( diff --git a/pkg/detectors/prodpad/prodpad_integration_test.go b/pkg/detectors/prodpad/prodpad_integration_test.go index 80fd2a5e734c..d17a8632f152 100644 --- a/pkg/detectors/prodpad/prodpad_integration_test.go +++ b/pkg/detectors/prodpad/prodpad_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package prodpad import ( @@ -7,9 +10,9 @@ import ( "time" "github.com/kylelemons/godebug/pretty" - "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/common" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) diff --git a/pkg/detectors/salesmate/salesmate_integration_test.go b/pkg/detectors/salesmate/salesmate_integration_test.go index c1bc3d34190f..68f1b032253c 100644 --- a/pkg/detectors/salesmate/salesmate_integration_test.go +++ b/pkg/detectors/salesmate/salesmate_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package salesmate import ( diff --git a/pkg/detectors/scalr/scalr_integration_test.go b/pkg/detectors/scalr/scalr_integration_test.go index e1103d10fa4e..404cbeca5a7c 100644 --- a/pkg/detectors/scalr/scalr_integration_test.go +++ b/pkg/detectors/scalr/scalr_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package scalr import ( diff --git a/pkg/detectors/shopify/shopify_integration_test.go b/pkg/detectors/shopify/shopify_integration_test.go index 0b811f3c9bc9..4282cd67d1b9 100644 --- a/pkg/detectors/shopify/shopify_integration_test.go +++ b/pkg/detectors/shopify/shopify_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package shopify import ( diff --git a/pkg/detectors/tokeet/tokeet_integration_test.go b/pkg/detectors/tokeet/tokeet_integration_test.go index 0b8ce70f3b40..a0f5254c0739 100644 --- a/pkg/detectors/tokeet/tokeet_integration_test.go +++ b/pkg/detectors/tokeet/tokeet_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package tokeet import ( @@ -7,9 +10,9 @@ import ( "time" "github.com/kylelemons/godebug/pretty" - "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/common" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) diff --git a/pkg/detectors/transferwise/transferwise_integration_test.go b/pkg/detectors/transferwise/transferwise_integration_test.go index 4c0cb0a9e056..fd833fae22fa 100644 --- a/pkg/detectors/transferwise/transferwise_integration_test.go +++ b/pkg/detectors/transferwise/transferwise_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package transferwise import ( @@ -7,9 +10,9 @@ import ( "time" "github.com/kylelemons/godebug/pretty" - "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/common" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) diff --git a/pkg/detectors/twist/twist_integration_test.go b/pkg/detectors/twist/twist_integration_test.go index 88027608c823..ff3fc753858d 100644 --- a/pkg/detectors/twist/twist_integration_test.go +++ b/pkg/detectors/twist/twist_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package twist import ( @@ -7,9 +10,9 @@ import ( "time" "github.com/kylelemons/godebug/pretty" - "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/common" + "github.com/trufflesecurity/trufflehog/v3/pkg/detectors" "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb" ) diff --git a/pkg/detectors/websitepulse/websitepulse_integration_test.go b/pkg/detectors/websitepulse/websitepulse_integration_test.go index daec26e07fd7..e4e2faf94198 100644 --- a/pkg/detectors/websitepulse/websitepulse_integration_test.go +++ b/pkg/detectors/websitepulse/websitepulse_integration_test.go @@ -1,3 +1,6 @@ +//go:build detectors +// +build detectors + package websitepulse import (