@@ -760,6 +760,86 @@ def test_cp_with_error_and_warning_permissions(self):
760
760
self .assertIn ('upload failed' , stderr )
761
761
self .assertIn ('warning: File has an invalid timestamp.' , stderr )
762
762
763
+ def test_upload_with_checksum_algorithm_crc32 (self ):
764
+ full_path = self .files .create_file ('foo.txt' , 'contents' )
765
+ cmdline = f'{ self .prefix } { full_path } s3://bucket/key.txt --checksum-algorithm CRC32'
766
+ self .run_cmd (cmdline , expected_rc = 0 )
767
+ self .assertEqual (self .operations_called [0 ][0 ].name , 'PutObject' )
768
+ self .assertEqual (self .operations_called [0 ][1 ]['ChecksumAlgorithm' ], 'CRC32' )
769
+
770
+ def test_upload_with_checksum_algorithm_crc32c (self ):
771
+ full_path = self .files .create_file ('foo.txt' , 'contents' )
772
+ cmdline = f'{ self .prefix } { full_path } s3://bucket/key.txt --checksum-algorithm CRC32C'
773
+ self .run_cmd (cmdline , expected_rc = 0 )
774
+ self .assertEqual (self .operations_called [0 ][0 ].name , 'PutObject' )
775
+ self .assertEqual (self .operations_called [0 ][1 ]['ChecksumAlgorithm' ], 'CRC32C' )
776
+
777
+ def test_multipart_upload_with_checksum_algorithm_crc32 (self ):
778
+ full_path = self .files .create_file ('foo.txt' , 'a' * 10 * (1024 ** 2 ))
779
+ self .parsed_responses = [
780
+ {'UploadId' : 'foo' },
781
+ {'ETag' : 'foo-e1' , 'ChecksumCRC32' : 'foo-1' },
782
+ {'ETag' : 'foo-e2' , 'ChecksumCRC32' : 'foo-2' },
783
+ {}
784
+ ]
785
+ cmdline = ('%s %s s3://bucket/key2.txt'
786
+ ' --checksum-algorithm CRC32' % (self .prefix , full_path ))
787
+ self .run_cmd (cmdline , expected_rc = 0 )
788
+ self .assertEqual (len (self .operations_called ), 4 , self .operations_called )
789
+ self .assertEqual (self .operations_called [0 ][0 ].name , 'CreateMultipartUpload' )
790
+ self .assertEqual (self .operations_called [0 ][1 ]['ChecksumAlgorithm' ], 'CRC32' )
791
+ self .assertEqual (self .operations_called [1 ][0 ].name , 'UploadPart' )
792
+ self .assertEqual (self .operations_called [1 ][1 ]['ChecksumAlgorithm' ], 'CRC32' )
793
+ self .assertEqual (self .operations_called [3 ][0 ].name , 'CompleteMultipartUpload' )
794
+ self .assertIn ({'ETag' : 'foo-e1' , 'ChecksumCRC32' : 'foo-1' , 'PartNumber' : 1 },
795
+ self .operations_called [3 ][1 ]['MultipartUpload' ]['Parts' ])
796
+ self .assertIn ({'ETag' : 'foo-e2' , 'ChecksumCRC32' : 'foo-2' , 'PartNumber' : 2 },
797
+ self .operations_called [3 ][1 ]['MultipartUpload' ]['Parts' ])
798
+
799
+ def test_copy_with_checksum_algorithm_crc32 (self ):
800
+ self .parsed_responses = [
801
+ self .head_object_response (),
802
+ # Mocked CopyObject response with a CRC32 checksum specified
803
+ {
804
+ 'ETag' : 'foo-1' ,
805
+ 'ChecksumCRC32' : 'Tq0H4g=='
806
+ }
807
+ ]
808
+ cmdline = f'{ self .prefix } s3://bucket1/key.txt s3://bucket2/key.txt --checksum-algorithm CRC32'
809
+ self .run_cmd (cmdline , expected_rc = 0 )
810
+ self .assertEqual (self .operations_called [1 ][0 ].name , 'CopyObject' )
811
+ self .assertEqual (self .operations_called [1 ][1 ]['ChecksumAlgorithm' ], 'CRC32' )
812
+
813
+ def test_download_with_checksum_mode_crc32 (self ):
814
+ self .parsed_responses = [
815
+ self .head_object_response (),
816
+ # Mocked GetObject response with a checksum algorithm specified
817
+ {
818
+ 'ETag' : 'foo-1' ,
819
+ 'ChecksumCRC32' : 'Tq0H4g==' ,
820
+ 'Body' : BytesIO (b'foo' )
821
+ }
822
+ ]
823
+ cmdline = f'{ self .prefix } s3://bucket/foo { self .files .rootdir } --checksum-mode ENABLED'
824
+ self .run_cmd (cmdline , expected_rc = 0 )
825
+ self .assertEqual (self .operations_called [1 ][0 ].name , 'GetObject' )
826
+ self .assertEqual (self .operations_called [1 ][1 ]['ChecksumMode' ], 'ENABLED' )
827
+
828
+ def test_download_with_checksum_mode_crc32c (self ):
829
+ self .parsed_responses = [
830
+ self .head_object_response (),
831
+ # Mocked GetObject response with a checksum algorithm specified
832
+ {
833
+ 'ETag' : 'foo-1' ,
834
+ 'ChecksumCRC32C' : 'checksum' ,
835
+ 'Body' : BytesIO (b'foo' )
836
+ }
837
+ ]
838
+ cmdline = f'{ self .prefix } s3://bucket/foo { self .files .rootdir } --checksum-mode ENABLED'
839
+ self .run_cmd (cmdline , expected_rc = 0 )
840
+ self .assertEqual (self .operations_called [1 ][0 ].name , 'GetObject' )
841
+ self .assertEqual (self .operations_called [1 ][1 ]['ChecksumMode' ], 'ENABLED' )
842
+
763
843
764
844
class TestStreamingCPCommand (BaseAWSCommandParamsTest ):
765
845
def test_streaming_upload (self ):
0 commit comments