c2patool 0.26.51

Tool for displaying and creating C2PA manifests.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
// Copyright 2022 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.

#![cfg(not(target_os = "wasi"))]
use std::{
    error::Error,
    fs::{self, create_dir_all},
    path::PathBuf,
    process::Command,
};

// Add methods on commands
use assert_cmd::{cargo, prelude::*};
use httpmock::{prelude::*, Mock};
use predicate::str;
use predicates::prelude::*;
use serde_json::Value;
use tempfile::tempdir;

const TEST_IMAGE: &str = "earth_apollo17.jpg";
//const TEST_IMAGE: &str = "libpng-test.png"; // save for png testing
const TEST_IMAGE_WITH_MANIFEST: &str = "C.jpg"; // save for manifest tests

fn fixture_path(name: &str) -> PathBuf {
    let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    path.push("tests/fixtures");
    path.push(name);
    fs::canonicalize(path).expect("canonicalize")
}

fn temp_path(name: &str) -> PathBuf {
    let path = PathBuf::from(env!("CARGO_TARGET_TMPDIR"));
    create_dir_all(&path).ok();
    path.join(name)
}
#[test]
fn tool_not_found() -> Result<(), Box<dyn Error>> {
    let mut cmd = Command::new(cargo::cargo_bin!("c2patool"));
    cmd.arg("test/file/notfound.jpg");
    cmd.assert().failure().stderr(str::contains("os error"));
    Ok(())
}
#[test]
fn tool_not_found_info() -> Result<(), Box<dyn Error>> {
    let mut cmd = Command::new(cargo::cargo_bin!("c2patool"));
    cmd.arg("test/file/notfound.jpg").arg("--info");
    cmd.assert()
        .failure()
        .stderr(str::contains("file not found"));
    Ok(())
}
#[test]
fn tool_jpeg_no_report() -> Result<(), Box<dyn Error>> {
    let mut cmd = Command::new(cargo::cargo_bin!("c2patool"));
    cmd.arg(fixture_path(TEST_IMAGE));
    cmd.assert()
        .failure()
        .stderr(str::contains("No claim found"));
    Ok(())
}

#[test]
// c2patool tests/fixtures/C.jpg --info
fn tool_info() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("--info")
        .assert()
        .success()
        .stdout(str::contains(
            "Provenance URI = self#jumbf=/c2pa/contentauth:urn:uuid:",
        ))
        .stdout(str::contains("Manifest store size = 51217"));
    Ok(())
}

