|
16 | 16 | package software.amazon.awssdk.http.auth.aws.internal.signer; |
17 | 17 |
|
18 | 18 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
| 19 | +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; |
19 | 20 | import static org.junit.jupiter.api.Assertions.assertThrows; |
20 | 21 | import static software.amazon.awssdk.checksums.DefaultChecksumAlgorithm.CRC32; |
21 | 22 | import static software.amazon.awssdk.checksums.DefaultChecksumAlgorithm.SHA256; |
@@ -956,6 +957,29 @@ void signAsync_WithPayloadSigningFalse_chunkEncodingTrue_cacheContainsChecksum_u |
956 | 957 | assertThat(contentAsString).contains("x-amz-checksum-crc32:" + BinaryUtils.toBase64(checksumValue) + "\r\n"); |
957 | 958 | } |
958 | 959 |
|
| 960 | + @Test |
| 961 | + void signAsync_WithPayloadSigningFalse_chunkEncodingTrue_noContentLengthHeader_throws() throws IOException { |
| 962 | + PayloadChecksumStore cache = PayloadChecksumStore.create(); |
| 963 | + |
| 964 | + byte[] checksumValue = "my-checksum".getBytes(StandardCharsets.UTF_8); |
| 965 | + cache.putChecksumValue(CRC32, checksumValue); |
| 966 | + |
| 967 | + AsyncSignRequest<? extends AwsCredentialsIdentity> request = generateBasicAsyncRequest( |
| 968 | + AwsCredentialsIdentity.create("access", "secret"), |
| 969 | + httpRequest -> httpRequest.uri(URI.create("http://demo.us-east-1.amazonaws.com")) |
| 970 | + .removeHeader("content-length"), |
| 971 | + signRequest -> signRequest |
| 972 | + .putProperty(PAYLOAD_SIGNING_ENABLED, false) |
| 973 | + .putProperty(CHUNK_ENCODING_ENABLED, true) |
| 974 | + .putProperty(CHECKSUM_ALGORITHM, CRC32) |
| 975 | + ); |
| 976 | + |
| 977 | + assertThatThrownBy(signer.signAsync(request)::join) |
| 978 | + .hasCauseInstanceOf(UnsupportedOperationException.class) |
| 979 | + .hasMessageContaining("Content-Length header must be specified"); |
| 980 | + } |
| 981 | + |
| 982 | + |
959 | 983 | private static byte[] computeChecksum(ChecksumAlgorithm algorithm, byte[] data) { |
960 | 984 | SdkChecksum checksum = SdkChecksum.forAlgorithm(algorithm); |
961 | 985 | checksum.update(data, 0, data.length); |
|
0 commit comments