|
15 | 15 | import com.amazonaws.services.s3.model.EncryptedPutObjectRequest; |
16 | 16 | import com.amazonaws.services.s3.model.EncryptionMaterials; |
17 | 17 | import com.amazonaws.services.s3.model.EncryptionMaterialsProvider; |
| 18 | +import com.amazonaws.services.s3.model.GetObjectMetadataRequest; |
| 19 | +import com.amazonaws.services.s3.model.InitiateMultipartUploadRequest; |
| 20 | +import com.amazonaws.services.s3.model.InitiateMultipartUploadResult; |
18 | 21 | import com.amazonaws.services.s3.model.KMSEncryptionMaterials; |
19 | 22 | import com.amazonaws.services.s3.model.KMSEncryptionMaterialsProvider; |
| 23 | +import com.amazonaws.services.s3.model.ObjectMetadata; |
20 | 24 | import com.amazonaws.services.s3.model.StaticEncryptionMaterialsProvider; |
| 25 | +import com.amazonaws.services.s3.model.StorageClass; |
| 26 | +import com.amazonaws.services.s3.model.UploadObjectRequest; |
21 | 27 | import org.junit.jupiter.api.BeforeAll; |
22 | 28 | import org.junit.jupiter.api.Test; |
23 | 29 | import software.amazon.awssdk.core.ResponseBytes; |
|
28 | 34 | import software.amazon.awssdk.services.s3.model.MetadataDirective; |
29 | 35 | import software.amazon.awssdk.services.s3.model.PutObjectRequest; |
30 | 36 | import software.amazon.encryption.s3.internal.InstructionFileConfig; |
| 37 | +import software.amazon.encryption.s3.utils.BoundedInputStream; |
31 | 38 |
|
32 | 39 | import javax.crypto.KeyGenerator; |
33 | 40 | import javax.crypto.SecretKey; |
34 | 41 | import java.io.ByteArrayInputStream; |
35 | 42 | import java.io.IOException; |
| 43 | +import java.io.InputStream; |
36 | 44 | import java.nio.charset.StandardCharsets; |
37 | 45 | import java.security.KeyPair; |
38 | 46 | import java.security.KeyPairGenerator; |
39 | 47 | import java.security.NoSuchAlgorithmException; |
40 | 48 | import java.util.HashMap; |
41 | 49 | import java.util.Map; |
| 50 | +import java.util.concurrent.ExecutionException; |
42 | 51 |
|
43 | 52 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 53 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
44 | 54 | import static org.junit.jupiter.api.Assertions.assertThrows; |
| 55 | +import static software.amazon.encryption.s3.S3EncryptionClient.builder; |
45 | 56 | import static software.amazon.encryption.s3.S3EncryptionClient.withAdditionalConfiguration; |
46 | 57 | import static software.amazon.encryption.s3.utils.S3EncryptionClientTestResources.BUCKET; |
47 | 58 | import static software.amazon.encryption.s3.utils.S3EncryptionClientTestResources.KMS_KEY_ID; |
@@ -127,6 +138,7 @@ public void AesWrapV1toV3() { |
127 | 138 |
|
128 | 139 | // Asserts |
129 | 140 | final String input = "AesGcmV1toV3"; |
| 141 | + System.out.println(System.getenv("AWS_S3EC_TEST_BUCKET")); |
130 | 142 | v1Client.putObject(BUCKET, objectKey, input); |
131 | 143 |
|
132 | 144 | ResponseBytes<GetObjectResponse> objectResponse = v3Client.getObjectAsBytes(builder -> builder |
@@ -210,6 +222,39 @@ public void AesGcmV2toV3WithInstructionFile() { |
210 | 222 | deleteObject(BUCKET, objectKey, v3Client); |
211 | 223 | v3Client.close(); |
212 | 224 | } |
| 225 | + @Test |
| 226 | + public void multipartPutObjectWithOptionsAndInstructionFileV2() throws IOException, InterruptedException, ExecutionException { |
| 227 | + final String objectKey = appendTestSuffix("multipart-put-object-with-options-and-instruction-file-v2"); |
| 228 | + final long fileSizeLimit = 1024 * 1024 * 10; //sets file size limit to 10 MB |
| 229 | + final InputStream inputStream = new BoundedInputStream(fileSizeLimit); |
| 230 | + |
| 231 | + //Now, we will create encryption client (v2) with instruction file config enabled and multipart upload enabled |
| 232 | + EncryptionMaterialsProvider materialsProvider = |
| 233 | + new StaticEncryptionMaterialsProvider(new EncryptionMaterials(AES_KEY)); |
| 234 | + CryptoConfigurationV2 cryptoConfig = |
| 235 | + new CryptoConfigurationV2(CryptoMode.StrictAuthenticatedEncryption) |
| 236 | + .withStorageMode(CryptoStorageMode.InstructionFile); |
| 237 | + AmazonS3EncryptionV2 v2Client = AmazonS3EncryptionClientV2.encryptionBuilder() |
| 238 | + .withCryptoConfiguration(cryptoConfig) |
| 239 | + .withEncryptionMaterialsProvider(materialsProvider) |
| 240 | + .build(); |
| 241 | + UploadObjectRequest uploadObjectRequest = new UploadObjectRequest("s3ec-github-test-bucket-597133212884", objectKey, inputStream, new ObjectMetadata()) |
| 242 | + .withPartSize(1024 * 1024 * 5) |
| 243 | + .withStorageClass(StorageClass.Glacier); |
| 244 | + v2Client.uploadObject(uploadObjectRequest); |
| 245 | + |
| 246 | + //Assert that the storage class on main object matches "GLACIER" |
| 247 | + GetObjectMetadataRequest mainObjectRequest = new GetObjectMetadataRequest("s3ec-github-test-bucket-597133212884", objectKey); |
| 248 | + ObjectMetadata mainObjectMetadata = v2Client.getObjectMetadata(mainObjectRequest); |
| 249 | + assertEquals("GLACIER", mainObjectMetadata.getStorageClass()); |
| 250 | + |
| 251 | + //Assert that the instruction file does not contain storage class (V2) |
| 252 | + GetObjectMetadataRequest instructionObjectRequest = new GetObjectMetadataRequest("s3ec-github-test-bucket-597133212884", objectKey + ".instruction"); |
| 253 | + ObjectMetadata instructionFileMetadata = v2Client.getObjectMetadata(instructionObjectRequest); |
| 254 | + |
| 255 | + assertNotEquals("GLACIER", instructionFileMetadata.getStorageClass()); |
| 256 | + |
| 257 | + } |
213 | 258 |
|
214 | 259 | @Test |
215 | 260 | public void AesGcmV3toV1() { |
|
0 commit comments