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
140 changes: 140 additions & 0 deletions rust/signed_doc/tests/brand_parameters.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
//! Integration test for brand parameters document validation part.
//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/docs/brand_parameters>

use catalyst_signed_doc::{providers::tests::TestCatalystProvider, *};
use catalyst_types::catalyst_id::role_index::RoleId;
use ed25519_dalek::ed25519::signature::Signer;
use test_case::test_case;

use crate::common::{
brand_parameters_doc, brand_parameters_form_template_doc, create_dummy_key_pair,
};

mod common;

#[test_case(
|provider| {
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
brand_parameters_doc(&template, provider)
}
=> true
;
"valid document"
)]
#[test_case(
|provider| {
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
let id = UuidV7::new();
let (sk, _, kid) = create_dummy_key_pair(RoleId::Role0)
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
Builder::new()
.with_json_metadata(serde_json::json!({
"content-type": ContentType::Json,
"content-encoding": ContentEncoding::Brotli,
"id": id,
"ver": id,
"type": doc_types::BRAND_PARAMETERS.clone(),
"template": {
"id": template.doc_id()?,
"ver": template.doc_ver()?,
},
}))?
.with_json_content(&serde_json::json!({}))?
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
.build()
}
=> false
;
"wrong role"
)]
#[test_case(
|provider| {
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
let id = UuidV7::new();
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
Builder::new()
.with_json_metadata(serde_json::json!({
"content-type": ContentType::Json,
"content-encoding": ContentEncoding::Brotli,
"id": id,
"ver": id,
"type": doc_types::BRAND_PARAMETERS.clone(),
"template": {
"id": template.doc_id()?,
"ver": template.doc_ver()?,
},
}))?
.empty_content()?
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
.build()
}
=> false
;
"empty content"
)]
#[test_case(
|provider| {
let template = brand_parameters_form_template_doc(provider).inspect(|v| provider.add_document(None, v).unwrap())?;
let id = UuidV7::new();
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
Builder::new()
.with_json_metadata(serde_json::json!({
"content-type": ContentType::Json,
"content-encoding": ContentEncoding::Brotli,
"id": id,
"ver": id,
"type": doc_types::BRAND_PARAMETERS.clone(),
"template": {
"id": template.doc_id()?,
"ver": template.doc_ver()?,
},
}))?
.with_json_content(&serde_json::json!({}))?
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
.build()
}
=> true
;
"missing 'content-encoding' (optional)"
)]
#[test_case(
|provider| {
let id = UuidV7::new();
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
Builder::new()
.with_json_metadata(serde_json::json!({
"content-type": ContentType::Json,
"content-encoding": ContentEncoding::Brotli,
"id": id,
"ver": id,
"type": doc_types::BRAND_PARAMETERS.clone(),
}))?
.with_json_content(&serde_json::json!({}))?
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
.build()
}
=> false
;
"missing 'template'"
)]
#[tokio::test]
#[allow(clippy::unwrap_used)]
async fn test_brand_parameters_doc(
doc_gen: impl FnOnce(&mut TestCatalystProvider) -> anyhow::Result<CatalystSignedDocument>
) -> bool {
let mut provider = TestCatalystProvider::default();

let doc = doc_gen(&mut provider).unwrap();
assert_eq!(
*doc.doc_type().unwrap(),
doc_types::BRAND_PARAMETERS.clone()
);

let is_valid = validator::validate(&doc, &provider).await.unwrap();
assert_eq!(is_valid, !doc.problem_report().is_problematic());
println!("{:?}", doc.problem_report());
is_valid
}
100 changes: 100 additions & 0 deletions rust/signed_doc/tests/brand_parameters_form_template.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//! Integration test for brand parameters form template document validation part.
//! <https://input-output-hk.github.io/catalyst-libs/architecture/08_concepts/signed_doc/docs/brand_parameters_form_template>

use catalyst_signed_doc::{providers::tests::TestCatalystProvider, *};
use catalyst_types::catalyst_id::role_index::RoleId;
use ed25519_dalek::ed25519::signature::Signer;
use test_case::test_case;

use crate::common::{brand_parameters_form_template_doc, create_dummy_key_pair};

mod common;

#[test_case(
|provider| {
brand_parameters_form_template_doc(provider)
}
=> true
;
"valid document"
)]
#[test_case(
|provider| {
let id = UuidV7::new();
let (sk, _, kid) = create_dummy_key_pair(RoleId::Role0)
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
Builder::new()
.with_json_metadata(serde_json::json!({
"content-type": ContentType::SchemaJson,
"content-encoding": ContentEncoding::Brotli,
"id": id,
"ver": id,
"type": doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone(),
}))?
.with_json_content(&serde_json::json!({}))?
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
.build()
}
=> false
;
"wrong role"
)]
#[test_case(
|provider| {
let id = UuidV7::new();
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
Builder::new()
.with_json_metadata(serde_json::json!({
"content-type": ContentType::SchemaJson,
"content-encoding": ContentEncoding::Brotli,
"id": id,
"ver": id,
"type": doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone(),
}))?
.empty_content()?
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
.build()
}
=> false
;
"empty content"
)]
#[test_case(
|provider| {
let id = UuidV7::new();
let (sk, _, kid) = create_dummy_key_pair(RoleId::BrandAdmin)
.inspect(|(_, pk, kid)| provider.add_pk(kid.clone(), *pk))?;
Builder::new()
.with_json_metadata(serde_json::json!({
"content-type": ContentType::SchemaJson,
"id": id,
"ver": id,
"type": doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone(),
}))?
.with_json_content(&serde_json::json!({}))?
.add_signature(|m| sk.sign(&m).to_vec(), kid)?
.build()
}
=> true
;
"missing 'content-encoding' (optional)"
)]
#[tokio::test]
#[allow(clippy::unwrap_used)]
async fn test_brand_parameters_form_template_doc(
doc_gen: impl FnOnce(&mut TestCatalystProvider) -> anyhow::Result<CatalystSignedDocument>
) -> bool {
let mut provider = TestCatalystProvider::default();

let doc = doc_gen(&mut provider).unwrap();
assert_eq!(
*doc.doc_type().unwrap(),
doc_types::BRAND_PARAMETERS_FORM_TEMPLATE.clone()
);

let is_valid = validator::validate(&doc, &provider).await.unwrap();
assert_eq!(is_valid, !doc.problem_report().is_problematic());
println!("{:?}", doc.problem_report());
is_valid
}
Loading
Loading