-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signal invalid CBOR through new status tracking path
- Loading branch information
1 parent
6a4a7cc
commit ef95c5f
Showing
8 changed files
with
156 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,3 +12,4 @@ | |
// each license. | ||
|
||
mod signer_payload; | ||
mod validation_errors; |
61 changes: 61 additions & 0 deletions
61
cawg_identity/src/tests/identity_assertion/validation_errors.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 std::io::Cursor; | ||
|
||
use c2pa::Reader; | ||
use c2pa_status_tracker::{LogKind, StatusTracker}; | ||
#[cfg(target_arch = "wasm32")] | ||
use wasm_bindgen_test::wasm_bindgen_test; | ||
|
||
use crate::IdentityAssertion; | ||
|
||
#[cfg_attr(not(target_arch = "wasm32"), tokio::test)] | ||
#[cfg_attr( | ||
all(target_arch = "wasm32", not(target_os = "wasi")), | ||
wasm_bindgen_test | ||
)] | ||
#[cfg_attr(target_os = "wasi", wstd::test)] | ||
async fn malformed_cbor() { | ||
let format = "image/jpeg"; | ||
let test_image = include_bytes!("../fixtures/validation_errors/malformed_cbor.jpg"); | ||
|
||
let mut test_image = Cursor::new(test_image); | ||
|
||
// Initial read with default `Reader` should pass without issues. | ||
let reader = Reader::from_stream(format, &mut test_image).unwrap(); | ||
assert_eq!(reader.validation_status(), None); | ||
|
||
// Re-parse with identity assertion code should find malformed CBOR error. | ||
let mut status_tracker = StatusTracker::default(); | ||
|
||
let active_manifest = reader.active_manifest().unwrap(); | ||
let ia_results: Vec<Result<IdentityAssertion, c2pa::Error>> = | ||
IdentityAssertion::from_manifest(active_manifest, &mut status_tracker).collect(); | ||
|
||
assert_eq!(ia_results.len(), 1); | ||
|
||
let ia_err = ia_results[0].as_ref().unwrap_err(); | ||
assert_eq!(ia_err.to_string(), "could not decode assertion cawg.identity (version (no version), content type application/json): missing field `signer_payload`"); | ||
|
||
assert_eq!(status_tracker.logged_items().len(), 1); | ||
|
||
let log = &status_tracker.logged_items()[0]; | ||
assert_eq!(log.kind, LogKind::Failure); | ||
assert_eq!(log.label, "cawg.identity"); | ||
assert_eq!(log.description, "invalid CBOR"); | ||
assert_eq!( | ||
log.validation_status.as_ref().unwrap().as_ref(), | ||
"cawg.identity.cbor.invalid" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters