|
17 | 17 | import software.amazon.awssdk.core.ResponseInputStream; |
18 | 18 | import software.amazon.awssdk.core.async.AsyncRequestBody; |
19 | 19 | import software.amazon.awssdk.core.async.AsyncResponseTransformer; |
| 20 | +import software.amazon.awssdk.core.async.BlockingInputStreamAsyncRequestBody; |
20 | 21 | import software.amazon.awssdk.core.sync.RequestBody; |
21 | 22 | import software.amazon.awssdk.services.s3.S3AsyncClient; |
22 | 23 | import software.amazon.awssdk.services.s3.S3Client; |
23 | 24 | import software.amazon.awssdk.services.s3.model.GetObjectResponse; |
24 | 25 | import software.amazon.awssdk.services.s3.model.PutObjectRequest; |
25 | 26 | import software.amazon.awssdk.services.s3.model.PutObjectResponse; |
26 | 27 | import software.amazon.awssdk.utils.IoUtils; |
27 | | -import software.amazon.encryption.s3.utils.BoundedStreamBufferer; |
28 | 28 | import software.amazon.encryption.s3.utils.BoundedInputStream; |
| 29 | +import software.amazon.encryption.s3.utils.BoundedStreamBufferer; |
29 | 30 | import software.amazon.encryption.s3.utils.MarkResetBoundedZerosInputStream; |
30 | 31 | import software.amazon.encryption.s3.utils.S3EncryptionClientTestResources; |
31 | 32 |
|
@@ -135,6 +136,56 @@ public void ordinaryInputStreamV3Encrypt() throws IOException { |
135 | 136 | v3Client.close(); |
136 | 137 | } |
137 | 138 |
|
| 139 | + @Test |
| 140 | + public void ordinaryInputStreamV3UnboundedAsync() { |
| 141 | + try (S3AsyncClient s3AsyncEncryptionClient = S3AsyncEncryptionClient.builder().aesKey(AES_KEY).build()) { |
| 142 | + final String objectKey = appendTestSuffix("ordinaryInputStreamV3UnboundedAsync"); |
| 143 | + BlockingInputStreamAsyncRequestBody body = |
| 144 | + AsyncRequestBody.forBlockingInputStream(null); |
| 145 | + try { |
| 146 | + s3AsyncEncryptionClient.putObject(r -> r.bucket(BUCKET).key(objectKey), body); |
| 147 | + fail("Expected exception!"); |
| 148 | + } catch (S3EncryptionClientException exception) { |
| 149 | + // expected |
| 150 | + assertTrue(exception.getMessage().contains("Unbounded streams are currently not supported")); |
| 151 | + } |
| 152 | + } |
| 153 | + } |
| 154 | + |
| 155 | + @Test |
| 156 | + public void ordinaryInputStreamV3UnboundedMultipartAsync() { |
| 157 | + try (S3AsyncClient s3AsyncEncryptionClient = S3AsyncEncryptionClient.builder().aesKey(AES_KEY).enableMultipartPutObject(true).wrappedClient(s3AsyncClient).build()) { |
| 158 | + final String objectKey = appendTestSuffix("ordinaryInputStreamV3UnboundedAsync"); |
| 159 | + BlockingInputStreamAsyncRequestBody body = |
| 160 | + AsyncRequestBody.forBlockingInputStream(null); |
| 161 | + try { |
| 162 | + s3AsyncEncryptionClient.putObject(r -> r.bucket(BUCKET).key(objectKey), body); |
| 163 | + fail("Expected exception!"); |
| 164 | + } catch (S3EncryptionClientException exception) { |
| 165 | + // expected |
| 166 | + assertTrue(exception.getMessage().contains("Unbounded streams are currently not supported")); |
| 167 | + } |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + @Test |
| 172 | + public void ordinaryInputStreamV3UnboundedCrt() { |
| 173 | + try (S3AsyncClient s3CrtAsyncClient = S3AsyncClient.crtCreate()) { |
| 174 | + try (S3AsyncClient s3AsyncEncryptionClient = S3AsyncEncryptionClient.builder().aesKey(AES_KEY).enableMultipartPutObject(true).wrappedClient(s3CrtAsyncClient).build()) { |
| 175 | + final String objectKey = appendTestSuffix("ordinaryInputStreamV3UnboundedCrt"); |
| 176 | + BlockingInputStreamAsyncRequestBody body = |
| 177 | + AsyncRequestBody.forBlockingInputStream(null); |
| 178 | + try { |
| 179 | + s3AsyncEncryptionClient.putObject(r -> r.bucket(BUCKET).key(objectKey), body); |
| 180 | + fail("Expected exception!"); |
| 181 | + } catch (S3EncryptionClientException exception) { |
| 182 | + // expected |
| 183 | + assertTrue(exception.getMessage().contains("Unbounded streams are currently not supported")); |
| 184 | + } |
| 185 | + } |
| 186 | + } |
| 187 | + } |
| 188 | + |
138 | 189 | @Test |
139 | 190 | public void ordinaryInputStreamV3Decrypt() throws IOException { |
140 | 191 | final String objectKey = appendTestSuffix("ordinaryInputStreamV3Decrypt"); |
@@ -274,9 +325,9 @@ public void customSetBufferSizeWithLargeObject() throws IOException { |
274 | 325 | final long fileSizeExceedingDefaultLimit = 1024 * 1024 * 32 + 1; |
275 | 326 | final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit); |
276 | 327 | v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder() |
277 | | - .bucket(BUCKET) |
278 | | - .key(objectKey) |
279 | | - .build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit)); |
| 328 | + .bucket(BUCKET) |
| 329 | + .key(objectKey) |
| 330 | + .build(), RequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit)); |
280 | 331 |
|
281 | 332 | largeObjectStream.close(); |
282 | 333 |
|
@@ -327,9 +378,9 @@ public void customSetBufferSizeWithLargeObjectAsyncClient() throws IOException { |
327 | 378 | final InputStream largeObjectStream = new BoundedInputStream(fileSizeExceedingDefaultLimit); |
328 | 379 | ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor(); |
329 | 380 | CompletableFuture<PutObjectResponse> futurePut = v3ClientWithBuffer32MiB.putObject(PutObjectRequest.builder() |
330 | | - .bucket(BUCKET) |
331 | | - .key(objectKey) |
332 | | - .build(), AsyncRequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit, singleThreadExecutor)); |
| 381 | + .bucket(BUCKET) |
| 382 | + .key(objectKey) |
| 383 | + .build(), AsyncRequestBody.fromInputStream(largeObjectStream, fileSizeExceedingDefaultLimit, singleThreadExecutor)); |
333 | 384 |
|
334 | 385 | futurePut.join(); |
335 | 386 | largeObjectStream.close(); |
@@ -387,7 +438,7 @@ public void delayedAuthModeWithLargeObject() throws IOException { |
387 | 438 | assertThrows(S3EncryptionClientException.class, () -> v3Client.getObjectAsBytes(builder -> builder |
388 | 439 | .bucket(BUCKET) |
389 | 440 | .key(objectKey))); |
390 | | - |
| 441 | + |
391 | 442 | S3Client v3ClientWithDelayedAuth = S3EncryptionClient.builder() |
392 | 443 | .aesKey(AES_KEY) |
393 | 444 | .enableDelayedAuthenticationMode(true) |
|
0 commit comments