1717import com .amazonaws .services .s3 .model .StaticEncryptionMaterialsProvider ;
1818import org .bouncycastle .jce .provider .BouncyCastleProvider ;
1919import org .junit .jupiter .api .BeforeAll ;
20+ import org .junit .jupiter .api .Test ;
2021import org .junitpioneer .jupiter .RetryingTest ;
2122import software .amazon .awssdk .auth .credentials .AwsCredentialsProvider ;
2223import software .amazon .awssdk .auth .credentials .AwsSessionCredentials ;
@@ -966,7 +967,7 @@ public void s3EncryptionClientTopLevelCredentialsWrongRegion() {
966967 }
967968 }
968969
969- @ RetryingTest ( 3 )
970+ @ Test
970971 public void crossRegionRoundTrip () {
971972 final String objectKey = appendTestSuffix ("cross-region-test" );
972973 SecretKeySpec aesKey = new SecretKeySpec (new byte [32 ], "AES" );
@@ -980,14 +981,12 @@ public void crossRegionRoundTrip() {
980981
981982 try {
982983 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 ());
984+ S3EncryptionClientException ex = assertThrows (S3EncryptionClientException .class , () ->
985+ s3 .putObject (request , RequestBody .fromBytes ("test" .getBytes ())));
986+ // Cross-region redirect causes the SDK to re-subscribe to the request body.
987+ // NoRetriesAsyncRequestBody blocks this to prevent GCM cipher key/IV reuse.
988+ assertTrue (ex .getMessage ().contains ("Re-subscription is not supported" ));
989989 } finally {
990- deleteObject (BUCKET , objectKey , s3 );
991990 s3 .close ();
992991 }
993992 }
0 commit comments