|
42 | 42 | import software.amazon.encryption.s3.algorithms.AlgorithmSuite; |
43 | 43 | import software.amazon.encryption.s3.internal.InstructionFileConfig; |
44 | 44 | import software.amazon.encryption.s3.internal.MetadataKeyConstants; |
| 45 | +import software.amazon.encryption.s3.materials.AesKeyring; |
45 | 46 | import software.amazon.encryption.s3.materials.CryptographicMaterialsManager; |
46 | 47 | import software.amazon.encryption.s3.materials.DefaultCryptoMaterialsManager; |
47 | 48 | import software.amazon.encryption.s3.materials.KmsKeyring; |
|
52 | 53 |
|
53 | 54 | import javax.crypto.KeyGenerator; |
54 | 55 | import javax.crypto.SecretKey; |
| 56 | +import javax.crypto.spec.SecretKeySpec; |
55 | 57 | import java.security.KeyPair; |
56 | 58 | import java.security.KeyPairGenerator; |
57 | 59 | import java.security.NoSuchAlgorithmException; |
@@ -964,6 +966,32 @@ public void s3EncryptionClientTopLevelCredentialsWrongRegion() { |
964 | 966 | } |
965 | 967 | } |
966 | 968 |
|
| 969 | + @RetryingTest(3) |
| 970 | + public void crossRegionRoundTrip() { |
| 971 | + final String objectKey = appendTestSuffix("cross-region-test"); |
| 972 | + SecretKeySpec aesKey = new SecretKeySpec(new byte[32], "AES"); |
| 973 | + AesKeyring keyRing = AesKeyring.builder().wrappingKey(aesKey).build(); |
| 974 | + |
| 975 | + S3Client s3 = S3EncryptionClient.builderV4() |
| 976 | + .region(Region.EU_CENTRAL_1) |
| 977 | + .crossRegionAccessEnabled(true) |
| 978 | + .keyring(keyRing) |
| 979 | + .build(); |
| 980 | + |
| 981 | + try { |
| 982 | + PutObjectRequest request = PutObjectRequest.builder().bucket(BUCKET).key(objectKey).build(); |
| 983 | + s3.putObject(request, RequestBody.fromBytes("test".getBytes())); |
| 984 | + ResponseBytes<GetObjectResponse> response = s3.getObjectAsBytes(builder -> builder |
| 985 | + .bucket(BUCKET) |
| 986 | + .key(objectKey) |
| 987 | + .build()); |
| 988 | + assertEquals("test", response.asUtf8String()); |
| 989 | + } finally { |
| 990 | + deleteObject(BUCKET, objectKey, s3); |
| 991 | + s3.close(); |
| 992 | + } |
| 993 | + } |
| 994 | + |
967 | 995 | @RetryingTest(3) |
968 | 996 | public void s3EncryptionClientTopLevelCredentialsNullCreds() { |
969 | 997 | final String objectKey = appendTestSuffix("wrapped-s3-client-with-null-credentials"); |
|
0 commit comments