@@ -29,7 +29,8 @@ impl CatalystSignedDocumentValidationRule for ContentEncodingRule {
2929 doc : & CatalystSignedDocument ,
3030 _provider : & dyn Provider ,
3131 ) -> anyhow:: Result < bool > {
32- Ok ( self . check_inner ( doc) )
32+ self . check_inner ( doc) ;
33+ Ok ( !doc. report ( ) . is_problematic ( ) )
3334 }
3435}
3536
@@ -63,7 +64,7 @@ impl ContentEncodingRule {
6364 fn check_inner (
6465 & self ,
6566 doc : & CatalystSignedDocument ,
66- ) -> bool {
67+ ) {
6768 let context = "Content Encoding Rule check" ;
6869 match self {
6970 Self :: NotSpecified => {
@@ -75,7 +76,6 @@ impl ContentEncodingRule {
7576 "{context}, document does not expect to have a content-encoding field"
7677 ) ,
7778 ) ;
78- return false ;
7979 }
8080 } ,
8181 Self :: Specified { exp, optional } => {
@@ -90,7 +90,6 @@ impl ContentEncodingRule {
9090 . join ( ", " ) ,
9191 "Invalid document content-encoding value" ,
9292 ) ;
93- return false ;
9493 }
9594 if content_encoding. decode ( doc. encoded_content ( ) ) . is_err ( ) {
9695 doc. report ( ) . invalid_value (
@@ -99,18 +98,15 @@ impl ContentEncodingRule {
9998 content_encoding. to_string ( ) . as_str ( ) ,
10099 "Document content is not decodable with the expected content-encoding" ,
101100 ) ;
102- return false ;
103101 }
104102 } else if !optional {
105103 doc. report ( ) . missing_field (
106104 "content-encoding" ,
107105 "Document must have a content-encoding field" ,
108106 ) ;
109- return false ;
110107 }
111108 } ,
112109 }
113- true
114110 }
115111}
116112
@@ -128,26 +124,38 @@ mod tests {
128124 optional : true ,
129125 } ;
130126
131- let doc = Builder :: new ( )
127+ let doc = Builder :: with_required_fields ( )
132128 . with_metadata_field ( SupportedField :: ContentEncoding ( content_encoding) )
133129 . with_content ( content_encoding. encode ( & [ 1 , 2 , 3 ] ) . unwrap ( ) )
134130 . build ( ) ;
135- assert ! ( rule. check_inner( & doc) ) ;
131+ rule. check_inner ( & doc) ;
132+ assert ! ( !doc. report( ) . is_problematic( ) ) ;
136133
137134 // empty content (empty bytes) could not be brotli decoded
138- let doc = Builder :: new ( )
135+ let doc = Builder :: with_required_fields ( )
139136 . with_metadata_field ( SupportedField :: ContentEncoding ( content_encoding) )
140137 . build ( ) ;
141- assert ! ( !rule. check_inner( & doc) ) ;
142-
143- let doc = Builder :: new ( ) . build ( ) ;
144- assert ! ( rule. check_inner( & doc) ) ;
138+ rule. check_inner ( & doc) ;
139+ let report = format ! ( "{:?}" , doc. report( ) ) ;
140+ println ! ( "{report}" ) ;
141+ assert ! ( doc. report( ) . is_problematic( ) ) ;
142+ assert ! (
143+ report. contains( "Document content is not decodable with the expected content-encoding" )
144+ ) ;
145+
146+ let doc = Builder :: with_required_fields ( ) . build ( ) ;
147+ rule. check_inner ( & doc) ;
148+ assert ! ( !doc. report( ) . is_problematic( ) ) ;
145149
146150 let rule = ContentEncodingRule :: Specified {
147151 exp : vec ! [ content_encoding] ,
148152 optional : false ,
149153 } ;
150- assert ! ( !rule. check_inner( & doc) ) ;
154+ rule. check_inner ( & doc) ;
155+ let report = format ! ( "{:?}" , doc. report( ) ) ;
156+ println ! ( "{report}" ) ;
157+ assert ! ( doc. report( ) . is_problematic( ) ) ;
158+ assert ! ( report. contains( "Document must have a content-encoding field" ) ) ;
151159 }
152160
153161 #[ test]
@@ -157,13 +165,18 @@ mod tests {
157165 let rule = ContentEncodingRule :: NotSpecified ;
158166
159167 // With Brotli content encoding
160- let doc = Builder :: new ( )
168+ let doc = Builder :: with_required_fields ( )
161169 . with_metadata_field ( SupportedField :: ContentEncoding ( content_encoding) )
162170 . build ( ) ;
163- assert ! ( !rule. check_inner( & doc) ) ;
171+ rule. check_inner ( & doc) ;
172+ let report = format ! ( "{:?}" , doc. report( ) ) ;
173+ println ! ( "{report}" ) ;
174+ assert ! ( doc. report( ) . is_problematic( ) ) ;
175+ assert ! ( report. contains( "document does not expect to have a content-encoding field" ) ) ;
164176
165177 // No content encoding
166- let doc = Builder :: new ( ) . build ( ) ;
167- assert ! ( rule. check_inner( & doc) ) ;
178+ let doc = Builder :: with_required_fields ( ) . build ( ) ;
179+ rule. check_inner ( & doc) ;
180+ assert ! ( !doc. report( ) . is_problematic( ) ) ;
168181 }
169182}
0 commit comments