Files
trufflehog/pkg/engine/gcs_test.go
ahrav c617bd7a4e Add resuming capability to GCS source (#1161)
* Add resuming capability to GCS source.

* Handle no auth scans.

* complete resume logic

* Use custom function type.

* remove functions.

* linter.

* fix test.

* fix test.

* Handle concurrent map writes.

* use string as CLI flag for include/exclude.

* handle emtpy buckets.

* Handle enumeration on initial job run.

* Rename stats to attributes.

* remove redundant return.

* If test fails due to 400, that is fine, it's expected.

* Add unauth GCS source type.

* comments.

* update proto.

* Use short flag.

* address comments.
2023-03-16 17:53:42 -07:00

71 lines
1.6 KiB
Go

package engine
import (
"strings"
"testing"
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
)
func TestScanGCS(t *testing.T) {
tests := []struct {
name string
gcsConfig sources.GCSConfig
wantErr bool
}{
{
name: "scanned GCS",
gcsConfig: sources.GCSConfig{
ApiKey: "abc123",
ProjectID: "test-project",
CloudCred: false,
WithoutAuth: false,
ServiceAccount: "",
},
},
{
name: "missing project ID, with auth",
gcsConfig: sources.GCSConfig{ApiKey: "abc123"},
wantErr: true,
},
{
name: "missing project ID, without auth, public scan",
gcsConfig: sources.GCSConfig{WithoutAuth: true},
},
{
name: "multiple selected auth methods",
gcsConfig: sources.GCSConfig{
ApiKey: "abc123",
ProjectID: "test-project",
CloudCred: true,
WithoutAuth: false,
ServiceAccount: "",
},
wantErr: true,
},
{
name: "no auth method selected",
gcsConfig: sources.GCSConfig{
ProjectID: "test-project",
MaxObjectSize: 10 * 1024 * 1024,
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
e := &Engine{}
err := e.ScanGCS(context.Background(), test.gcsConfig)
if err != nil && !test.wantErr && !strings.Contains(err.Error(), "googleapi: Error 400: Bad Request") {
t.Errorf("ScanGCS() got: %v, want: %v", err, nil)
return
}
if err == nil && test.wantErr {
t.Errorf("ScanGCS() got: %v, want: %v", err, "error")
}
})
}
}