Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion rust/signed_doc/src/validator/rules/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

use catalyst_signed_doc_spec::{is_required::IsRequired, metadata::chain::Chain};

use crate::{CatalystSignedDocument, providers::CatalystSignedDocumentProvider};
use crate::{
CatalystSignedDocument, providers::CatalystSignedDocumentProvider,
validator::rules::CollaboratorsRule,
};

#[cfg(test)]
mod tests;
Expand Down Expand Up @@ -34,10 +37,12 @@ impl ChainRule {
}

/// Field validation rule
#[allow(clippy::too_many_lines)]
pub(crate) async fn check<Provider>(
&self,
doc: &CatalystSignedDocument,
provider: &Provider,
collaborators_rule: &CollaboratorsRule,
) -> anyhow::Result<bool>
where
Provider: CatalystSignedDocumentProvider,
Expand Down Expand Up @@ -136,6 +141,14 @@ impl ChainRule {
}
}
}

if let CollaboratorsRule::Specified { .. } = collaborators_rule {
doc.report().functional_validation(
"Chained Documents do not support collaborators",
"Chained Documents validation",
);
return Ok(false);
}
}
if let Self::NotSpecified = self
&& chain.is_some()
Expand Down
54 changes: 49 additions & 5 deletions rust/signed_doc/src/validator/rules/chain/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,49 @@ async fn test_without_chaining_documents() {
.build();

let rule = ChainRule::NotSpecified;
assert!(rule.check(&doc, &provider).await.unwrap());
let collaborators_rule = CollaboratorsRule::NotSpecified;

assert!(
rule.check(&doc, &provider, &collaborators_rule)
.await
.unwrap()
);
let rule = ChainRule::Specified { optional: true };
assert!(rule.check(&doc, &provider).await.unwrap());
assert!(
rule.check(&doc, &provider, &collaborators_rule)
.await
.unwrap()
);
let rule = ChainRule::Specified { optional: false };
assert!(!rule.check(&doc, &provider).await.unwrap());
assert!(
!rule
.check(&doc, &provider, &collaborators_rule)
.await
.unwrap()
);
}

#[tokio::test]
async fn chain_rule_collaborators_rule_conflict() {
let doc_type = UuidV4::new();
let doc_id = UuidV7::new();
let doc_ver = UuidV7::new();

let provider = TestCatalystProvider::default();
let doc = Builder::new()
.with_metadata_field(SupportedField::Type(DocType::from(doc_type)))
.with_metadata_field(SupportedField::Id(doc_id))
.with_metadata_field(SupportedField::Ver(doc_ver))
.build();

let rule = ChainRule::Specified { optional: true };
let collaborators_rule = CollaboratorsRule::Specified { optional: true };
assert!(
!rule
.check(&doc, &provider, &collaborators_rule)
.await
.unwrap()
);
}

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

rule.check(&doc, &provider).await.unwrap()
rule.check(&doc, &provider, &collaborators_rule)
.await
.unwrap()
}

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

rule.check(&doc, &provider).await.unwrap()
rule.check(&doc, &provider, &collaborators_rule)
.await
.unwrap()
}
2 changes: 1 addition & 1 deletion rust/signed_doc/src/validator/rules/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Rules {
self.reply.check(doc, provider).boxed(),
self.section.check(doc).boxed(),
self.parameters.check(doc, provider).boxed(),
self.chain.check(doc, provider).boxed(),
self.chain.check(doc, provider, &self.collaborators).boxed(),
self.collaborators.check(doc).boxed(),
self.content.check(doc).boxed(),
self.kid.check(doc).boxed(),
Expand Down