30
30
import static software .amazon .awssdk .http .auth .aws .signer .AwsV4HttpSigner .PAYLOAD_SIGNING_ENABLED ;
31
31
import static software .amazon .awssdk .http .auth .spi .signer .SdkInternalHttpSignerProperty .CHECKSUM_STORE ;
32
32
33
+ import io .reactivex .Flowable ;
33
34
import java .io .IOException ;
34
35
import java .net .URI ;
36
+ import java .nio .ByteBuffer ;
35
37
import java .nio .charset .StandardCharsets ;
36
38
import java .time .Duration ;
37
- import java .util .Optional ;
39
+ import java .util .List ;
40
+ import java .util .stream .Collectors ;
38
41
import org .junit .jupiter .api .Disabled ;
39
42
import org .junit .jupiter .api .Test ;
40
43
import org .junit .jupiter .params .ParameterizedTest ;
41
44
import org .junit .jupiter .params .provider .ValueSource ;
42
45
import org .mockito .MockedStatic ;
43
46
import org .mockito .Mockito ;
47
+ import org .reactivestreams .Publisher ;
44
48
import software .amazon .awssdk .checksums .SdkChecksum ;
45
49
import software .amazon .awssdk .checksums .spi .ChecksumAlgorithm ;
46
50
import software .amazon .awssdk .http .Header ;
@@ -709,7 +713,9 @@ void sign_WithPayloadSigningTrueAndChunkEncodingTrueAndHttp_SignsPayload() {
709
713
}
710
714
711
715
@ Test
712
- void signAsync_WithPayloadSigningTrueAndChunkEncodingTrueAndHttp_IgnoresPayloadSigning () {
716
+ @ Disabled ("Fallback to signing is disabled to match pre-SRA behavior" )
717
+ // TODO: Enable this test once we figure out what the expected behavior is post SRA. See JAVA-8078
718
+ void signAsync_WithPayloadSigningTrueAndChunkEncodingTrueAndHttp_RespectsPayloadSigning () {
713
719
AsyncSignRequest <? extends AwsCredentialsIdentity > request = generateBasicAsyncRequest (
714
720
AwsCredentialsIdentity .create ("access" , "secret" ),
715
721
httpRequest -> httpRequest .uri (URI .create ("http://demo.us-east-1.amazonaws.com" )),
@@ -727,6 +733,8 @@ void signAsync_WithPayloadSigningTrueAndChunkEncodingTrueAndHttp_IgnoresPayloadS
727
733
}
728
734
729
735
@ Test
736
+ @ Disabled ("Fallback to signing is disabled to match pre-SRA behavior" )
737
+ // TODO: Enable this test once we figure out what the expected behavior is post SRA. See JAVA-8078
730
738
void sign_WithPayloadSigningFalseAndChunkEncodingTrueAndHttp_SignsPayload () {
731
739
SignRequest <? extends AwsCredentialsIdentity > request = generateBasicRequest (
732
740
AwsCredentialsIdentity .create ("access" , "secret" ),
@@ -745,7 +753,9 @@ void sign_WithPayloadSigningFalseAndChunkEncodingTrueAndHttp_SignsPayload() {
745
753
}
746
754
747
755
@ Test
748
- void signAsync_WithPayloadSigningFalseAndChunkEncodingTrueAndHttp_DoesNotFallBackToPayloadSigning () {
756
+ @ Disabled ("Fallback to signing is disabled to match pre-SRA behavior" )
757
+ // TODO: Enable this test once we figure out what the expected behavior is post SRA. See JAVA-8078
758
+ void signAsync_WithPayloadSigningFalseAndChunkEncodingTrueAndHttp_FallsBackToPayloadSigning () {
749
759
AsyncSignRequest <? extends AwsCredentialsIdentity > request = generateBasicAsyncRequest (
750
760
AwsCredentialsIdentity .create ("access" , "secret" ),
751
761
httpRequest -> httpRequest .uri (URI .create ("http://demo.us-east-1.amazonaws.com" )),
@@ -783,7 +793,9 @@ void sign_WithPayloadSigningFalseAndChunkEncodingTrueAndFlexibleChecksumAndHttp_
783
793
}
784
794
785
795
@ Test
786
- void signAsync_WithPayloadSigningFalseAndChunkEncodingTrueAndFlexibleChecksumAndHttp_DoesNotFallBackToPayloadSigning () {
796
+ @ Disabled ("Fallback to signing is disabled to match pre-SRA behavior" )
797
+ // TODO: Enable this test once we figure out what the expected behavior is post SRA. See JAVA-8078
798
+ void signAsync_WithPayloadSigningFalseAndChunkEncodingTrueAndFlexibleChecksumAndHttp_FallsBackToPayloadSigning () {
787
799
AsyncSignRequest <? extends AwsCredentialsIdentity > request = generateBasicAsyncRequest (
788
800
AwsCredentialsIdentity .create ("access" , "secret" ),
789
801
httpRequest -> httpRequest .uri (URI .create ("http://demo.us-east-1.amazonaws.com" )),
@@ -900,9 +912,61 @@ void sign_withPayloadSigningTrue_chunkEncodingFalse_withChecksum_cacheEmpty_stor
900
912
assertThat (cache .getChecksumValue (CRC32 )).isEqualTo (crc32Value );
901
913
}
902
914
915
+ @ Test
916
+ void signAsync_WithPayloadSigningFalse_chunkEncodingTrue_cacheEmpty_storesComputedChecksum () throws IOException {
917
+ PayloadChecksumStore cache = PayloadChecksumStore .create ();
918
+
919
+ AsyncSignRequest <? extends AwsCredentialsIdentity > request = generateBasicAsyncRequest (
920
+ AwsCredentialsIdentity .create ("access" , "secret" ),
921
+ httpRequest -> httpRequest .uri (URI .create ("http://demo.us-east-1.amazonaws.com" )),
922
+ signRequest -> signRequest
923
+ .putProperty (PAYLOAD_SIGNING_ENABLED , false )
924
+ .putProperty (CHUNK_ENCODING_ENABLED , true )
925
+ .putProperty (CHECKSUM_ALGORITHM , CRC32 )
926
+ .putProperty (CHECKSUM_STORE , cache )
927
+ );
928
+
929
+ AsyncSignedRequest signedRequest = signer .signAsync (request ).join ();
930
+
931
+ getAllItems (signedRequest .payload ().get ());
932
+ assertThat (cache .getChecksumValue (CRC32 )).isEqualTo (computeChecksum (CRC32 , testPayload ()));
933
+ }
934
+
935
+ @ Test
936
+ void signAsync_WithPayloadSigningFalse_chunkEncodingTrue_cacheContainsChecksum_usesCachedValue () throws IOException {
937
+ PayloadChecksumStore cache = PayloadChecksumStore .create ();
938
+
939
+ byte [] checksumValue = "my-checksum" .getBytes (StandardCharsets .UTF_8 );
940
+ cache .putChecksumValue (CRC32 , checksumValue );
941
+
942
+ AsyncSignRequest <? extends AwsCredentialsIdentity > request = generateBasicAsyncRequest (
943
+ AwsCredentialsIdentity .create ("access" , "secret" ),
944
+ httpRequest -> httpRequest .uri (URI .create ("http://demo.us-east-1.amazonaws.com" )),
945
+ signRequest -> signRequest
946
+ .putProperty (PAYLOAD_SIGNING_ENABLED , false )
947
+ .putProperty (CHUNK_ENCODING_ENABLED , true )
948
+ .putProperty (CHECKSUM_ALGORITHM , CRC32 )
949
+ .putProperty (CHECKSUM_STORE , cache )
950
+ );
951
+
952
+ AsyncSignedRequest signedRequest = signer .signAsync (request ).join ();
953
+
954
+ List <ByteBuffer > content = getAllItems (signedRequest .payload ().get ());
955
+ String contentAsString = content .stream ().map (DefaultAwsV4HttpSignerTest ::bufferAsString ).collect (Collectors .joining ());
956
+ assertThat (contentAsString ).contains ("x-amz-checksum-crc32:" + BinaryUtils .toBase64 (checksumValue ) + "\r \n " );
957
+ }
958
+
903
959
private static byte [] computeChecksum (ChecksumAlgorithm algorithm , byte [] data ) {
904
960
SdkChecksum checksum = SdkChecksum .forAlgorithm (algorithm );
905
961
checksum .update (data , 0 , data .length );
906
962
return checksum .getChecksumBytes ();
907
963
}
964
+
965
+ private List <ByteBuffer > getAllItems (Publisher <ByteBuffer > publisher ) {
966
+ return Flowable .fromPublisher (publisher ).toList ().blockingGet ();
967
+ }
968
+
969
+ private static String bufferAsString (ByteBuffer buffer ) {
970
+ return StandardCharsets .UTF_8 .decode (buffer .duplicate ()).toString ();
971
+ }
908
972
}
0 commit comments