@@ -22,6 +22,68 @@ struct TestCase {
2222 post_checks : Option < Box < PostCheck > > ,
2323}
2424
25+ fn signed_doc_deprecated_doc_ref_case ( field_name : & ' static str ) -> TestCase {
26+ let uuid_v7 = UuidV7 :: new ( ) ;
27+ let doc_type = DocType :: from ( UuidV4 :: new ( ) ) ;
28+ let doc_ref = DocumentRef :: new ( UuidV7 :: new ( ) , UuidV7 :: new ( ) , DocLocator :: default ( ) ) ;
29+ TestCase {
30+ name : format ! (
31+ "Catalyst Signed Doc with deprecated {field_name} version before v0.04 validating."
32+ ) ,
33+ bytes_gen : Box :: new ( {
34+ move || {
35+ let mut e = Encoder :: new ( Vec :: new ( ) ) ;
36+ e. tag ( Tag :: new ( 98 ) ) ?;
37+ e. array ( 4 ) ?;
38+
39+ // protected headers (metadata fields)
40+ e. bytes ( {
41+ let mut p_headers = Encoder :: new ( Vec :: new ( ) ) ;
42+ p_headers. map ( 5 ) ?;
43+ p_headers. u8 ( 3 ) ?. encode ( ContentType :: Json ) ?;
44+ p_headers
45+ . str ( "id" ) ?
46+ . encode_with ( uuid_v7, & mut catalyst_types:: uuid:: CborContext :: Tagged ) ?;
47+ p_headers
48+ . str ( "ver" ) ?
49+ . encode_with ( uuid_v7, & mut catalyst_types:: uuid:: CborContext :: Tagged ) ?;
50+ p_headers. str ( "type" ) ?. encode ( & doc_type) ?;
51+ p_headers. str ( field_name) ?;
52+ p_headers. array ( 2 ) ?;
53+ p_headers. encode_with (
54+ doc_ref. id ( ) ,
55+ & mut catalyst_types:: uuid:: CborContext :: Tagged ,
56+ ) ?;
57+ p_headers. encode_with (
58+ doc_ref. ver ( ) ,
59+ & mut catalyst_types:: uuid:: CborContext :: Tagged ,
60+ ) ?;
61+
62+ p_headers. into_writer ( ) . as_slice ( )
63+ } ) ?;
64+
65+ // empty unprotected headers
66+ e. map ( 0 ) ?;
67+ // content
68+ e. bytes ( serde_json:: to_vec ( & serde_json:: Value :: Null ) ?. as_slice ( ) ) ?;
69+ // zero signatures
70+ e. array ( 0 ) ?;
71+
72+ Ok ( e)
73+ }
74+ } ) ,
75+ policy : CompatibilityPolicy :: Accept ,
76+ can_decode : true ,
77+ valid_doc : true ,
78+ post_checks : Some ( Box :: new ( {
79+ move |doc| {
80+ anyhow:: ensure!( doc. is_deprecated( ) ?) ;
81+ Ok ( ( ) )
82+ }
83+ } ) ) ,
84+ }
85+ }
86+
2587fn signed_doc_with_valid_alias_case ( alias : & ' static str ) -> TestCase {
2688 let uuid_v7 = UuidV7 :: new ( ) ;
2789 let doc_type = DocType :: from ( UuidV4 :: new ( ) ) ;
@@ -537,6 +599,7 @@ fn signed_doc_with_minimal_metadata_fields_case() -> TestCase {
537599 doc. encoded_content( ) == serde_json:: to_vec( & serde_json:: Value :: Null ) ?
538600 ) ;
539601 anyhow:: ensure!( doc. kids( ) . len( ) == 1 ) ;
602+ anyhow:: ensure!( !doc. is_deprecated( ) ?) ;
540603 Ok ( ( ) )
541604 }
542605 } ) ) ,
@@ -622,6 +685,7 @@ fn signed_doc_with_complete_metadata_fields_case() -> TestCase {
622685 anyhow:: ensure!( doc. doc_content_type( ) ? == ContentType :: Json ) ;
623686 anyhow:: ensure!( doc. encoded_content( ) == serde_json:: to_vec( & serde_json:: Value :: Null ) ?) ;
624687 anyhow:: ensure!( doc. kids( ) . len( ) == 1 ) ;
688+ anyhow:: ensure!( !doc. is_deprecated( ) ?) ;
625689 Ok ( ( ) )
626690 }
627691 } ) ) ,
@@ -1240,6 +1304,13 @@ fn signed_doc_with_non_supported_protected_signature_header_invalid() -> TestCas
12401304fn catalyst_signed_doc_decoding_test ( ) {
12411305 let test_cases = [
12421306 decoding_empty_bytes_case ( ) ,
1307+ signed_doc_deprecated_doc_ref_case ( "template" ) ,
1308+ signed_doc_deprecated_doc_ref_case ( "ref" ) ,
1309+ signed_doc_deprecated_doc_ref_case ( "reply" ) ,
1310+ signed_doc_deprecated_doc_ref_case ( "parameters" ) ,
1311+ signed_doc_deprecated_doc_ref_case ( "category_id" ) ,
1312+ signed_doc_deprecated_doc_ref_case ( "brand_id" ) ,
1313+ signed_doc_deprecated_doc_ref_case ( "campaign_id" ) ,
12431314 signed_doc_with_minimal_metadata_fields_case ( ) ,
12441315 signed_doc_with_complete_metadata_fields_case ( ) ,
12451316 signed_doc_valid_null_as_no_content ( ) ,
0 commit comments