Skip to content

Commit dcec86f

Browse files
authored
Update dependencies: mockito 1.7.0, base64 modern API + github actions (#12)
1 parent 2f0a988 commit dcec86f

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

.github/workflows/scorecard.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ jobs:
3535

3636
steps:
3737
- name: "Checkout code"
38-
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
38+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3939
with:
4040
persist-credentials: false
4141

4242
- name: "Run analysis"
43-
uses: ossf/scorecard-action@62b2cac7ed8198b15735ed49ab1e5cf35480ba46 # v2.4.0
43+
uses: ossf/scorecard-action@05b42c624433fc40578a4040d5cf5e36ddca8cde # v2.4.2
4444
with:
4545
results_file: results.sarif
4646
results_format: sarif

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ serde_json = "1.0"
1818
url = { version = "2.5.4", features = ["serde"] }
1919
uuid = { version = "1.10.1", features = ["v4"] }
2020
time = { version = "0.3.36", features = ["serde"] }
21-
serde_with = { version = "2", features = ["time_0_3"] }
21+
serde_with = { version = "3", features = ["time_0_3"] }
2222
reqwest = { version = "0.12.5", features = ["blocking"] }
2323
openssl = "0.10.72"
2424
openssl-sys = "0.9.103"
2525
ring = "0.17.12"
2626
coset = "^0.3.5"
2727
hex = "0.4"
28-
base64 = "0.13"
28+
base64 = "0.22"
2929
chrono = { version = "0.4", features = ["serde"] }
3030

3131
[dev-dependencies]
32-
mockito = "0.31.0"
32+
mockito = "1.7.0"

src/manifest.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ use crate::claim::{validate_claim_v2, ClaimV2};
9595
pub use crate::cross_reference::CrossReference;
9696
use crate::datetime_wrapper::OffsetDateTimeWrapper;
9797
use crate::ingredient::{validate_ingredient, Ingredient};
98+
use base64::{engine::general_purpose, Engine as _};
9899
use openssl::pkey::PKey;
99100
use openssl::sign::Verifier;
100101
use serde::{Deserialize, Serialize};
@@ -265,7 +266,8 @@ fn extract_signature_from_manifest(manifest_bytes: &[u8]) -> Result<Vec<u8>, Str
265266
// Check if claim_v2 is present
266267
if let Some(claim_v2) = manifest.claim_v2 {
267268
if let Some(signature) = claim_v2.signature {
268-
let signature_bytes = base64::decode(signature)
269+
let signature_bytes = general_purpose::STANDARD
270+
.decode(signature)
269271
.map_err(|e| format!("Failed to decode signature: {e}"))?;
270272
return Ok(signature_bytes);
271273
} else {
@@ -274,8 +276,9 @@ fn extract_signature_from_manifest(manifest_bytes: &[u8]) -> Result<Vec<u8>, Str
274276
}
275277

276278
if let Some(signature) = manifest.claim.signature {
277-
let signature_bytes =
278-
base64::decode(signature).map_err(|e| format!("Failed to decode signature: {e}"))?;
279+
let signature_bytes = general_purpose::STANDARD
280+
.decode(signature)
281+
.map_err(|e| format!("Failed to decode signature: {e}"))?;
279282
Ok(signature_bytes)
280283
} else {
281284
Err("Signature field is missing in claim.".to_string())

tests/test_dataset.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ use atlas_c2pa_lib::assertion::{
22
Action, ActionAssertion, Assertion, Author, CreativeWorkAssertion,
33
};
44
use atlas_c2pa_lib::asset_type::AssetType;
5-
use atlas_c2pa_lib::claim::ClaimV2; // Using ClaimV2
5+
use atlas_c2pa_lib::claim::ClaimV2;
66
use atlas_c2pa_lib::datetime_wrapper::OffsetDateTimeWrapper;
77
use atlas_c2pa_lib::ingredient::{Ingredient, IngredientData};
88
use atlas_c2pa_lib::manifest::Manifest;
9-
use mockito::mock;
9+
use mockito::Server;
1010
use openssl::sha::sha256;
1111
use std::fs;
1212
use time::OffsetDateTime;
13+
1314
#[test]
1415
fn test_dataset_manifest_creation_v2() {
16+
let mut server = Server::new();
1517
let claim_generator = "c2pa-ml/0.1.0".to_string();
1618

1719
let file_paths = [
@@ -21,18 +23,20 @@ fn test_dataset_manifest_creation_v2() {
2123
];
2224

2325
let mut ingredients = vec![];
26+
let mut mocks = vec![]; // Store mocks to keep them alive
2427

2528
for (i, file_path) in file_paths.iter().enumerate() {
2629
let file_content = fs::read(file_path).expect("Failed to read test file");
2730

28-
let mock = mock("GET", format!("/dataset_file_{i}").as_str())
31+
let mock = server
32+
.mock("GET", format!("/dataset_file_{i}").as_str())
2933
.with_status(200)
3034
.with_header("content-type", "application/octet-stream")
3135
.with_body(file_content.clone())
3236
.create();
3337

3438
let ingredient_data = IngredientData {
35-
url: mockito::server_url() + &format!("/dataset_file_{i}"),
39+
url: server.url() + &format!("/dataset_file_{i}"),
3640
alg: "sha256".to_string(),
3741
hash: "".to_string(),
3842
data_types: vec![AssetType::Dataset],
@@ -76,6 +80,7 @@ fn test_dataset_manifest_creation_v2() {
7680
};
7781

7882
ingredients.push(ingredient);
83+
mocks.push(mock); // Keep mock alive
7984
}
8085

8186
let creative_work_assertion = Assertion::CreativeWork(CreativeWorkAssertion {

tests/test_linking_ingredients.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use atlas_c2pa_lib::claim::ClaimV2;
33
use atlas_c2pa_lib::datetime_wrapper::OffsetDateTimeWrapper;
44
use atlas_c2pa_lib::ingredient::{Ingredient, IngredientData, LinkedIngredient};
55
use atlas_c2pa_lib::manifest::Manifest;
6-
use mockito::mock;
6+
use mockito::Server;
77
use openssl::sha::sha256;
88
use time::OffsetDateTime;
99

1010
#[test]
1111
fn test_ingredient_linking_with_verification() {
12+
let mut server = Server::new(); // Create a new mock server
1213
let claim_generator = "c2pa-ml/0.1.0".to_string();
1314

1415
// Fixed timestamp for consistent hashing
@@ -22,14 +23,14 @@ fn test_ingredient_linking_with_verification() {
2223

2324
// Linked ingredient (that itself is a reference to another dataset or model)
2425
let linked_ingredient = LinkedIngredient {
25-
url: mockito::server_url() + "/linked_ingredient.json",
26+
url: server.url() + "/linked_ingredient.json",
2627
hash: "ab82708c91050a674c1b12e2d48f4b2dced1dd25b1132d3f59460ec39ecce664".to_string(), // We'll verify this later
2728
media_type: "application/json".to_string(),
2829
};
2930

3031
// Main ingredient with a link to another ingredient
3132
let ingredient_data = IngredientData {
32-
url: mockito::server_url() + "/ingredient.json",
33+
url: server.url() + "/ingredient.json",
3334
alg: "sha256".to_string(),
3435
hash: "ingredient_hash".to_string(),
3536
data_types: vec![AssetType::ModelOpenVino],
@@ -78,14 +79,16 @@ fn test_ingredient_linking_with_verification() {
7879
let _manifest_hash = hex::encode(sha256(manifest_json.as_bytes()));
7980

8081
// Mock the HTTP server to return the linked ingredient
81-
let linked_ingredient_mock = mock("GET", "/linked_ingredient.json")
82+
let linked_ingredient_mock = server
83+
.mock("GET", "/linked_ingredient.json")
8284
.with_status(200)
8385
.with_header("content-type", "application/json")
8486
.with_body("{ \"ingredient\": \"linked\" }") // Simulated linked ingredient
8587
.create();
8688

8789
// Mock the HTTP server to return the ingredient
88-
let ingredient_mock = mock("GET", "/ingredient.json")
90+
let ingredient_mock = server
91+
.mock("GET", "/ingredient.json")
8992
.with_status(200)
9093
.with_header("content-type", "application/json")
9194
.with_body(manifest_json.clone()) // Return the serialized manifest

tests/test_manifest.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,33 @@ use atlas_c2pa_lib::assertion::{
22
Action, ActionAssertion, Assertion, Author, CreativeWorkAssertion,
33
};
44
use atlas_c2pa_lib::asset_type::AssetType;
5-
use atlas_c2pa_lib::claim::ClaimV2; // Updated to use ClaimV2
5+
use atlas_c2pa_lib::claim::ClaimV2;
66
use atlas_c2pa_lib::datetime_wrapper::OffsetDateTimeWrapper;
77
use atlas_c2pa_lib::ingredient::{Ingredient, IngredientData};
88
use atlas_c2pa_lib::manifest::Manifest;
9-
use mockito::mock;
9+
use mockito::Server;
1010
use openssl::sha::sha256;
1111
use std::fs;
1212
use time::OffsetDateTime;
1313

1414
#[test]
1515
fn test_manifest_creation_v2() {
16+
let mut server = Server::new(); // Create a new mock server
1617
let claim_generator = "c2pa-ml/0.1.0".to_string();
1718

1819
let file_path = "tests/test_data/model.bin";
1920
let file_content = fs::read(file_path).expect("Failed to read test file");
2021

2122
// Mock the server to expect a GET request to /model.file
22-
let mock = mock("GET", "/model.file")
23+
let mock = server
24+
.mock("GET", "/model.file")
2325
.with_status(200)
2426
.with_header("content-type", "application/octet-stream")
2527
.with_body(file_content.clone())
2628
.create();
2729

2830
let ingredient_data = IngredientData {
29-
url: mockito::server_url() + "/model.file",
31+
url: server.url() + "/model.file",
3032
alg: "sha256".to_string(),
3133
hash: "".to_string(),
3234
data_types: vec![AssetType::ModelOpenVino],

tests/test_manifest_cross_ref.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@ use atlas_c2pa_lib::claim::ClaimV2;
66
use atlas_c2pa_lib::datetime_wrapper::OffsetDateTimeWrapper;
77
use atlas_c2pa_lib::ingredient::{Ingredient, IngredientData};
88
use atlas_c2pa_lib::manifest::{CrossReference, Manifest};
9-
use mockito::mock;
9+
use mockito::Server;
1010
use openssl::sha::sha256;
1111
use time::OffsetDateTime;
1212

1313
#[test]
1414
fn test_cross_manifest_linking() {
15+
let mut server = Server::new(); // Create a new mock server
1516
let claim_generator = "c2pa-ml/0.1.0".to_string();
1617

1718
let fixed_timestamp = OffsetDateTimeWrapper(
@@ -45,14 +46,15 @@ fn test_cross_manifest_linking() {
4546

4647
let linked_manifest_hash = hex::encode(sha256(linked_manifest_json.as_bytes()));
4748

48-
let linked_manifest_mock = mock("GET", "/linked_manifest.json")
49+
let linked_manifest_mock = server
50+
.mock("GET", "/linked_manifest.json")
4951
.with_status(200)
5052
.with_header("content-type", "application/json")
5153
.with_body(linked_manifest_json.clone()) // Fixed linked manifest
5254
.create();
5355

5456
let ingredient_data = IngredientData {
55-
url: mockito::server_url() + "/model.file",
57+
url: server.url() + "/model.file",
5658
alg: "sha256".to_string(),
5759
hash: "4e4fc7c4587ee5d5fa73f0b679e2d3549b5b0101fc556df783445a6db8b4161f".to_string(),
5860
data_types: vec![AssetType::ModelOpenVino],
@@ -118,7 +120,7 @@ fn test_cross_manifest_linking() {
118120
}),
119121
created_at: fixed_timestamp.clone(),
120122
cross_references: vec![CrossReference {
121-
manifest_url: mockito::server_url() + "/linked_manifest.json",
123+
manifest_url: server.url() + "/linked_manifest.json",
122124
manifest_hash: linked_manifest_hash.clone(),
123125
media_type: Some("application/json".to_string()),
124126
}],

0 commit comments

Comments
 (0)