mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-12 17:12:01 -06:00
S3 Backend : Bucket key should not contain trailing slash
This commit is contained in:
parent
ff68c8d129
commit
4cb355f3d6
@ -37,6 +37,11 @@ func New() backend.Backend {
|
|||||||
if strings.HasPrefix(v.(string), "/") {
|
if strings.HasPrefix(v.(string), "/") {
|
||||||
return nil, []error{errors.New("key must not start with '/'")}
|
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
|
return nil, nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -326,6 +326,19 @@ func TestBackendConfig_invalidKey(t *testing.T) {
|
|||||||
if !diags.HasErrors() {
|
if !diags.HasErrors() {
|
||||||
t.Fatal("expected config validation error")
|
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) {
|
func TestBackendConfig_invalidSSECustomerKeyLength(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user