Skip to content

Commit

Permalink
refactor(test): use s3 canned acl (#269)
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Pivkin <[email protected]>
  • Loading branch information
nikpivkin authored Nov 26, 2024
1 parent 574f9f8 commit b189830
Showing 1 changed file with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions internal/adapters/cloud/aws/s3/s3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type publicAccessBlock struct {

type bucketDetails struct {
bucketName string
acl string
acl s3types.BucketCannedACL
encrypted bool
loggingEnabled bool
loggingTargetBucket string
Expand All @@ -43,31 +43,31 @@ func Test_S3BucketACLs(t *testing.T) {
name: "simple bucket with public-read acl",
details: bucketDetails{
bucketName: "test-bucket",
acl: "public-read",
acl: s3types.BucketCannedACLPublicRead,
encrypted: false,
},
},
{
name: "simple bucket with authenticated-read acl",
details: bucketDetails{
bucketName: "wide-open-bucket",
acl: "authenticated-read",
acl: s3types.BucketCannedACLAuthenticatedRead,
encrypted: false,
},
},
{
name: "simple bucket with public-read-write acl",
details: bucketDetails{
bucketName: "public-read-write-bucket",
acl: "public-read-write",
acl: s3types.BucketCannedACLPublicReadWrite,
encrypted: false,
},
},
{
name: "simple bucket with private acl and encryption",
details: bucketDetails{
bucketName: "private-bucket",
acl: "private",
acl: s3types.BucketCannedACLPrivate,
encrypted: true,
},
},
Expand Down Expand Up @@ -96,7 +96,7 @@ func Test_S3BucketACLs(t *testing.T) {
}

assert.Equal(t, tt.details.bucketName, got.Name.Value())
assert.Equal(t, tt.details.acl, got.ACL.Value())
assert.Equal(t, string(tt.details.acl), got.ACL.Value())
if tt.details.encrypted {
// Amazon S3 now applies server-side encryption with Amazon S3 managed keys (SSE-S3)
assert.Equal(t, string(s3types.ServerSideEncryptionAes256), got.Encryption.Algorithm.Value())
Expand Down Expand Up @@ -296,8 +296,7 @@ func bootstrapBucket(t *testing.T, ra *aws.RootAdapter, spec bucketDetails) {

_, err := api.CreateBucket(ra.Context(), &s3api.CreateBucketInput{
Bucket: awssdk.String(spec.bucketName),

ACL: aclToCannedACL(spec.acl),
ACL: spec.acl,
})
require.NoError(t, err)

Expand Down Expand Up @@ -386,19 +385,6 @@ func createPublicAccessBlock(t *testing.T, api *s3api.Client, ctx context.Contex
require.NoError(t, err)
}

func aclToCannedACL(acl string) s3types.BucketCannedACL {
switch acl {
case "authenticated-read":
return s3types.BucketCannedACLAuthenticatedRead
case "public-read":
return s3types.BucketCannedACLPublicRead
case "public-read-write":
return s3types.BucketCannedACLPublicReadWrite
default:
return s3types.BucketCannedACLPrivate
}
}

func removeBucket(t *testing.T, ra *aws.RootAdapter, spec bucketDetails) {

api := s3api.NewFromConfig(ra.SessionConfig())
Expand Down

0 comments on commit b189830

Please sign in to comment.