Skip to content

Commit d480132

Browse files
committed
Additional test for no content-length
1 parent 0a236dc commit d480132

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

core/http-auth-aws/src/test/java/software/amazon/awssdk/http/auth/aws/internal/signer/DefaultAwsV4HttpSignerTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.awssdk.http.auth.aws.internal.signer;
1717

1818
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
19+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;
1920
import static org.junit.jupiter.api.Assertions.assertThrows;
2021
import static software.amazon.awssdk.checksums.DefaultChecksumAlgorithm.CRC32;
2122
import static software.amazon.awssdk.checksums.DefaultChecksumAlgorithm.SHA256;
@@ -956,6 +957,29 @@ void signAsync_WithPayloadSigningFalse_chunkEncodingTrue_cacheContainsChecksum_u
956957
assertThat(contentAsString).contains("x-amz-checksum-crc32:" + BinaryUtils.toBase64(checksumValue) + "\r\n");
957958
}
958959

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+
959983
private static byte[] computeChecksum(ChecksumAlgorithm algorithm, byte[] data) {
960984
SdkChecksum checksum = SdkChecksum.forAlgorithm(algorithm);
961985
checksum.update(data, 0, data.length);

0 commit comments

Comments
 (0)