S3 Backend : Bucket key should not contain trailing slash

This commit is contained in:
Paschalis Tsilias 2020-01-28 14:47:38 +02:00 committed by Graham Davison
parent ff68c8d129
commit 4cb355f3d6
2 changed files with 18 additions and 0 deletions

View File

@ -37,6 +37,11 @@ func New() backend.Backend {
if strings.HasPrefix(v.(string), "/") {
return nil, []error{errors.New("key must not start with '/'")}
}
// s3 will recognize objects with a trailing slash as a directory
// so they should not be valid keys
if strings.HasSuffix(v.(string), "/") {
return nil, []error{errors.New("key must not end with '/'")}
}
return nil, nil
},
},

View File

@ -326,6 +326,19 @@ func TestBackendConfig_invalidKey(t *testing.T) {
if !diags.HasErrors() {
t.Fatal("expected config validation error")
}
cfg = hcl2shim.HCL2ValueFromConfigValue(map[string]interface{}{
"region": "us-west-1",
"bucket": "tf-test",
"key": "trailing-slash/",
"encrypt": true,
"dynamodb_table": "dynamoTable",
})
_, diags = New().PrepareConfig(cfg)
if !diags.HasErrors() {
t.Fatal("expected config validation error")
}
}
func TestBackendConfig_invalidSSECustomerKeyLength(t *testing.T) {