@@ -3,7 +3,6 @@ use crate::utils::*;
33
44use std:: sync:: Arc ;
55
6- use base64:: Engine as _;
76use s3s_test:: Result ;
87use s3s_test:: TestFixture ;
98use s3s_test:: TestSuite ;
@@ -15,8 +14,6 @@ use aws_sdk_s3::primitives::SdkBody;
1514use bytes:: Bytes ;
1615use futures:: StreamExt as _;
1716use http_body_util:: StreamBody ;
18- use sha2:: Digest as _;
19- use sha2:: Sha256 ;
2017
2118pub fn register ( tcx : & mut TestContext ) {
2219 case ! ( tcx, Basic , Essential , test_list_buckets) ;
@@ -393,56 +390,85 @@ impl Put {
393390 let bucket = self . bucket . as_str ( ) ;
394391 let key = "with-checksum-trailer" ;
395392
396- let body = {
397- let bytes = Bytes :: from_static ( & [ b'a' ; 1024 ] ) ;
398-
399- let stream = futures:: stream:: repeat_with ( move || {
400- let frame = http_body:: Frame :: data ( bytes. clone ( ) ) ;
401- Ok :: < _ , std:: io:: Error > ( frame)
402- } ) ;
403-
404- let body = WithSizeHint :: new ( StreamBody :: new ( stream. take ( 70 ) ) , 70 * 1024 ) ;
405- ByteStream :: new ( SdkBody :: from_body_1_x ( body) )
406- } ;
407-
408- let put_resp = s3
409- . put_object ( )
410- . bucket ( bucket)
411- . key ( key)
412- . checksum_algorithm ( ChecksumAlgorithm :: Crc32 )
413- . body ( body)
414- . send ( )
415- . await ?;
416-
417- let put_crc32 = put_resp
418- . checksum_crc32 ( )
419- . expect ( "PUT should return checksum when checksum_algorithm is used" ) ;
420-
421- let resp = s3
422- . get_object ( )
423- . bucket ( bucket)
424- . key ( key)
425- . checksum_mode ( ChecksumMode :: Enabled )
426- . send ( )
427- . await ?;
428-
429- let get_crc32 = resp
430- . checksum_crc32 ( )
431- . expect ( "GET should return checksum when checksum_mode is enabled and full object is returned" )
432- . to_owned ( ) ;
393+ for checksum_algorithm in [
394+ ChecksumAlgorithm :: Crc32 ,
395+ ChecksumAlgorithm :: Crc32C ,
396+ ChecksumAlgorithm :: Sha1 ,
397+ ChecksumAlgorithm :: Sha256 ,
398+ ChecksumAlgorithm :: Crc64Nvme ,
399+ ] {
400+ let body = {
401+ let bytes = Bytes :: from_static ( & [ b'a' ; 1024 ] ) ;
402+
403+ let stream = futures:: stream:: repeat_with ( move || {
404+ let frame = http_body:: Frame :: data ( bytes. clone ( ) ) ;
405+ Ok :: < _ , std:: io:: Error > ( frame)
406+ } ) ;
407+
408+ let body = WithSizeHint :: new ( StreamBody :: new ( stream. take ( 70 ) ) , 70 * 1024 ) ;
409+ ByteStream :: new ( SdkBody :: from_body_1_x ( body) )
410+ } ;
411+
412+ let put_resp = s3
413+ . put_object ( )
414+ . bucket ( bucket)
415+ . key ( key)
416+ . checksum_algorithm ( checksum_algorithm. clone ( ) )
417+ . body ( body)
418+ . send ( )
419+ . await ?;
433420
434- let body = resp. body . collect ( ) . await ?;
435- let body = String :: from_utf8 ( body. to_vec ( ) ) ?;
436- assert_eq ! ( body, "a" . repeat( 70 * 1024 ) ) ;
421+ let put_resp_checksum = match checksum_algorithm {
422+ ChecksumAlgorithm :: Crc32 => put_resp
423+ . checksum_crc32 ( )
424+ . expect ( "PUT should return checksum when checksum_algorithm is used" ) ,
425+ ChecksumAlgorithm :: Crc32C => put_resp
426+ . checksum_crc32_c ( )
427+ . expect ( "PUT should return checksum when checksum_algorithm is used" ) ,
428+ ChecksumAlgorithm :: Sha1 => put_resp
429+ . checksum_sha1 ( )
430+ . expect ( "PUT should return checksum when checksum_algorithm is used" ) ,
431+ ChecksumAlgorithm :: Sha256 => put_resp
432+ . checksum_sha256 ( )
433+ . expect ( "PUT should return checksum when checksum_algorithm is used" ) ,
434+ ChecksumAlgorithm :: Crc64Nvme => put_resp
435+ . checksum_crc64_nvme ( )
436+ . expect ( "PUT should return checksum when checksum_algorithm is used" ) ,
437+ _ => panic ! ( "Unsupported checksum algorithm" ) ,
438+ } ;
439+
440+ let mut resp = s3
441+ . get_object ( )
442+ . bucket ( bucket)
443+ . key ( key)
444+ . checksum_mode ( ChecksumMode :: Enabled )
445+ . send ( )
446+ . await ?;
437447
438- assert_eq ! ( get_crc32, put_crc32) ;
448+ let body = std:: mem:: replace ( & mut resp. body , ByteStream :: new ( SdkBody :: empty ( ) ) )
449+ . collect ( )
450+ . await ?;
451+ // let body = resp.body.collect().await?;
452+ let body = String :: from_utf8 ( body. to_vec ( ) ) ?;
453+ assert_eq ! ( body, "a" . repeat( 70 * 1024 ) ) ;
454+
455+ let get_resp_checksum = match checksum_algorithm {
456+ ChecksumAlgorithm :: Crc32 => resp. checksum_crc32 ( ) ,
457+ ChecksumAlgorithm :: Crc32C => resp. checksum_crc32_c ( ) ,
458+ ChecksumAlgorithm :: Sha1 => resp. checksum_sha1 ( ) ,
459+ ChecksumAlgorithm :: Sha256 => resp. checksum_sha256 ( ) ,
460+ ChecksumAlgorithm :: Crc64Nvme => resp. checksum_crc64_nvme ( ) ,
461+ _ => panic ! ( "Unsupported checksum algorithm" ) ,
462+ } ;
463+
464+ assert_eq ! ( get_resp_checksum, Some ( put_resp_checksum) ) ;
465+ }
439466
440467 Ok ( ( ) )
441468 }
442469
443470 async fn test_put_object_with_content_checksums ( self : Arc < Self > ) -> Result {
444471 use base64:: Engine ;
445- use sha2:: { Digest , Sha256 } ;
446472
447473 let s3 = & self . s3 ;
448474 let bucket = self . bucket . as_str ( ) ;
0 commit comments