Skip to content

Commit

Permalink
chore(cawg_identity): Refactor boilerplate code for manifest and pare…
Browse files Browse the repository at this point in the history
…nt JSON in test cases (#949)

Refactor boilerplate code for manifest and parent JSON in test cases
  • Loading branch information
scouten-adobe authored Feb 28, 2025
1 parent da13c79 commit 85f97b5
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 104 deletions.
56 changes: 4 additions & 52 deletions cawg_identity/src/tests/builder/simple_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use std::io::{Cursor, Seek};

use c2pa::{Builder, Reader, SigningAlg};
use serde_json::json;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test;

Expand All @@ -23,7 +22,10 @@ use crate::{
AsyncIdentityAssertionBuilder, AsyncIdentityAssertionSigner, IdentityAssertionBuilder,
IdentityAssertionSigner,
},
tests::fixtures::{NaiveAsyncCredentialHolder, NaiveCredentialHolder, NaiveSignatureVerifier},
tests::fixtures::{
manifest_json, parent_json, NaiveAsyncCredentialHolder, NaiveCredentialHolder,
NaiveSignatureVerifier,
},
IdentityAssertion, ToCredentialSummary,
};

Expand Down Expand Up @@ -141,53 +143,3 @@ async fn simple_case_async() {
let nc_json = serde_json::to_string(&nc_summary).unwrap();
assert_eq!(nc_json, "{}");
}

fn manifest_json() -> String {
json!({
"vendor": "test",
"claim_generator_info": [
{
"name": "c2pa_test",
"version": "1.0.0"
}
],
"metadata": [
{
"dateTime": "1985-04-12T23:20:50.52Z",
"my_custom_metadata": "my custom metatdata value"
}
],
"title": "Test_Manifest",
"format": "image/tiff",
"instance_id": "1234",
"thumbnail": {
"format": "image/jpeg",
"identifier": "thumbnail.jpg"
},
"ingredients": [
{
"title": "Test",
"format": "image/jpeg",
"instance_id": "12345",
"relationship": "componentOf"
}
],
"assertions": [
{
"label": "org.test.assertion",
"data": "assertion"
}
]
})
.to_string()
}

fn parent_json() -> String {
json!({
"title": "Parent Test",
"format": "image/jpeg",
"instance_id": "12345",
"relationship": "parentOf"
})
.to_string()
}
65 changes: 65 additions & 0 deletions cawg_identity/src/tests/fixtures/manifest_json.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2025 Adobe. All rights reserved.
// This file is licensed to you under the Apache License,
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
// or the MIT license (http://opensource.org/licenses/MIT),
// at your option.

// Unless required by applicable law or agreed to in writing,
// this software is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
// specific language governing permissions and limitations under
// each license.

use serde_json::json;

/// Boilerplate JSON to use when building manifests for test cases.
pub(crate) fn manifest_json() -> String {
json!({
"vendor": "test",
"claim_generator_info": [
{
"name": "c2pa_test",
"version": "1.0.0"
}
],
"metadata": [
{
"dateTime": "1985-04-12T23:20:50.52Z",
"my_custom_metadata": "my custom metatdata value"
}
],
"title": "Test_Manifest",
"format": "image/tiff",
"instance_id": "1234",
"thumbnail": {
"format": "image/jpeg",
"identifier": "thumbnail.jpg"
},
"ingredients": [
{
"title": "Test",
"format": "image/jpeg",
"instance_id": "12345",
"relationship": "componentOf"
}
],
"assertions": [
{
"label": "org.test.assertion",
"data": "assertion"
}
]
})
.to_string()
}

pub(crate) fn parent_json() -> String {
json!({
"title": "Parent Test",
"format": "image/jpeg",
"instance_id": "12345",
"relationship": "parentOf"
})
.to_string()
}
3 changes: 3 additions & 0 deletions cawg_identity/src/tests/fixtures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#![allow(unused)]

mod manifest_json;
pub(crate) use manifest_json::{manifest_json, parent_json};

mod naive_credential_holder;
pub(crate) use naive_credential_holder::{
NaiveAsyncCredentialHolder, NaiveCredentialHolder, NaiveSignatureVerifier,
Expand Down
53 changes: 1 addition & 52 deletions cawg_identity/src/tests/x509.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@ use std::io::{Cursor, Seek};

use c2pa::{Builder, Reader, SigningAlg};
use c2pa_crypto::raw_signature;
use serde_json::json;
#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))]
use wasm_bindgen_test::wasm_bindgen_test;

use crate::{
builder::{AsyncIdentityAssertionBuilder, AsyncIdentityAssertionSigner},
tests::fixtures::cert_chain_and_private_key_for_alg,
tests::fixtures::{cert_chain_and_private_key_for_alg, manifest_json, parent_json},
x509::{X509CredentialHolder, X509SignatureVerifier},
IdentityAssertion,
};
Expand Down Expand Up @@ -97,53 +96,3 @@ async fn simple_case() {

// TO DO: Not sure what to check from COSE_Sign1.
}

fn manifest_json() -> String {
json!({
"vendor": "test",
"claim_generator_info": [
{
"name": "c2pa_test",
"version": "1.0.0"
}
],
"metadata": [
{
"dateTime": "1985-04-12T23:20:50.52Z",
"my_custom_metadata": "my custom metatdata value"
}
],
"title": "Test_Manifest",
"format": "image/tiff",
"instance_id": "1234",
"thumbnail": {
"format": "image/jpeg",
"identifier": "thumbnail.jpg"
},
"ingredients": [
{
"title": "Test",
"format": "image/jpeg",
"instance_id": "12345",
"relationship": "componentOf"
}
],
"assertions": [
{
"label": "org.test.assertion",
"data": "assertion"
}
]
})
.to_string()
}

fn parent_json() -> String {
json!({
"title": "Parent Test",
"format": "image/jpeg",
"instance_id": "12345",
"relationship": "parentOf"
})
.to_string()
}

0 comments on commit 85f97b5

Please sign in to comment.