Skip to content

Commit

Permalink
Test, javadoc
Browse files Browse the repository at this point in the history
  • Loading branch information
haydenbaker committed Oct 2, 2023
1 parent 5bcc23f commit 872cd5e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ static V4RequestSigner presigned(V4Properties properties, Duration expirationDur
}

/**
* Retrieve an implementation of a V4RequestSigner, which signs the request and adds authentication through query parameters,
* which includes an expiration param, signalling how long a request signature is valid.
* Retrieve an implementation of a V4RequestSigner to handle the anonymous credentials case, where the request is not
* sigend at all.
*/
static V4RequestSigner anonymous(V4Properties properties) {
return requestBuilder ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public void sign_WithPayloadSigningFalseAndChunkEncodingTrueAndTrailer_Delegates
}

@Test
public void sign_WithPayloadSigningFalseAndChunkEncodingTrueWithoutTrailer_Throws() {
public void sign_WithPayloadSigningFalseAndChunkEncodingTrueWithoutTrailer_DelegatesToUnsignedPayload() {
SignRequest<? extends AwsCredentialsIdentity> request = generateBasicRequest(
AwsCredentialsIdentity.create("access", "secret"),
httpRequest -> httpRequest
Expand All @@ -231,7 +231,27 @@ public void sign_WithPayloadSigningFalseAndChunkEncodingTrueWithoutTrailer_Throw
.putProperty(CHUNK_ENCODING_ENABLED, true)
);

assertThrows(UnsupportedOperationException.class, () -> signer.sign(request));
SignedRequest signedRequest = signer.sign(request);
assertThat(signedRequest.request().firstMatchingHeader("x-amz-content-sha256")).hasValue("UNSIGNED-PAYLOAD");
assertThat(signedRequest.request().firstMatchingHeader("x-amz-decoded-content-length")).isNotPresent();
}

@Test
public void sign_WithPayloadSigningFalseAndChunkEncodingTrueWithChecksumHeader_DelegatesToUnsignedPayload() {
SignRequest<? extends AwsCredentialsIdentity> request = generateBasicRequest(
AwsCredentialsIdentity.create("access", "secret"),
httpRequest -> httpRequest
.putHeader(Header.CONTENT_LENGTH, "20")
.putHeader("x-amz-checksum-crc32", "bogus"),
signRequest -> signRequest
.putProperty(PAYLOAD_SIGNING_ENABLED, false)
.putProperty(CHUNK_ENCODING_ENABLED, true)
);

SignedRequest signedRequest = signer.sign(request);
assertThat(signedRequest.request().firstMatchingHeader("x-amz-content-sha256")).hasValue("UNSIGNED-PAYLOAD");
assertThat(signedRequest.request().firstMatchingHeader("x-amz-checksum-crc32")).hasValue("bogus");
assertThat(signedRequest.request().firstMatchingHeader("x-amz-decoded-content-length")).isNotPresent();
}

@Test
Expand Down

0 comments on commit 872cd5e

Please sign in to comment.