#[test]
fn tool_embed_jpeg_report() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE))
        .arg("-m")
        .arg("sample/test.json")
        .arg("-p")
        .arg(fixture_path(TEST_IMAGE))
        .arg("-o")
        .arg(temp_path("out.jpg"))
        .arg("-f")
        .assert()
        .success() // should this be a failure?
        .stdout(str::contains("My Title"));
    Ok(())
}
#[test]
fn tool_fs_output_report() -> Result<(), Box<dyn Error>> {
    let path = temp_path("output_dir");
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path("verify.jpeg"))
        .arg("-o")
        .arg(&path)
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains(format!(
            "Manifest report written to the directory {path:?}"
        )));
    let manifest_json = path.join("manifest_store.json");
    let contents = fs::read_to_string(manifest_json)?;
    let json: Value = serde_json::from_str(&contents)?;
    assert_eq!(
        json.as_object()
            .unwrap()
            .get("active_manifest")
            .unwrap()
            .as_str()
            .unwrap(),
        "adobe:urn:uuid:df1d2745-5beb-4d6c-bd99-3527e29c7df0",
    );
    Ok(())
}
#[test]
fn tool_fs_output_report_supports_detailed_flag() -> Result<(), Box<dyn Error>> {
    let path = temp_path("./output_detailed");
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path("verify.jpeg"))
        .arg("-o")
        .arg(&path)
        .arg("-f")
        .arg("-d")
        .assert()
        .success()
        .stdout(str::contains(format!(
            "Manifest report written to the directory {path:?}"
        )));
    let manifest_json = path.join("detailed.json");
    let contents = fs::read_to_string(manifest_json)?;
    let json: Value = serde_json::from_str(&contents)?;
    assert!(json
        .as_object()
        .unwrap()
        .get("validation_results")
        .is_some());
    Ok(())
}
#[test]
fn tool_fs_output_fails_when_output_exists() -> Result<(), Box<dyn Error>> {
    let path = temp_path("./output_conflict");
    // Create conflict directory.
    create_dir_all(&path)?;
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path("C.jpg"))
        .arg("-o")
        .arg(&path)
        .assert()
        .failure()
        .stderr(str::contains(
            "Error: Output already exists; use -f/force to force write",
        ));
    Ok(())
}
#[test]
// c2patool tests/fixtures/C.jpg -fo target/tmp/manifest_test
fn tool_test_manifest_folder() -> Result<(), Box<dyn std::error::Error>> {
    let out_path = temp_path("manifest_test");
    // first export a c2pa file
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("-o")
        .arg(&out_path)
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains("Manifest report written"));
    // then read it back in
    let json =
        std::fs::read_to_string(out_path.join("manifest_store.json")).expect("read manifest");
    dbg!(&json);
    assert!(json.contains("make_test_images"));
    Ok(())
}
#[test]
// c2patool tests/fixtures/C.jpg -ifo target/tmp/ingredient_test
fn tool_test_ingredient_folder() -> Result<(), Box<dyn std::error::Error>> {
    let out_path = temp_path("ingredient_test");
    // first export a c2pa file
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("-o")
        .arg(&out_path)
        .arg("--ingredient")
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains("Ingredient report written"));
    // then read it back in
    let json = std::fs::read_to_string(out_path.join("ingredient.json")).expect("read manifest");
    assert!(json.contains("manifest_data"));
    Ok(())
}
#[test]
// c2patool tests/fixtures/C.jpg -ifo target/tmp/ingredient_json
// c2patool tests/fixtures/earth_apollo17.jpg -m sample/test.json -p target/tmp/ingredient_json/ingredient.json -fo target/tmp/out_2.jpg
fn tool_test_manifest_ingredient_json() -> Result<(), Box<dyn std::error::Error>> {
    let out_path = temp_path("ingredient_json");
    // first export a c2pa file
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("-o")
        .arg(&out_path)
        .arg("--ingredient")
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains("Ingredient report written"));
    let json_path = out_path.join("ingredient.json");
    let parent = json_path.to_string_lossy().to_string();
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE))
        .arg("-p")
        .arg(parent)
        .arg("-m")
        .arg("sample/test.json")
        .arg("-o")
        .arg(temp_path("out_2.jpg"))
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains("My Title"));
    Ok(())
}
#[test]
// c2patool tests/fixtures/earth_apollo17.jpg -m tests/fixtures/ingredient_test.json -o target/tmp/ingredients.jpg -f
fn tool_embed_jpeg_with_ingredients_report() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE))
        .arg("-m")
        .arg(fixture_path("ingredient_test.json"))
        .arg("-o")
        .arg(temp_path("ingredients.jpg"))
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains("ingredients.jpg"))
        .stdout(str::contains("test ingredient"))
        .stdout(str::contains("temporal"))
        .stdout(str::contains("earth_apollo17.jpg"));
    Ok(())
}
#[test]
fn tool_extensions_do_not_match() -> Result<(), Box<dyn Error>> {
    let path = temp_path("./foo.png");
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path("C.jpg"))
        .arg("-m")
        .arg(fixture_path("ingredient_test.json"))
        .arg("-o")
        .arg(&path)
        .assert()
        .failure()
        .stderr(str::contains("Output type must match source type"));
    Ok(())
}
#[test]
fn tool_similar_extensions_match() -> Result<(), Box<dyn Error>> {
    let path = temp_path("./similar.JpEg");
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path("C.jpg"))
        .arg("-m")
        .arg(fixture_path("ingredient_test.json"))
        .arg("-o")
        .arg(&path)
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains("similar."));
    Ok(())
}
#[test]
fn tool_fail_if_thumbnail_missing() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE))
        .arg("-c")
        .arg("{\"thumbnail\": {\"identifier\": \"thumb.jpg\",\"format\": \"image/jpeg\"}}")
        .arg("-o")
        .arg(temp_path("out_thumb.jpg"))
        .arg("-f")
        .assert()
        .failure()
        .stderr(str::contains("resource not found"));
    Ok(())
}

