Skip to content
Merged
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
22 changes: 14 additions & 8 deletions rust/signed_doc/src/validator/rules/ownership/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
38 changes: 38 additions & 0 deletions rust/signed_doc/src/validator/rules/ownership/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -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)));
}