diff --git a/rust/signed_doc/src/validator/rules/ownership/mod.rs b/rust/signed_doc/src/validator/rules/ownership/mod.rs index 65f238b737..c7565a653c 100644 --- a/rust/signed_doc/src/validator/rules/ownership/mod.rs +++ b/rust/signed_doc/src/validator/rules/ownership/mod.rs @@ -91,20 +91,26 @@ impl DocumentOwnershipRule { Self::OriginalAuthor => { // only run check for the non first version of the document if doc_id != doc.doc_ver()? { - let first_doc = provider - .try_get_first_doc(doc_id) - .await? - .ok_or(anyhow::anyhow!("cannot get a first version document"))?; + let Some(first_doc) = provider.try_get_first_doc(doc_id).await? else { + doc.report().other( + "Cannot find a first version of the referenced document", + REPORT_CONTEXT, + ); + return Ok(false); + }; allowed_authors.extend(first_doc.authors()); } }, Self::CollaboratorsFieldBased => { // only run check for the non first version of the document if doc_id != doc.doc_ver()? { - let first_doc = provider - .try_get_first_doc(doc_id) - .await? - .ok_or(anyhow::anyhow!("cannot get a first version document"))?; + let Some(first_doc) = provider.try_get_first_doc(doc_id).await? else { + doc.report().other( + "Cannot find a first version of the referenced document", + REPORT_CONTEXT, + ); + return Ok(false); + }; allowed_authors.extend(first_doc.authors()); let last_doc = provider.try_get_last_doc(doc_id).await?.ok_or( diff --git a/rust/signed_doc/src/validator/rules/ownership/tests/mod.rs b/rust/signed_doc/src/validator/rules/ownership/tests/mod.rs index 156ee8ad29..ada28b665e 100644 --- a/rust/signed_doc/src/validator/rules/ownership/tests/mod.rs +++ b/rust/signed_doc/src/validator/rules/ownership/tests/mod.rs @@ -1,5 +1,43 @@ //! Ownership Validation Rule testing +use catalyst_types::{catalyst_id::role_index::RoleId, uuid::UuidV7}; +use ed25519_dalek::ed25519::signature::Signer; + +use crate::{ + builder::tests::Builder, + metadata::SupportedField, + providers::tests::TestCatalystProvider, + validator::rules::{DocumentOwnershipRule, utils::create_dummy_key_pair}, +}; + mod collaborators_field_based; mod ref_field_based; mod without_collaborators; + +#[tokio::test] +async fn empty_provider_test() { + let provider = TestCatalystProvider::default(); + + let (a_sk, a_kid) = create_dummy_key_pair(RoleId::Role0); + let id = UuidV7::new(); + let ver = UuidV7::new(); + let doc = Builder::new() + .with_metadata_field(SupportedField::Id(id)) + .with_metadata_field(SupportedField::Ver(ver)) + .add_signature(|m| a_sk.sign(&m).to_vec(), a_kid.clone()) + .unwrap() + .build(); + + let result = DocumentOwnershipRule::OriginalAuthor + .check_inner(&doc, &provider) + .await; + assert!(matches!(result, Ok(false))); + let result = DocumentOwnershipRule::RefFieldBased + .check_inner(&doc, &provider) + .await; + assert!(matches!(result, Ok(false))); + let result = DocumentOwnershipRule::CollaboratorsFieldBased + .check_inner(&doc, &provider) + .await; + assert!(matches!(result, Ok(false))); +}