#[test]
fn tool_sign_to_same_file_with_force() -> Result<(), Box<dyn Error>> {
    let tmp_dir = tempdir()?;
    let file_path = tmp_dir.path().join("same_image.jpg");
    fs::copy(fixture_path(TEST_IMAGE), &file_path)?;

    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(&file_path)
        .arg("-m")
        .arg(fixture_path("ingredient_test.json"))
        .arg("-o")
        .arg(&file_path)
        .arg("-f")
        .assert()
        .success()
        .stdout(str::contains("same_image.jpg"))
        .stdout(str::contains("test ingredient"))
        .stdout(str::contains("temporal"))
        .stdout(str::contains("earth_apollo17.jpg"));
    Ok(())
}

#[test]
fn tool_sign_to_same_file_no_force() -> Result<(), Box<dyn Error>> {
    let tmp_dir = tempdir()?;
    let file_path = tmp_dir.path().join("same_image.jpg");
    fs::copy(fixture_path(TEST_IMAGE), &file_path)?;

    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(&file_path)
        .arg("-m")
        .arg(fixture_path("ingredient_test.json"))
        .arg("-o")
        .arg(&file_path)
        .assert()
        .failure()
        .stderr(str::contains(
            "Error: Output already exists; use -f/force to force write",
        ));

    Ok(())
}
// #[test]
// fn test_succeed_using_example_signer() -> Result<(), Box<dyn Error>> {
//     let output = temp_path("./output_external.jpg");
//     // We are calling a cargo/bin here that successfully signs claim bytes. We are using
//     // a cargo/bin because it works on all OSs, we like Rust, and our example external signing
//     // code is compiled and verified during every test of this project.
//     let mut successful_process = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
//     successful_process.push("target/debug/signer-path-success");
//     Command::cargo_bin("c2patool")?
//         .arg(fixture_path("earth_apollo17.jpg"))
//         .arg("--signer-path")
//         .arg(&successful_process)
//         .arg("--reserve-size")
//         .arg("20248")
//         .arg("--manifest")
//         .arg("sample/test.json")
//         .arg("-o")
//         .arg(&output)
//         .arg("-f")
//         .assert()
//         .success();
//     Ok(())
// }
// #[test]
// fn test_fails_for_not_found_external_signer() -> Result<(), Box<dyn Error>> {
//     let output = temp_path("./output_external.jpg");
//     Command::cargo_bin("c2patool")?
//         .arg(fixture_path("earth_apollo17.jpg"))
//         .arg("--signer-path")
//         .arg("./executable-not-found-test")
//         .arg("--reserve-size")
//         .arg("10248")
//         .arg("--manifest")
//         .arg("sample/test.json")
//         .arg("-o")
//         .arg(&output)
//         .arg("-f")
//         .assert()
//         .stderr(str::contains("Failed to run command at"))
//         .failure();
//     Ok(())
// }
// #[test]
// fn test_fails_for_external_signer_failure() -> Result<(), Box<dyn Error>> {
//     let output = temp_path("./output_external.jpg");
//     let mut failing_process = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
//     failing_process.push("target/debug/signer-path-fail");
//     Command::cargo_bin("c2patool")?
//         .arg(fixture_path("earth_apollo17.jpg"))
//         .arg("--signer-path")
//         .arg(&failing_process)
//         .arg("--reserve-size")
//         .arg("20248")
//         .arg("--manifest")
//         .arg("sample/test.json")
//         .arg("-o")
//         .arg(&output)
//         .arg("-f")
//         .assert()
//         .stderr(str::contains("User supplied signer process failed"))
//         // Ensures stderr from user executable is revealed to client.
//         .stderr(str::contains("signer-path-fail-stderr"))
//         .failure();
//     Ok(())
// }
// #[test]
// fn test_fails_for_external_signer_success_without_stdout() -> Result<(), Box<dyn Error>> {
//     let output = temp_path("./output_external.jpg");
//     let mut failing_process = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
//     failing_process.push("target/debug/signer-path-no-stdout");
//     Command::cargo_bin("c2patool")?
//         .arg(fixture_path("earth_apollo17.jpg"))
//         .arg("--signer-path")
//         .arg(&failing_process)
//         .arg("--reserve-size")
//         .arg("10248")
//         .arg("--manifest")
//         .arg("sample/test.json")
//         .arg("-o")
//         .arg(&output)
//         .arg("-f")
//         .assert()
//         .stderr(str::contains("User supplied process succeeded, but the external process did not write signature bytes to stdout"))
//         .failure();
//     Ok(())
// }

