Skip to content

Commit 47577a6

Browse files
ChainRule mutual exclusive with the CollaboratorsRule
1 parent bbc0a5d commit 47577a6

File tree

3 files changed

+64
-7
lines changed

3 files changed

+64
-7
lines changed

rust/signed_doc/src/validator/rules/chain/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
33
use catalyst_signed_doc_spec::{is_required::IsRequired, metadata::chain::Chain};
44

5-
use crate::{CatalystSignedDocument, providers::CatalystSignedDocumentProvider};
5+
use crate::{
6+
CatalystSignedDocument, providers::CatalystSignedDocumentProvider,
7+
validator::rules::CollaboratorsRule,
8+
};
69

710
#[cfg(test)]
811
mod tests;
@@ -34,10 +37,12 @@ impl ChainRule {
3437
}
3538

3639
/// Field validation rule
40+
#[allow(clippy::too_many_lines)]
3741
pub(crate) async fn check<Provider>(
3842
&self,
3943
doc: &CatalystSignedDocument,
4044
provider: &Provider,
45+
collaborators_rule: &CollaboratorsRule,
4146
) -> anyhow::Result<bool>
4247
where
4348
Provider: CatalystSignedDocumentProvider,
@@ -136,6 +141,14 @@ impl ChainRule {
136141
}
137142
}
138143
}
144+
145+
if let CollaboratorsRule::Specified { .. } = collaborators_rule {
146+
doc.report().functional_validation(
147+
"Chained Documents do not support collaborators",
148+
"Chained Documents validation",
149+
);
150+
return Ok(false);
151+
}
139152
}
140153
if let Self::NotSpecified = self
141154
&& chain.is_some()

rust/signed_doc/src/validator/rules/chain/tests.rs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,49 @@ async fn test_without_chaining_documents() {
4141
.build();
4242

4343
let rule = ChainRule::NotSpecified;
44-
assert!(rule.check(&doc, &provider).await.unwrap());
44+
let collaborators_rule = CollaboratorsRule::NotSpecified;
45+
46+
assert!(
47+
rule.check(&doc, &provider, &collaborators_rule)
48+
.await
49+
.unwrap()
50+
);
4551
let rule = ChainRule::Specified { optional: true };
46-
assert!(rule.check(&doc, &provider).await.unwrap());
52+
assert!(
53+
rule.check(&doc, &provider, &collaborators_rule)
54+
.await
55+
.unwrap()
56+
);
4757
let rule = ChainRule::Specified { optional: false };
48-
assert!(!rule.check(&doc, &provider).await.unwrap());
58+
assert!(
59+
!rule
60+
.check(&doc, &provider, &collaborators_rule)
61+
.await
62+
.unwrap()
63+
);
64+
}
65+
66+
#[tokio::test]
67+
async fn chain_rule_collaborators_rule_conflict() {
68+
let doc_type = UuidV4::new();
69+
let doc_id = UuidV7::new();
70+
let doc_ver = UuidV7::new();
71+
72+
let provider = TestCatalystProvider::default();
73+
let doc = Builder::new()
74+
.with_metadata_field(SupportedField::Type(DocType::from(doc_type)))
75+
.with_metadata_field(SupportedField::Id(doc_id))
76+
.with_metadata_field(SupportedField::Ver(doc_ver))
77+
.build();
78+
79+
let rule = ChainRule::Specified { optional: true };
80+
let collaborators_rule = CollaboratorsRule::Specified { optional: true };
81+
assert!(
82+
!rule
83+
.check(&doc, &provider, &collaborators_rule)
84+
.await
85+
.unwrap()
86+
);
4987
}
5088

5189
#[test_case(
@@ -131,8 +169,11 @@ async fn test_valid_chained_documents(
131169
(provider, doc): (TestCatalystProvider, CatalystSignedDocument)
132170
) -> bool {
133171
let rule = ChainRule::Specified { optional: false };
172+
let collaborators_rule = CollaboratorsRule::NotSpecified;
134173

135-
rule.check(&doc, &provider).await.unwrap()
174+
rule.check(&doc, &provider, &collaborators_rule)
175+
.await
176+
.unwrap()
136177
}
137178

138179
#[test_case(
@@ -278,6 +319,9 @@ async fn test_invalid_chained_documents(
278319
(provider, doc): (TestCatalystProvider, CatalystSignedDocument)
279320
) -> bool {
280321
let rule = ChainRule::Specified { optional: false };
322+
let collaborators_rule = CollaboratorsRule::NotSpecified;
281323

282-
rule.check(&doc, &provider).await.unwrap()
324+
rule.check(&doc, &provider, &collaborators_rule)
325+
.await
326+
.unwrap()
283327
}

rust/signed_doc/src/validator/rules/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl Rules {
9898
self.reply.check(doc, provider).boxed(),
9999
self.section.check(doc).boxed(),
100100
self.parameters.check(doc, provider).boxed(),
101-
self.chain.check(doc, provider).boxed(),
101+
self.chain.check(doc, provider, &self.collaborators).boxed(),
102102
self.collaborators.check(doc).boxed(),
103103
self.content.check(doc).boxed(),
104104
self.kid.check(doc).boxed(),

0 commit comments

Comments
 (0)