Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@
<artifactId>s3-transfer-manager</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>aws.sdk.kotlin</groupId>
<artifactId>s3-jvm</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2024 Adobe.
* Copyright 2017-2025 Adobe.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,16 +21,10 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo
import software.amazon.awssdk.services.s3.S3Client
import software.amazon.awssdk.services.s3.model.AccessControlPolicy
import software.amazon.awssdk.services.s3.model.CreateBucketRequest
import software.amazon.awssdk.services.s3.model.GetObjectAclRequest
import software.amazon.awssdk.services.s3.model.Grant
import software.amazon.awssdk.services.s3.model.Grantee
import software.amazon.awssdk.services.s3.model.ObjectCannedACL
import software.amazon.awssdk.services.s3.model.ObjectOwnership
import software.amazon.awssdk.services.s3.model.Owner
import software.amazon.awssdk.services.s3.model.Permission.FULL_CONTROL
import software.amazon.awssdk.services.s3.model.PutObjectAclRequest
import software.amazon.awssdk.services.s3.model.Type.CANONICAL_USER

internal class AclITV2 : S3TestBase() {
Expand All @@ -43,33 +37,27 @@ internal class AclITV2 : S3TestBase() {
val bucketName = bucketName(testInfo)

//create bucket that sets ownership to non-default to allow setting ACLs.
s3ClientV2.createBucket(CreateBucketRequest
.builder()
.bucket(bucketName)
.objectOwnership(ObjectOwnership.OBJECT_WRITER)
.build()
)
s3ClientV2.createBucket {
it.bucket(bucketName)
it.objectOwnership(ObjectOwnership.OBJECT_WRITER)
}.also {
assertThat(it.sdkHttpResponse().isSuccessful).isTrue()
}

givenObjectV2(bucketName, sourceKey)

s3ClientV2.putObjectAcl(
PutObjectAclRequest
.builder()
.bucket(bucketName)
.key(sourceKey)
.acl(ObjectCannedACL.PRIVATE)
.build()
).also {
s3ClientV2.putObjectAcl {
it.bucket(bucketName)
it.key(sourceKey)
it.acl(ObjectCannedACL.PRIVATE)
}.also {
assertThat(it.sdkHttpResponse().isSuccessful).isTrue()
}

s3ClientV2.getObjectAcl(
GetObjectAclRequest
.builder()
.bucket(bucketName)
.key(sourceKey)
.build()
).also {
s3ClientV2.getObjectAcl {
it.bucket(bucketName)
it.key(sourceKey)
}.also {
assertThat(it.sdkHttpResponse().isSuccessful).isTrue()
assertThat(it.owner().id()).isNotBlank()
assertThat(it.owner().displayName()).isNotBlank()
Expand All @@ -85,13 +73,10 @@ internal class AclITV2 : S3TestBase() {
val sourceKey = UPLOAD_FILE_NAME
val (bucketName, _) = givenBucketAndObjectV2(testInfo, sourceKey)

val acl = s3ClientV2.getObjectAcl(
GetObjectAclRequest
.builder()
.bucket(bucketName)
.key(sourceKey)
.build()
)
val acl = s3ClientV2.getObjectAcl {
it.bucket(bucketName)
it.key(sourceKey)
}

acl.owner().also { owner ->
assertThat(owner.id()).isEqualTo(DEFAULT_OWNER.id)
Expand Down Expand Up @@ -124,34 +109,30 @@ internal class AclITV2 : S3TestBase() {
val granteeId = "79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2ef"
val granteeName = "Jane Doe"
val granteeEmail = "jane@doe.com"
s3ClientV2.putObjectAcl(
PutObjectAclRequest
.builder()
.bucket(bucketName)
.key(sourceKey)
.accessControlPolicy(
AccessControlPolicy
.builder()
.owner(Owner.builder().id(userId).displayName(userName).build())
.grants(
Grant.builder()
.permission(FULL_CONTROL)
.grantee(
Grantee.builder().id(granteeId).displayName(granteeName)
.type(CANONICAL_USER).build()
).build()
).build()
)
.build()
)

val acl = s3ClientV2.getObjectAcl(
GetObjectAclRequest
.builder()
.bucket(bucketName)
.key(sourceKey)
.build()
)
s3ClientV2.putObjectAcl {
it.bucket(bucketName)
it.key(sourceKey)
it.accessControlPolicy {
it.owner {
it.id(userId)
it.displayName(userName)
}
it.grants(
Grant.builder()
.permission(FULL_CONTROL)
.grantee {
it.id(granteeId)
it.displayName(granteeName)
it.type(CANONICAL_USER)
}.build()
).build()
}
}

val acl = s3ClientV2.getObjectAcl {
it.bucket(bucketName)
it.key(sourceKey)
}
acl.owner().also {
assertThat(it).isNotNull
assertThat(it.id()).isEqualTo(userId)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2017-2025 Adobe.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.adobe.testing.s3mock.its

import aws.sdk.kotlin.services.s3.model.CreateBucketRequest
import aws.sdk.kotlin.services.s3.model.DeleteBucketRequest
import aws.sdk.kotlin.services.s3.model.HeadBucketRequest
import aws.sdk.kotlin.services.s3.model.S3Exception
import aws.sdk.kotlin.services.s3.waiters.waitUntilBucketExists
import aws.sdk.kotlin.services.s3.waiters.waitUntilBucketNotExists
import kotlinx.coroutines.runBlocking
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInfo

internal class KotlinSDKIT: S3TestBase() {
private val s3Client = createS3ClientKotlin()

@Test
@S3VerifiedTodo
fun createAndDeleteBucket(testInfo: TestInfo) : Unit = runBlocking {
val bucketName = bucketName(testInfo)
s3Client.createBucket(CreateBucketRequest { bucket = bucketName })

s3Client.waitUntilBucketExists(HeadBucketRequest { bucket = bucketName })

//does not throw exception if bucket exists.
s3Client.headBucket(HeadBucketRequest { bucket = bucketName })

s3Client.deleteBucket(DeleteBucketRequest { bucket = bucketName })
s3Client.waitUntilBucketNotExists(HeadBucketRequest { bucket = bucketName })

//throws exception if bucket does not exist.
assertThatThrownBy {
runBlocking {
s3Client.headBucket(HeadBucketRequest { bucket = bucketName })
}
}.isInstanceOf(S3Exception::class.java)
}
}
Loading
Loading