#[test]
// c2patool tests/fixtures/C.jpg trust --trust_anchors=tests/fixtures/trust/anchors.pem --trust_config=tests/fixtures/trust/store.cfg
fn tool_load_trust_settings_from_file_trusted() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("trust")
        .arg("--trust_anchors")
        .arg(fixture_path("trust/anchors.pem"))
        .arg("--trust_config")
        .arg(fixture_path("trust/store.cfg"))
        .assert()
        .success()
        .stdout(str::contains("C2PA Test Signing Cert"))
        .stdout(str::contains("signingCredential.untrusted").not());
    Ok(())
}

#[test]
// c2patool tests/fixtures/C.jpg trust --trust_anchors=tests/fixtures/trust/no-match.pem --trust_config=tests/fixtures/trust/store.cfg
fn tool_load_trust_settings_from_file_untrusted() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("trust")
        .arg("--trust_anchors")
        .arg(fixture_path("trust/no-match.pem"))
        .arg("--trust_config")
        .arg(fixture_path("trust/store.cfg"))
        .assert()
        .success()
        .stdout(str::contains("C2PA Test Signing Cert"))
        .stdout(str::contains("signingCredential.untrusted"));
    Ok(())
}

fn create_mock_server<'a>(
    server: &'a MockServer,
    anchor_source: &str,
    config_source: &str,
) -> Vec<Mock<'a>> {
    let anchor_path = fixture_path(anchor_source).to_str().unwrap().to_owned();
    let trust_mock = server.mock(|when, then| {
        when.method(GET).path("/trust/anchors.pem");
        then.status(200)
            .header("content-type", "text/plain")
            .body_from_file(anchor_path);
    });
    let config_path = fixture_path(config_source).to_str().unwrap().to_owned();
    let config_mock = server.mock(|when, then| {
        when.method(GET).path("/trust/store.cfg");
        then.status(200)
            .header("content-type", "text/plain")
            .body_from_file(config_path);
    });

    vec![trust_mock, config_mock]
}

#[test]
fn tool_load_trust_settings_from_url_arg_trusted() -> Result<(), Box<dyn Error>> {
    let server = MockServer::start();
    let mocks = create_mock_server(&server, "trust/anchors.pem", "trust/store.cfg");

    // Test flags
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("trust")
        .arg("--trust_anchors")
        .arg(server.url("/trust/anchors.pem"))
        .arg("--trust_config")
        .arg(server.url("/trust/store.cfg"))
        .assert()
        .success()
        .stdout(str::contains("C2PA Test Signing Cert"))
        .stdout(str::contains("signingCredential.untrusted").not());

    mocks.iter().for_each(|m| m.assert());

    Ok(())
}

#[test]
fn tool_load_trust_settings_from_url_arg_untrusted() -> Result<(), Box<dyn Error>> {
    let server = MockServer::start();
    let mocks = create_mock_server(&server, "trust/no-match.pem", "trust/store.cfg");

    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("trust")
        .arg("--trust_anchors")
        .arg(server.url("/trust/anchors.pem"))
        .arg("--trust_config")
        .arg(server.url("/trust/store.cfg"))
        .assert()
        .success()
        .stdout(str::contains("C2PA Test Signing Cert"))
        .stdout(str::contains("signingCredential.untrusted"));

    mocks.iter().for_each(|m| m.assert());

    Ok(())
}

#[test]
fn tool_load_trust_settings_from_url_env_trusted() -> Result<(), Box<dyn Error>> {
    let server = MockServer::start();
    let mocks = create_mock_server(&server, "trust/anchors.pem", "trust/store.cfg");

    // Test flags
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("trust")
        .env("C2PATOOL_TRUST_ANCHORS", server.url("/trust/anchors.pem"))
        .env("C2PATOOL_TRUST_CONFIG", server.url("/trust/store.cfg"))
        .assert()
        .success()
        .stdout(str::contains("C2PA Test Signing Cert"))
        .stdout(str::contains("signingCredential.untrusted").not());

    mocks.iter().for_each(|m| m.assert());

    Ok(())
}

