Skip to content

Commit

Permalink
Add missing check in acl client with test case (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolancon authored Oct 3, 2024
1 parent ea34efd commit c8908c7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
5 changes: 3 additions & 2 deletions internal/controller/bucket/acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,14 @@ func (l *ACLClient) observeBackend(bucket *v1alpha1.Bucket, backendName string)
return Updated
}

if bucket.Spec.ForProvider.AccessControlPolicy == nil &&
if bucket.Spec.ForProvider.ACL == nil &&
bucket.Spec.ForProvider.AccessControlPolicy == nil &&
bucket.Spec.ForProvider.GrantFullControl == nil &&
bucket.Spec.ForProvider.GrantWrite == nil &&
bucket.Spec.ForProvider.GrantWriteACP == nil &&
bucket.Spec.ForProvider.GrantRead == nil &&
bucket.Spec.ForProvider.GrantReadACP == nil {
l.log.Info("No access control policy or grants requested - no action required", consts.KeyBucketName, bucket.Name, consts.KeyBackendName, backendName)
l.log.Info("No acl or access control policy or grants requested - no action required", consts.KeyBucketName, bucket.Name, consts.KeyBackendName, backendName)

return Updated
}
Expand Down
31 changes: 30 additions & 1 deletion internal/controller/bucket/acl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (

func TestACLObserveBackend(t *testing.T) {
grantId := "id=abcd"
publicReadWriteACL := "public-read-write"
t.Parallel()

type fields struct {
Expand Down Expand Up @@ -106,7 +107,7 @@ func TestACLObserveBackend(t *testing.T) {
status: Updated,
},
},
"No policy or grants specified for the bucket": {
"No acl or policy or grants specified for the bucket": {
fields: fields{
backendStore: func() *backendstore.BackendStore {
fake := backendstorefakes.FakeS3Client{}
Expand All @@ -132,6 +133,34 @@ func TestACLObserveBackend(t *testing.T) {
status: Updated,
},
},
"ACL specified for the bucket": {
fields: fields{
backendStore: func() *backendstore.BackendStore {
fake := backendstorefakes.FakeS3Client{}

bs := backendstore.NewBackendStore()
bs.AddOrUpdateBackend("s3-backend-1", &fake, nil, true, apisv1alpha1.HealthStatusHealthy)

return bs
}(),
},
args: args{
bucket: &v1alpha1.Bucket{
ObjectMeta: metav1.ObjectMeta{
Name: "bucket",
},
Spec: v1alpha1.BucketSpec{
ForProvider: v1alpha1.BucketParameters{
ACL: &publicReadWriteACL,
},
},
},
backendName: "s3-backend-1",
},
want: want{
status: NeedsUpdate,
},
},
"Policy specified for the bucket": {
fields: fields{
backendStore: func() *backendstore.BackendStore {
Expand Down

0 comments on commit c8908c7

Please sign in to comment.