diff --git a/physical/s3/s3.go b/physical/s3/s3.go index 315b6d3269..b131678d47 100644 --- a/physical/s3/s3.go +++ b/physical/s3/s3.go @@ -225,6 +225,11 @@ func (s *S3Backend) Get(ctx context.Context, key string) (*physical.Entry, error return nil, err } + // Strip path prefix + if s.path != "" { + key = strings.TrimPrefix(key, s.path+"/") + } + ent := &physical.Entry{ Key: key, Value: data.Bytes(), @@ -266,8 +271,8 @@ func (s *S3Backend) List(ctx context.Context, prefix string) ([]string, error) { // Setup prefix prefix = path.Join(s.path, prefix) - // Validate prefix is ending with a "/" - if !strings.HasSuffix(prefix, "/") { + // Validate prefix (if present) is ending with a "/" + if prefix != "" && !strings.HasSuffix(prefix, "/") { prefix += "/" } diff --git a/physical/s3/s3_test.go b/physical/s3/s3_test.go index 849ab6b278..a7a7245541 100644 --- a/physical/s3/s3_test.go +++ b/physical/s3/s3_test.go @@ -34,12 +34,12 @@ func DoS3BackendTest(t *testing.T, kmsKeyId string) { credsChain, err := credsConfig.GenerateCredentialChain() if err != nil { - t.SkipNow() + t.Fatal(err) } _, err = credsChain.Get() if err != nil { - t.SkipNow() + t.Fatal(err) } // If the variable is empty or doesn't exist, the default