#[test]
fn tool_load_trust_settings_from_url_env_untrusted() -> Result<(), Box<dyn Error>> {
    let server = MockServer::start();
    let mocks = create_mock_server(&server, "trust/no-match.pem", "trust/store.cfg");

    // Test flags
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("trust")
        .env("C2PATOOL_TRUST_ANCHORS", server.url("/trust/anchors.pem"))
        .env("C2PATOOL_TRUST_CONFIG", server.url("/trust/store.cfg"))
        .assert()
        .success()
        .stdout(str::contains("C2PA Test Signing Cert"))
        .stdout(str::contains("signingCredential.untrusted"));

    mocks.iter().for_each(|m| m.assert());

    Ok(())
}

#[test]
// c2patool tests/fixtures/C.jpg --tree
fn tool_tree() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .arg("--tree")
        .assert()
        .success()
        .stdout(str::contains("Asset:C.jpg, Manifest:contentauth:urn:uuid:"))
        .stdout(str::contains("Assertion:c2pa.actions"));
    Ok(())
}

#[test]
// c2patool --settings .../trust/cawg_test_settings.toml C_with_CAWG_data.jpg
fn tool_read_image_with_cawg_data() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg("--settings")
        .arg(fixture_path("trust/cawg_test_settings.toml"))
        .arg(fixture_path("C_with_CAWG_data.jpg"))
        .assert()
        .success()
        .stdout(str::contains("cawg.identity"))
        .stdout(str::contains("c2pa.assertions/cawg.training-mining"))
        .stdout(str::contains("cawg.identity.well-formed"));
    Ok(())
}

#[test]
// c2patool --settings .../trust/cawg_test_settings.toml --detailed C_with_CAWG_data.jpg
fn tool_read_image_with_details_with_cawg_data() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg("--settings")
        .arg(fixture_path("trust/cawg_test_settings.toml"))
        .arg(fixture_path("C_with_CAWG_data.jpg"))
        .arg("--detailed")
        .assert()
        .success()
        .stdout(str::contains("assertion_store"))
        .stdout(str::contains("cawg.identity"))
        .stdout(str::contains("c2pa.assertions/cawg.training-mining"))
        .stdout(str::contains("cawg.identity.well-formed"));
    Ok(())
}

#[test]
// c2patool --settings .../trust/cawg_test_settings.toml C_with_CAWG_data.jpg
fn tool_sign_image_with_cawg_data() -> Result<(), Box<dyn Error>> {
    let tmp_dir = tempdir()?;
    let file_path = tmp_dir.path().join("same_image.jpg");
    fs::copy(fixture_path(TEST_IMAGE), &file_path)?;

    let output_path = tmp_dir.path().join("same_image_cawg_signed.jpg");

    Command::new(cargo::cargo_bin!("c2patool"))
        .arg("--settings")
        .arg(fixture_path("trust/cawg_sign_settings.toml"))
        .arg(&file_path)
        .arg("-m")
        .arg(fixture_path("ingredient_test.json"))
        .arg("-o")
        .arg(&output_path)
        .arg("-f")
        .assert()
        .success();

    Command::new(cargo::cargo_bin!("c2patool"))
        .arg("--settings")
        .arg(fixture_path("trust/cawg_sign_settings.toml"))
        .arg(&output_path)
        .assert()
        .success()
        .stdout(str::contains("cawg.identity"))
        .stdout(str::contains("c2pa.assertions/cawg.training-mining"));
    // .stdout(str::contains("cawg.identity.well-formed"));
    // ^^ Enable this when #1356 lands.
    Ok(())
}

#[test]
// c2patool --crjson C.jpg
fn tool_read_image_crjson() -> Result<(), Box<dyn Error>> {
    Command::new(cargo::cargo_bin!("c2patool"))
        .arg("--crjson")
        .arg(fixture_path(TEST_IMAGE_WITH_MANIFEST))
        .assert()
        .success()
        .stdout(str::contains("\"jsonGenerator\""))
        .stdout(str::contains("https://c2pa.org/crjson"));
    Ok(())
}