Fix S3 configurable path handling (#7966)

Also remove some incorrect skipping of the S3 test.

Fixes #7362
This commit is contained in:
Jim Kalafut 2019-12-04 06:18:45 -08:00 committed by GitHub
parent f991b92dc3
commit 5d5c1374d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 4 deletions

View file

@ -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 += "/"
}

View file

@ -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