Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(cawg_identity): Refactor boilerplate code for manifest and parent JSON in test cases #949

Merged
merged 1 commit into from
Feb 28, 2025
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
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()
}
Loading