Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 3 additions & 6 deletions rust/signed_doc/src/validator/rules/collaborators/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ impl CatalystSignedDocumentValidationRule for CollaboratorsRule {
doc: &CatalystSignedDocument,
_provider: &dyn Provider,
) -> anyhow::Result<bool> {
Ok(self.check_inner(doc))
self.check_inner(doc);
Ok(!doc.report().is_problematic())
}
}

Expand All @@ -49,7 +50,7 @@ impl CollaboratorsRule {
fn check_inner(
&self,
doc: &CatalystSignedDocument,
) -> bool {
) {
if let Self::Specified { optional } = self
&& doc.doc_meta().collaborators().is_empty()
&& !optional
Expand All @@ -58,7 +59,6 @@ impl CollaboratorsRule {
"collaborators",
"Document must have at least one entry in 'collaborators' field",
);
return false;
}
if let Self::NotSpecified = self
&& !doc.doc_meta().collaborators().is_empty()
Expand All @@ -75,9 +75,6 @@ impl CollaboratorsRule {
),
"Document does not expect to have a 'collaborators' field",
);
return false;
}

true
}
}
21 changes: 12 additions & 9 deletions rust/signed_doc/src/validator/rules/collaborators/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{

#[test_case(
|| {
Builder::new()
Builder::with_required_fields()
.with_metadata_field(SupportedField::Collaborators(
vec![create_dummy_key_pair(RoleId::Role0).1].into()
))
Expand All @@ -20,7 +20,7 @@ use crate::{
)]
#[test_case(
|| {
Builder::new().build()
Builder::with_required_fields().build()
}
=> true
;
Expand All @@ -31,12 +31,13 @@ fn section_rule_specified_optional_test(doc_gen: impl FnOnce() -> CatalystSigned
let rule = CollaboratorsRule::Specified { optional: true };

let doc = doc_gen();
rule.check_inner(&doc)
rule.check_inner(&doc);
!doc.report().is_problematic()
}

#[test_case(
|| {
Builder::new()
Builder::with_required_fields()
.with_metadata_field(SupportedField::Collaborators(
vec![create_dummy_key_pair(RoleId::Role0).1].into()
))
Expand All @@ -48,7 +49,7 @@ fn section_rule_specified_optional_test(doc_gen: impl FnOnce() -> CatalystSigned
)]
#[test_case(
|| {
Builder::new().build()
Builder::with_required_fields().build()
}
=> false
;
Expand All @@ -61,20 +62,21 @@ fn section_rule_specified_not_optional_test(
let rule = CollaboratorsRule::Specified { optional: false };

let doc = doc_gen();
rule.check_inner(&doc)
rule.check_inner(&doc);
!doc.report().is_problematic()
}

#[test_case(
|| {
Builder::new().build()
Builder::with_required_fields().build()
}
=> true
;
"missing 'collaborators' field"
)]
#[test_case(
|| {
Builder::new()
Builder::with_required_fields()
.with_metadata_field(SupportedField::Collaborators(
vec![create_dummy_key_pair(RoleId::Role0).1].into()
))
Expand All @@ -89,5 +91,6 @@ fn section_rule_not_specified_test(doc_gen: impl FnOnce() -> CatalystSignedDocum
let rule = CollaboratorsRule::NotSpecified;

let doc = doc_gen();
rule.check_inner(&doc)
rule.check_inner(&doc);
!doc.report().is_problematic()
}
Loading