@@ -1013,6 +1013,94 @@ func TestUploaderValidARN(t *testing.T) {
1013
1013
}
1014
1014
}
1015
1015
1016
+ // TestUploadRequestChecksumCalculation tests that checksum behavior respects
1017
+ // the RequestChecksumCalculation setting for backwards compatibility.
1018
+ func TestUploadRequestChecksumCalculation (t * testing.T ) {
1019
+ testCases := []struct {
1020
+ name string
1021
+ requestChecksumCalculation aws.RequestChecksumCalculation
1022
+ inputChecksumAlgorithm types.ChecksumAlgorithm
1023
+ expectedChecksumAlgorithm types.ChecksumAlgorithm
1024
+ description string
1025
+ }{
1026
+ {
1027
+ name : "WhenRequired_NoDefault" ,
1028
+ requestChecksumCalculation : aws .RequestChecksumCalculationWhenRequired ,
1029
+ inputChecksumAlgorithm : "" ,
1030
+ expectedChecksumAlgorithm : "" ,
1031
+ description : "When RequestChecksumCalculationWhenRequired is set, no default checksum should be applied (backwards compatibility)" ,
1032
+ },
1033
+ {
1034
+ name : "WhenSupported_HasDefault" ,
1035
+ requestChecksumCalculation : aws .RequestChecksumCalculationWhenSupported ,
1036
+ inputChecksumAlgorithm : "" ,
1037
+ expectedChecksumAlgorithm : types .ChecksumAlgorithmCrc32 ,
1038
+ description : "When RequestChecksumCalculationWhenSupported is set, default CRC32 checksum should be applied" ,
1039
+ },
1040
+ {
1041
+ name : "WhenRequired_ExplicitPreserved" ,
1042
+ requestChecksumCalculation : aws .RequestChecksumCalculationWhenRequired ,
1043
+ inputChecksumAlgorithm : types .ChecksumAlgorithmSha256 ,
1044
+ expectedChecksumAlgorithm : types .ChecksumAlgorithmSha256 ,
1045
+ description : "Explicit checksums should always be preserved regardless of RequestChecksumCalculation setting" ,
1046
+ },
1047
+ {
1048
+ name : "WhenSupported_ExplicitPreserved" ,
1049
+ requestChecksumCalculation : aws .RequestChecksumCalculationWhenSupported ,
1050
+ inputChecksumAlgorithm : types .ChecksumAlgorithmSha1 ,
1051
+ expectedChecksumAlgorithm : types .ChecksumAlgorithmSha1 ,
1052
+ description : "Explicit checksums should override defaults even with WhenSupported" ,
1053
+ },
1054
+ }
1055
+
1056
+ for _ , tc := range testCases {
1057
+ t .Run (tc .name , func (t * testing.T ) {
1058
+ c , invocations , args := s3testing .NewUploadLoggingClient (nil )
1059
+
1060
+ mgr := manager .NewUploader (c , func (u * manager.Uploader ) {
1061
+ u .RequestChecksumCalculation = tc .requestChecksumCalculation
1062
+ })
1063
+
1064
+ input := & s3.PutObjectInput {
1065
+ Bucket : aws .String ("Bucket" ),
1066
+ Key : aws .String ("Key" ),
1067
+ Body : bytes .NewReader (buf12MB ),
1068
+ }
1069
+ if tc .inputChecksumAlgorithm != "" {
1070
+ input .ChecksumAlgorithm = tc .inputChecksumAlgorithm
1071
+ }
1072
+
1073
+ resp , err := mgr .Upload (context .Background (), input )
1074
+ if err != nil {
1075
+ t .Errorf ("Expected no error but received %v" , err )
1076
+ }
1077
+
1078
+ expectedOps := []string {"CreateMultipartUpload" , "UploadPart" , "UploadPart" , "UploadPart" , "CompleteMultipartUpload" }
1079
+ if diff := cmpDiff (expectedOps , * invocations ); len (diff ) > 0 {
1080
+ t .Error (diff )
1081
+ }
1082
+
1083
+ if resp .UploadID != "UPLOAD-ID" {
1084
+ t .Errorf ("expect %q, got %q" , "UPLOAD-ID" , resp .UploadID )
1085
+ }
1086
+
1087
+ cmu := (* args )[0 ].(* s3.CreateMultipartUploadInput )
1088
+ if cmu .ChecksumAlgorithm != tc .expectedChecksumAlgorithm {
1089
+ t .Errorf ("%s: Expected checksum algorithm %v in CreateMultipartUpload, but got %v" ,
1090
+ tc .description , tc .expectedChecksumAlgorithm , cmu .ChecksumAlgorithm )
1091
+ }
1092
+
1093
+ for i := 1 ; i <= 3 ; i ++ {
1094
+ uploadPart := (* args )[i ].(* s3.UploadPartInput )
1095
+ if uploadPart .ChecksumAlgorithm != tc .expectedChecksumAlgorithm {
1096
+ t .Errorf ("%s: Expected checksum algorithm %v in UploadPart %d, but got %v" ,
1097
+ tc .description , tc .expectedChecksumAlgorithm , i , uploadPart .ChecksumAlgorithm )
1098
+ }
1099
+ }
1100
+ })
1101
+ }
1102
+ }
1103
+
1016
1104
type mockS3UploadServer struct {
1017
1105
* http.ServeMux
1018
1106
0 commit comments