@@ -160,26 +160,34 @@ impl ManifestValidationResult {
160160
161161/// Manifest containing [`ManifestRequest`] and [`ManifestResponse`]
162162#[ derive( Debug , Clone , Serialize , Deserialize , PartialEq , From ) ]
163- // #[serde(rename_all = "camelCase")]
163+ #[ serde( rename_all = "camelCase" ) ]
164164pub struct Manifest {
165- // // / Manifest version
166- // pub manifest_version: String,
167- // // / ID of the manifest
168- // pub id: String,
169- // // / Title of the manifest
170- // pub title: String,
171- // // / Description of the manifest
172- // pub description: String,
165+ /// Manifest version
166+ pub manifest_version : String ,
167+ /// ID of the manifest
168+ pub id : Option < String > ,
169+ /// Title of the manifest
170+ pub title : Option < String > ,
171+ /// Description of the manifest
172+ pub description : Option < String > ,
173173 /// HTTP request lock items
174- pub request : ManifestRequest ,
174+ pub request : ManifestRequest ,
175175 /// HTTP response lock items
176- pub response : ManifestResponse ,
176+ pub response : ManifestResponse ,
177177}
178178
179179impl Manifest {
180- fn validate_manifest ( & self ) -> ManifestValidationResult {
180+ fn validate_manifest ( & self ) -> Result < ManifestValidationResult , WebProverCoreError > {
181181 let mut summary = ManifestValidationResult :: default ( ) ;
182182
183+ // Validate manifest version
184+ if self . manifest_version != "2" {
185+ return Err ( WebProverCoreError :: InvalidManifest ( format ! (
186+ "Invalid manifest version: {}" ,
187+ self . manifest_version
188+ ) ) ) ;
189+ }
190+
183191 // TODO: Validate manifest version, id, title, description, prepareUrl
184192 if let Err ( e) = self . request . validate ( ) {
185193 debug ! ( "Invalid manifest request: {:?}" , e) ;
@@ -194,7 +202,7 @@ impl Manifest {
194202 summary. errors . push ( e. to_string ( ) ) ;
195203 }
196204
197- summary
205+ Ok ( summary)
198206 }
199207
200208 /// Validates `Manifest` request and response fields. They are validated against valid statuses,
@@ -207,7 +215,7 @@ impl Manifest {
207215 let mut result = ManifestValidationResult :: default ( ) ;
208216
209217 // Validate manifest fields
210- result. merge ( & self . validate_manifest ( ) ) ;
218+ result. merge ( & self . validate_manifest ( ) ? ) ;
211219
212220 // Check if request matches manifest requirements
213221 result. merge ( & self . request . is_subset_of ( request) ?) ;
@@ -266,10 +274,10 @@ mod tests {
266274 $( , $field: ident = $value: expr) * $( , ) ?
267275 ) => { {
268276 Manifest {
269- // manifest_version: "1 ".to_string(),
270- // id: "Default Manifest ID".to_string(),
271- // title: "Default Manifest Title".to_string(),
272- // description: "Default description.".to_string(),
277+ manifest_version: "2 " . to_string( ) ,
278+ id: Some ( "Default Manifest ID" . to_string( ) ) ,
279+ title: Some ( "Default Manifest Title" . to_string( ) ) ,
280+ description: Some ( "Default description." . to_string( ) ) ,
273281 request: $request,
274282 response: $response,
275283 $(
@@ -317,14 +325,14 @@ mod tests {
317325 #[ test]
318326 fn test_green_path_manifest_validation ( ) {
319327 let manifest: Manifest = serde_json:: from_str ( TEST_MANIFEST ) . unwrap ( ) ;
320- let result = manifest. validate_manifest ( ) ;
328+ let result = manifest. validate_manifest ( ) . unwrap ( ) ;
321329 assert ! ( result. is_success( ) ) ;
322330 assert ! ( result. values( ) . is_empty( ) ) ;
323331 }
324332
325333 const TEST_MANIFEST_WITHOUT_VARS : & str = r#"
326334{
327- "manifestVersion": "1 ",
335+ "manifestVersion": "2 ",
328336 "id": "reddit-user-karma",
329337 "title": "Total Reddit Karma",
330338 "description": "Generate a proof that you have a certain amount of karma",
@@ -363,7 +371,7 @@ mod tests {
363371 #[ test]
364372 fn test_parse_manifest_without_vars ( ) {
365373 let manifest: Manifest = serde_json:: from_str ( TEST_MANIFEST_WITHOUT_VARS ) . unwrap ( ) ;
366- let result = manifest. validate_manifest ( ) ;
374+ let result = manifest. validate_manifest ( ) . unwrap ( ) ;
367375 assert ! ( !result. is_success( ) ) ;
368376
369377 assert ! ( manifest. request. body. is_none( ) ) ; // Optional field we omitted
@@ -376,7 +384,7 @@ mod tests {
376384 #[ test]
377385 fn test_manifest_validation_invalid_method ( ) {
378386 let manifest = create_manifest ! ( request!( method: "INVALID" . to_string( ) ) , response!( ) , ) ;
379- let result = manifest. validate_manifest ( ) ;
387+ let result = manifest. validate_manifest ( ) . unwrap ( ) ;
380388 assert ! ( !result. is_success( ) ) ;
381389 assert ! ( result. values( ) . is_empty( ) ) ;
382390 assert_eq ! ( result. errors. len( ) , 1 ) ;
@@ -386,7 +394,7 @@ mod tests {
386394 #[ test]
387395 fn test_manifest_validation_invalid_url ( ) {
388396 let manifest = create_manifest ! ( request!( url: "ftp://example.com" . to_string( ) ) , response!( ) , ) ;
389- let result = manifest. validate_manifest ( ) ;
397+ let result = manifest. validate_manifest ( ) . unwrap ( ) ;
390398 assert ! ( !result. is_success( ) ) ;
391399 assert ! ( result. values( ) . is_empty( ) ) ;
392400 assert_eq ! ( result. errors. len( ) , 1 ) ;
@@ -396,7 +404,7 @@ mod tests {
396404 #[ test]
397405 fn test_manifest_validation_invalid_response_status ( ) {
398406 let manifest = create_manifest ! ( request!( ) , response!( status: "500" . to_string( ) ) , ) ;
399- let result = manifest. validate_manifest ( ) ;
407+ let result = manifest. validate_manifest ( ) . unwrap ( ) ;
400408 assert ! ( !result. is_success( ) ) ;
401409 assert ! ( result. values( ) . is_empty( ) ) ;
402410 assert_eq ! ( result. errors. len( ) , 1 ) ;
@@ -419,7 +427,7 @@ mod tests {
419427 ) ,
420428 response!( ) ,
421429 ) ;
422- let result = manifest. validate_manifest ( ) ;
430+ let result = manifest. validate_manifest ( ) . unwrap ( ) ;
423431 assert ! ( !result. is_success( ) ) ;
424432 assert ! ( result. values( ) . is_empty( ) ) ;
425433 assert_eq ! ( result. errors. len( ) , 1 ) ;
@@ -437,7 +445,7 @@ mod tests {
437445 ( "Content-Type" . to_string( ) , "invalid/type" . to_string( ) )
438446 ] ) ) ,
439447 ) ;
440- let result = manifest. validate_manifest ( ) ;
448+ let result = manifest. validate_manifest ( ) . unwrap ( ) ;
441449 assert ! ( !result. is_success( ) ) ;
442450 assert ! ( result. values( ) . is_empty( ) ) ;
443451 assert_eq ! ( result. errors. len( ) , 1 ) ;
@@ -660,4 +668,12 @@ mod tests {
660668 assert ! ( !result. is_success( ) ) ;
661669 assert ! ( result. values( ) . is_empty( ) ) ;
662670 }
671+
672+ #[ test]
673+ fn test_manifest_with_a_wrong_version ( ) {
674+ let mut manifest = create_manifest ! ( request!( ) , response!( ) , ) ;
675+ manifest. manifest_version = "1" . to_string ( ) ;
676+ let result = manifest. validate_manifest ( ) ;
677+ assert ! ( result. is_err( ) ) ;
678+ }
663679}
0 commit comments