|
25 | 25 | import software.amazon.awssdk.services.s3.S3Client;
|
26 | 26 | import software.amazon.awssdk.services.s3.model.GetObjectRequest;
|
27 | 27 | import software.amazon.awssdk.services.s3.model.GetObjectResponse;
|
| 28 | +import software.amazon.awssdk.services.s3.model.MetadataDirective; |
28 | 29 | import software.amazon.awssdk.services.s3.model.PutObjectRequest;
|
29 | 30 | import software.amazon.encryption.s3.internal.InstructionFileConfig;
|
30 | 31 |
|
@@ -168,6 +169,7 @@ public void AesGcmV2toV3() {
|
168 | 169 | // Cleanup
|
169 | 170 | deleteObject(BUCKET, objectKey, v3Client);
|
170 | 171 | v3Client.close();
|
| 172 | + |
171 | 173 | }
|
172 | 174 |
|
173 | 175 | @Test
|
@@ -902,4 +904,62 @@ public void AesWrapV1toV3FailsWhenLegacyModeDisabled() {
|
902 | 904 | deleteObject(BUCKET, objectKey, v3Client);
|
903 | 905 | v3Client.close();
|
904 | 906 | }
|
| 907 | + |
| 908 | + @Test |
| 909 | + public void nullMaterialDescriptionV3() { |
| 910 | + final String objectKey = appendTestSuffix("null-matdesc-v3"); |
| 911 | + |
| 912 | + // V2 Client |
| 913 | + EncryptionMaterialsProvider materialsProvider = |
| 914 | + new StaticEncryptionMaterialsProvider(new EncryptionMaterials(AES_KEY)); |
| 915 | + AmazonS3EncryptionV2 v2Client = AmazonS3EncryptionClientV2.encryptionBuilder() |
| 916 | + .withEncryptionMaterialsProvider(materialsProvider) |
| 917 | + .build(); |
| 918 | + |
| 919 | + // V3 Client |
| 920 | + S3Client v3Client = S3EncryptionClient.builder() |
| 921 | + .aesKey(AES_KEY) |
| 922 | + .build(); |
| 923 | + |
| 924 | + // Asserts |
| 925 | + final String input = "AesGcmWithNullMatDesc"; |
| 926 | + v2Client.putObject(BUCKET, objectKey, input); |
| 927 | + |
| 928 | + ResponseBytes<GetObjectResponse> objectResponse = v3Client.getObjectAsBytes(builder -> builder |
| 929 | + .bucket(BUCKET) |
| 930 | + .key(objectKey)); |
| 931 | + String output = objectResponse.asUtf8String(); |
| 932 | + assertEquals(input, output); |
| 933 | + |
| 934 | + // Now remove MatDesc - this must be done via CopyObject |
| 935 | + final String copyKey = objectKey + "copied"; |
| 936 | + Map<String, String> modMd = new HashMap<>(objectResponse.response().metadata()); |
| 937 | + modMd.remove("x-amz-meta-x-amz-matdesc"); |
| 938 | + modMd.remove("x-amz-matdesc"); |
| 939 | + v3Client.copyObject(builder -> builder |
| 940 | + .sourceBucket(BUCKET) |
| 941 | + .destinationBucket(BUCKET) |
| 942 | + .sourceKey(objectKey) |
| 943 | + .destinationKey(copyKey) |
| 944 | + .metadataDirective(MetadataDirective.REPLACE) |
| 945 | + .metadata(modMd) |
| 946 | + .build()); |
| 947 | + |
| 948 | + // V2 |
| 949 | + String v2CopyOut = v2Client.getObjectAsString(BUCKET, copyKey); |
| 950 | + assertEquals(input, v2CopyOut); |
| 951 | + |
| 952 | + // V3 |
| 953 | + ResponseBytes<GetObjectResponse> objectResponseCopy = v3Client.getObjectAsBytes(builder -> builder |
| 954 | + .bucket(BUCKET) |
| 955 | + .key(copyKey)); |
| 956 | + String outputCopy = objectResponseCopy.asUtf8String(); |
| 957 | + assertEquals(input, outputCopy); |
| 958 | + |
| 959 | + // Cleanup |
| 960 | + deleteObject(BUCKET, objectKey, v3Client); |
| 961 | + deleteObject(BUCKET, copyKey, v3Client); |
| 962 | + v3Client.close(); |
| 963 | + |
| 964 | + } |
905 | 965 | }
|
0 commit comments