diff options
| author | tv <tv@krebsco.de> | 2026-12-01 05:13:36 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-12-01 05:13:36 +0000 |
| commit | 60da3a663ed070c1e6c5d2a1b171e316a0395bbd (patch) | |
| tree | c11fcce3cb5480413dce3d1aefa7d05b681b3df6 /tests | |
| parent | cd06c0a8ed52e9c251a5f2c0debb6f263ce74705 (diff) | |
enstate: --pack --dry-run, every problem of a source list
Reads every source and writes nothing: every problem, not just the
first, by address, with kind, location and variables, and the source,
as text or JSON (--json): an item the schema has no slot for, a record
in a type without records, a required slot without an item, a location
that doesn't exist, a source that can't be read (with what it said), a
record that isn't JSON. Exit status 1 if there are problems. --pack
itself refuses with the same list; --out isn't for a dry run, --json
only for one. The completion offers accordingly.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/receptor.rs | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/tests/receptor.rs b/tests/receptor.rs index 170fbae..061e23f 100644 --- a/tests/receptor.rs +++ b/tests/receptor.rs @@ -742,3 +742,95 @@ fn pack_from_locations() { "{said}" ); } + +/// `--pack --dry-run`: every problem, by address, with location and variables, as text +/// or JSON; nothing written; and --pack refuses with all of them. +#[test] +fn pack_dry_run() { + let host = Host::new("dry-run"); + let _ = host.schema(secrets_schema(&host)); + // A store that has a.pub, and nothing else. + let secrets = host.program( + "secrets", + r#"if [ "$2" = a.pub ]; then echo pub-of-K; else echo "Error: $2 is not in the password store." >&2; exit 1; fi"#, + ); + let sources = host.root.join("sources.json"); + std::fs::write( + &sources, + json!({ + "channel": "secrets", + "complete": true, + "locations": { "secrets": { "source": { "command": [secrets, "show", "$(var:key)"] } } }, + "items": { + "a.key": { "location": "secrets", "key": "a.key" }, + "a.pub": { "location": "secrets", "key": "a.pub" }, + "nope": { "source": "env:PATH" } + } + }) + .to_string(), + ) + .unwrap(); + let enstate = |arguments: &[&str]| { + let output = Command::new(env!("CARGO_BIN_EXE_enstate")) + .args(arguments) + .arg(format!( + "--schema={}", + host.root.join("schema.json").display() + )) + .output() + .unwrap(); + ( + output.status.code(), + String::from_utf8_lossy(&output.stdout).into_owned(), + String::from_utf8_lossy(&output.stderr).into_owned(), + ) + }; + let path = sources.to_str().unwrap(); + let (code, stdout, stderr) = enstate(&["--pack", path, "--dry-run"]); + assert_eq!(code, Some(1), "{stderr}"); + assert!( + stdout.contains("secrets/a.key (location secrets, key a.key): can't be read:") + && stdout.contains("is not in the password store") + && stdout.contains("secrets/nope: the schema has no slot secrets/nope") + && stdout.contains("channel secrets: 3 items, 2 problems"), + "{stdout}" + ); + let (code, stdout, _) = enstate(&["--pack", path, "--dry-run", "--json"]); + assert_eq!(code, Some(1)); + let report: Value = serde_json::from_str(&stdout).unwrap(); + let problems = report["problems"].as_array().unwrap(); + assert_eq!(problems.len(), 2, "{report}"); + let key = problems + .iter() + .find(|p| p["address"] == "secrets/a.key") + .unwrap(); + assert_eq!(key["problem"], "unreadable"); + assert_eq!(key["location"], "secrets"); + assert_eq!(key["variables"], json!({ "key": "a.key" })); + assert!( + key["source"].as_str().unwrap().contains("show $(var:key)"), + "{key}" + ); + assert!(problems.iter().any(|p| p["problem"] == "not-in-schema")); + // Nothing written; and the real thing refuses with both. + let out = host.root.join("packed"); + let (code, _, stderr) = enstate(&["--pack", path, "--out", out.to_str().unwrap()]); + assert_eq!(code, Some(2)); + assert!( + stderr.contains("can't make a submission") + && stderr.contains("secrets/a.key") + && stderr.contains("secrets/nope"), + "{stderr}" + ); + assert!(!out.exists()); + // Options not for a dry run. + let (code, _, stderr) = enstate(&["--pack", path, "--dry-run", "--out", "x"]); + assert_eq!(code, Some(2)); + assert!(stderr.contains("--out is not for a dry run"), "{stderr}"); + let (code, _, stderr) = enstate(&["--pack", path, "--json", "--out", "x"]); + assert_eq!(code, Some(2)); + assert!( + stderr.contains("--json is for --pack only with --dry-run"), + "{stderr}" + ); +} |
