Skip to content

Commit

Permalink
chore: run unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz committed Dec 12, 2024
1 parent bf6f313 commit f7da488
Show file tree
Hide file tree
Showing 19 changed files with 63 additions and 20 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
2 changes: 1 addition & 1 deletion pkg/detectors/aws/access_keys/accesskey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 7 additions & 7 deletions pkg/detectors/gcp/gcp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/detectors/hubspot_apikey/v1/apikey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
// },
{
Expand Down Expand Up @@ -61,7 +61,7 @@ const blogPosts = hs.blog.getPosts({ name: 'Inbound' });`,
"method": "GET",
"deprecated": false
}]`,
want: []string{""},
want: []string{"hDNxPGyQ-AOMZ-w9Sp-aw5t-TwKLBQjQ85go"},
},
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/detectors/kanbantool/kanbantool_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package kanbantool

import (
Expand Down
4 changes: 4 additions & 0 deletions pkg/detectors/lemlist/lemlist_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package lemlist

import (
Expand All @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions pkg/detectors/meraki/meraki_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package meraki

import (
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/monkeylearn/monkeylearn_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package monkeylearn

import (
Expand All @@ -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"
)

Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/opsgenie/opsgenie_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package opsgenie

import (
Expand All @@ -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"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package privatekey

import (
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/prodpad/prodpad_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package prodpad

import (
Expand All @@ -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"
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/detectors/salesmate/salesmate_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package salesmate

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/detectors/scalr/scalr_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package scalr

import (
Expand Down
3 changes: 3 additions & 0 deletions pkg/detectors/shopify/shopify_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package shopify

import (
Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/tokeet/tokeet_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package tokeet

import (
Expand All @@ -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"
)

Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/transferwise/transferwise_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package transferwise

import (
Expand All @@ -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"
)

Expand Down
5 changes: 4 additions & 1 deletion pkg/detectors/twist/twist_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package twist

import (
Expand All @@ -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"
)

Expand Down
3 changes: 3 additions & 0 deletions pkg/detectors/websitepulse/websitepulse_integration_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build detectors
// +build detectors

package websitepulse

import (
Expand Down

0 comments on commit f7da488

Please sign in to comment.