Repository: sa7mon/S3Scanner (language: python)

Issue:
Some provider throws an error with bucket named 'auth'
Can't remember which provider it was, but one of them returns an unexpected error response when checking for a bucket called `auth`.


Discussion / hints:

Fix patch:
diff --git a/provider/dreamhost.go b/provider/dreamhost.go
index 3528583..2cea22c 100644
--- a/provider/dreamhost.go
+++ b/provider/dreamhost.go
@@ -6,8 +6,12 @@ import (
 	"github.com/aws/aws-sdk-go-v2/service/s3"
 	"github.com/sa7mon/s3scanner/bucket"
 	"github.com/sa7mon/s3scanner/provider/clientmap"
+	"strings"
 )
 
+// Dreamhost responds strangely if you attempt to access a bucket named 'auth'
+var forbiddenBuckets = []string{"auth"}
+
 type ProviderDreamhost struct {
 	clients *clientmap.ClientMap
 }
@@ -25,6 +29,14 @@ func (p ProviderDreamhost) AddressStyle() int {
 }
 
 func (p ProviderDreamhost) BucketExists(b *bucket.Bucket) (*bucket.Bucket, error) {
+	// Check for forbidden name
+	for _, fb := range forbiddenBuckets {
+		if strings.ToLower(b.Name) == fb {
+			b.Exists = bucket.BucketNotExist
+			return b, nil
+		}
+	}
+
 	b.Provider = p.Name()
 	exists, region, err := bucketExists(p.clients, b)
 	if err != nil {


Test patch:
diff --git a/provider/dreamhost_test.go b/provider/dreamhost_test.go
new file mode 100644
index 0000000..c9a731a
--- /dev/null
+++ b/provider/dreamhost_test.go
@@ -0,0 +1,35 @@
+package provider
+
+import (
+	"github.com/sa7mon/s3scanner/bucket"
+	"github.com/stretchr/testify/assert"
+	"testing"
+)
+
+func TestProviderDreamhost_BucketExists(t *testing.T) {
+	t.Parallel()
+	b := bucket.NewBucket("auth")
+	dh, err := NewProviderDreamhost()
+	if err != nil {
+		t.Error(err)
+	}
+	beb, err := dh.BucketExists(&b)
+	if err != nil {
+		t.Error(err)
+	}
+	assert.Equal(t, bucket.BucketNotExist, beb.Exists)
+}
+
+func TestProviderDreamhost_BucketExists_Cap(t *testing.T) {
+	t.Parallel()
+	b := bucket.NewBucket("aUtH")
+	dh, err := NewProviderDreamhost()
+	if err != nil {
+		t.Error(err)
+	}
+	beb, err := dh.BucketExists(&b)
+	if err != nil {
+		t.Error(err)
+	}
+	assert.Equal(t, bucket.BucketNotExist, beb.Exists)
+}