|
1 | 1 | //! Integration test for COSE decoding part. |
2 | 2 |
|
3 | | -use catalyst_signed_doc::*; |
| 3 | +use catalyst_signed_doc::{providers::tests::TestVerifyingKeyProvider, *}; |
4 | 4 | use catalyst_types::catalyst_id::role_index::RoleId; |
5 | 5 | use common::create_dummy_key_pair; |
6 | 6 | use coset::TaggedCborSerializable; |
@@ -56,9 +56,13 @@ fn catalyst_signed_doc_cbor_roundtrip_kid_as_id_test() { |
56 | 56 | assert!(doc.problem_report().is_problematic()); |
57 | 57 | } |
58 | 58 |
|
59 | | -#[test] |
60 | | -fn catalyst_signed_doc_parameters_aliases_test() { |
| 59 | +#[tokio::test] |
| 60 | +#[allow(clippy::too_many_lines)] |
| 61 | +async fn catalyst_signed_doc_parameters_aliases_test() { |
61 | 62 | let (_, _, metadata_fields) = common::test_metadata(); |
| 63 | + let (sk, pk, kid) = common::create_dummy_key_pair(RoleId::Role0).unwrap(); |
| 64 | + let mut provider = TestVerifyingKeyProvider::default(); |
| 65 | + provider.add_pk(kid.clone(), pk); |
62 | 66 |
|
63 | 67 | let content = serde_json::to_vec(&serde_json::Value::Null).unwrap(); |
64 | 68 |
|
@@ -97,46 +101,58 @@ fn catalyst_signed_doc_parameters_aliases_test() { |
97 | 101 | parameters_val_cbor.clone(), |
98 | 102 | )); |
99 | 103 |
|
100 | | - let doc: CatalystSignedDocument = cose_with_category_id |
101 | | - .to_tagged_vec() |
| 104 | + let cbor_bytes = cose_with_category_id.to_tagged_vec().unwrap(); |
| 105 | + let doc: CatalystSignedDocument = cbor_bytes.as_slice().try_into().unwrap(); |
| 106 | + let doc = doc |
| 107 | + .into_builder() |
| 108 | + .add_signature(|m| sk.sign(&m).to_vec(), &kid) |
102 | 109 | .unwrap() |
103 | | - .as_slice() |
104 | | - .try_into() |
105 | | - .unwrap(); |
| 110 | + .build(); |
106 | 111 | assert!(!doc.problem_report().is_problematic()); |
107 | 112 | assert!(doc.doc_meta().parameters().is_some()); |
| 113 | + assert!(validator::validate_signatures(&doc, &provider) |
| 114 | + .await |
| 115 | + .unwrap()); |
108 | 116 |
|
109 | 117 | // case: `brand_id`. |
110 | | - let mut cose_with_category_id = cose.clone(); |
111 | | - cose_with_category_id.protected.header.rest.push(( |
| 118 | + let mut cose_with_brand_id = cose.clone(); |
| 119 | + cose_with_brand_id.protected.header.rest.push(( |
112 | 120 | coset::Label::Text("brand_id".to_string()), |
113 | 121 | parameters_val_cbor.clone(), |
114 | 122 | )); |
115 | 123 |
|
116 | | - let doc: CatalystSignedDocument = cose_with_category_id |
117 | | - .to_tagged_vec() |
| 124 | + let cbor_bytes = cose_with_brand_id.to_tagged_vec().unwrap(); |
| 125 | + let doc: CatalystSignedDocument = cbor_bytes.as_slice().try_into().unwrap(); |
| 126 | + let doc = doc |
| 127 | + .into_builder() |
| 128 | + .add_signature(|m| sk.sign(&m).to_vec(), &kid) |
118 | 129 | .unwrap() |
119 | | - .as_slice() |
120 | | - .try_into() |
121 | | - .unwrap(); |
| 130 | + .build(); |
122 | 131 | assert!(!doc.problem_report().is_problematic()); |
123 | 132 | assert!(doc.doc_meta().parameters().is_some()); |
| 133 | + assert!(validator::validate_signatures(&doc, &provider) |
| 134 | + .await |
| 135 | + .unwrap()); |
124 | 136 |
|
125 | 137 | // case: `campaign_id`. |
126 | | - let mut cose_with_category_id = cose.clone(); |
127 | | - cose_with_category_id.protected.header.rest.push(( |
| 138 | + let mut cose_with_campaign_id = cose.clone(); |
| 139 | + cose_with_campaign_id.protected.header.rest.push(( |
128 | 140 | coset::Label::Text("campaign_id".to_string()), |
129 | 141 | parameters_val_cbor.clone(), |
130 | 142 | )); |
131 | 143 |
|
132 | | - let doc: CatalystSignedDocument = cose_with_category_id |
133 | | - .to_tagged_vec() |
| 144 | + let cbor_bytes = cose_with_campaign_id.to_tagged_vec().unwrap(); |
| 145 | + let doc: CatalystSignedDocument = cbor_bytes.as_slice().try_into().unwrap(); |
| 146 | + let doc = doc |
| 147 | + .into_builder() |
| 148 | + .add_signature(|m| sk.sign(&m).to_vec(), &kid) |
134 | 149 | .unwrap() |
135 | | - .as_slice() |
136 | | - .try_into() |
137 | | - .unwrap(); |
| 150 | + .build(); |
138 | 151 | assert!(!doc.problem_report().is_problematic()); |
139 | 152 | assert!(doc.doc_meta().parameters().is_some()); |
| 153 | + assert!(validator::validate_signatures(&doc, &provider) |
| 154 | + .await |
| 155 | + .unwrap()); |
140 | 156 |
|
141 | 157 | // `parameters` value along with its aliases are not allowed to be present at the |
142 | 158 | let mut cose_with_category_id = cose.clone(); |
|
0 commit comments