Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix: ignore dreamhost 'auth' bucket #208

Merged
merged 2 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions provider/dreamhost.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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 {
Expand Down
35 changes: 35 additions & 0 deletions provider/dreamhost_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
Loading