diff --git a/pkg/analyzer/analyzers/gitlab/expected_output.json b/pkg/analyzer/analyzers/gitlab/expected_output.json new file mode 100644 index 000000000000..80555a496aed --- /dev/null +++ b/pkg/analyzer/analyzers/gitlab/expected_output.json @@ -0,0 +1,59 @@ +{ + "AnalyzerType":5, + "Bindings":[ + { + "Resource":{ + "Name":"test-project-token", + "FullyQualifiedName":"test-project-token", + "Type":"access_token", + "Metadata":{ + "created_at":"2024-08-15T06:33:00.337Z", + "expires_at":"2025-08-15", + "last_used_at":"2024-08-15T07:21:41.127Z", + "revoked":false + }, + "Parent":null + }, + "Permission":{ + "Value":"read_api", + "Parent":null + } + }, + { + "Resource":{ + "Name":"test-project-token", + "FullyQualifiedName":"test-project-token", + "Type":"access_token", + "Metadata":{ + "created_at":"2024-08-15T06:33:00.337Z", + "expires_at":"2025-08-15", + "last_used_at":"2024-08-15T07:21:41.127Z", + "revoked":false + }, + "Parent":null + }, + "Permission":{ + "Value":"read_repository", + "Parent":null + } + }, + { + "Resource":{ + "Name":"truffletester / trufflehog", + "FullyQualifiedName":"truffletester / trufflehog", + "Type":"project", + "Metadata":null, + "Parent":null + }, + "Permission":{ + "Value":"Developer", + "Parent":null + } + } + ], + "UnboundedResources":null, + "Metadata":{ + "enterprise":true, + "version":"17.3.0-pre" + } + } \ No newline at end of file diff --git a/pkg/analyzer/analyzers/gitlab/gitlab_test.go b/pkg/analyzer/analyzers/gitlab/gitlab_test.go index 1345cd1fa7d9..bc62df9b36b1 100644 --- a/pkg/analyzer/analyzers/gitlab/gitlab_test.go +++ b/pkg/analyzer/analyzers/gitlab/gitlab_test.go @@ -1,6 +1,7 @@ package gitlab import ( + _ "embed" "encoding/json" "testing" "time" @@ -10,6 +11,9 @@ import ( "github.com/trufflesecurity/trufflehog/v3/pkg/context" ) +//go:embed expected_output.json +var expectedOutput []byte + func TestAnalyzer_Analyze(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) defer cancel() @@ -25,67 +29,9 @@ func TestAnalyzer_Analyze(t *testing.T) { wantErr bool }{ { - name: "valid gitlab access token", - key: testSecrets.MustGetField("GITLABV2"), - want: `{ - "AnalyzerType":5, - "Bindings":[ - { - "Resource":{ - "Name":"test-project-token", - "FullyQualifiedName":"test-project-token", - "Type":"access_token", - "Metadata":{ - "created_at":"2024-08-15T06:33:00.337Z", - "expires_at":"2025-08-15", - "last_used_at":"2024-08-15T07:21:41.127Z", - "revoked":false - }, - "Parent":null - }, - "Permission":{ - "Value":"read_api", - "Parent":null - } - }, - { - "Resource":{ - "Name":"test-project-token", - "FullyQualifiedName":"test-project-token", - "Type":"access_token", - "Metadata":{ - "created_at":"2024-08-15T06:33:00.337Z", - "expires_at":"2025-08-15", - "last_used_at":"2024-08-15T07:21:41.127Z", - "revoked":false - }, - "Parent":null - }, - "Permission":{ - "Value":"read_repository", - "Parent":null - } - }, - { - "Resource":{ - "Name":"truffletester / trufflehog", - "FullyQualifiedName":"truffletester / trufflehog", - "Type":"project", - "Metadata":null, - "Parent":null - }, - "Permission":{ - "Value":"Developer", - "Parent":null - } - } - ], - "UnboundedResources":null, - "Metadata":{ - "enterprise":true, - "version":"17.3.0-pre" - } - }`, + name: "valid gitlab access token", + key: testSecrets.MustGetField("GITLABV2"), + want: string(expectedOutput), wantErr: false, }, }