@@ -662,26 +662,45 @@ mod post_policy_test_helpers {
662662 )
663663 }
664664
665- /// Build a POST object request with a policy
665+ /// Augment a test POST policy JSON with the required `SigV4` eq conditions
666+ /// (`x-amz-date`, `x-amz-credential`, `x-amz-algorithm`) so the request
667+ /// passes the verifier's policy-field-matching checks.
668+ fn augment_post_policy_for_test ( policy_json : & str , amz_date : & str , credential : & str , algorithm : & str ) -> String {
669+ let mut policy: serde_json:: Value = serde_json:: from_str ( policy_json) . expect ( "invalid test policy JSON" ) ;
670+ let conditions = policy[ "conditions" ]
671+ . as_array_mut ( )
672+ . expect ( "policy must have a conditions array" ) ;
673+ conditions. push ( serde_json:: json!( { "x-amz-date" : amz_date} ) ) ;
674+ conditions. push ( serde_json:: json!( { "x-amz-credential" : credential} ) ) ;
675+ conditions. push ( serde_json:: json!( { "x-amz-algorithm" : algorithm} ) ) ;
676+ policy. to_string ( )
677+ }
678+
679+ /// Build a POST object request with a policy.
680+ ///
681+ /// The provided `policy_json` is augmented with the required `SigV4` POST
682+ /// policy eq conditions (`x-amz-date`, `x-amz-credential`, `x-amz-algorithm`)
683+ /// so the request passes the verifier's policy-field-matching checks.
666684 pub fn build_post_object_request (
667685 policy_json : & str ,
668686 file_content : & str ,
669687 secret_key : & SecretKey ,
670688 with_content_type : bool ,
671689 ) -> Request {
672- let policy_b64 = base64_simd:: STANDARD . encode_to_string ( policy_json) ;
673-
674690 let boundary = "------------------------test12345678" ;
675691 let bucket = "test-bucket" ;
676692 let key = "test-key" ;
677693 let amz_date = sig_v4:: AmzDate :: parse ( "20250101T000000Z" ) . unwrap ( ) ;
694+ let amz_date_str = amz_date. fmt_iso8601 ( ) ;
678695 let region = "us-east-1" ;
679696 let service = "s3" ;
680697 let content_type = "text/plain" ;
681698 let algorithm = "AWS4-HMAC-SHA256" ;
682699 let credential = "AKIAIOSFODNN7EXAMPLE/20250101/us-east-1/s3/aws4_request" ;
700+
701+ let policy_json = augment_post_policy_for_test ( policy_json, amz_date_str. as_str ( ) , credential, algorithm) ;
702+ let policy_b64 = base64_simd:: STANDARD . encode_to_string ( & policy_json) ;
683703 let signature = sig_v4:: calculate_signature ( & policy_b64, secret_key, & amz_date, region, service) ;
684- let amz_date_str = amz_date. fmt_iso8601 ( ) ;
685704
686705 let fields = {
687706 let mut f = vec ! [
@@ -721,25 +740,29 @@ mod post_policy_test_helpers {
721740 /// This ensures that `aggregate_file_stream_limited` returns a `Vec<Bytes>`
722741 /// with multiple entries, so tests can distinguish between
723742 /// `vec_bytes.len()` (chunk count) and the total byte count.
743+ ///
744+ /// The provided `policy_json` is augmented with the required `SigV4` POST
745+ /// policy eq conditions so the request passes the verifier's checks.
724746 pub fn build_post_object_request_chunked (
725747 policy_json : & str ,
726748 file_content : & str ,
727749 secret_key : & SecretKey ,
728750 chunk_size : usize ,
729751 ) -> Request {
730- let policy_b64 = base64_simd:: STANDARD . encode_to_string ( policy_json) ;
731-
732752 let boundary = "------------------------test12345678" ;
733753 let bucket = "test-bucket" ;
734754 let key = "test-key" ;
735755 let amz_date = sig_v4:: AmzDate :: parse ( "20250101T000000Z" ) . unwrap ( ) ;
756+ let amz_date_str = amz_date. fmt_iso8601 ( ) ;
736757 let region = "us-east-1" ;
737758 let service = "s3" ;
738759 let content_type = "text/plain" ;
739760 let algorithm = "AWS4-HMAC-SHA256" ;
740761 let credential = "AKIAIOSFODNN7EXAMPLE/20250101/us-east-1/s3/aws4_request" ;
762+
763+ let policy_json = augment_post_policy_for_test ( policy_json, amz_date_str. as_str ( ) , credential, algorithm) ;
764+ let policy_b64 = base64_simd:: STANDARD . encode_to_string ( & policy_json) ;
741765 let signature = sig_v4:: calculate_signature ( & policy_b64, secret_key, & amz_date, region, service) ;
742- let amz_date_str = amz_date. fmt_iso8601 ( ) ;
743766
744767 let body = build_multipart_fields (
745768 & [
0 commit comments