deny_unknown_fields on every config struct. [enforcement] mode, EnforcementMode and mask-entire-file are gone, and on_parse_error defaults to allow. New settings on_unparsed_read and on_mask_write, default deny, read by later blocks. SecretsConfig::load stays strict for the channel filter. load_or_default skips only the layers that fail, so a typo keeps the other layers and the default list. Hooks note the broken layer and any skipped() secret file beside output that shows text, not beside every Write (shows_text). Under deny the refusal is unchanged. fermata check exits 2 with the line number. A non-UTF-8 layer counts as a failed layer; a layer whose bytes cannot be read stays silent, as pinned.
72 lines
2.2 KiB
Rust
72 lines
2.2 KiB
Rust
use assert_cmd::Command;
|
|
use predicates::prelude::*;
|
|
use std::fs;
|
|
|
|
#[test]
|
|
fn check_blocks_botignore_match() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
fs::write(tmp.path().join(".botignore"), ".env\n").unwrap();
|
|
let target = tmp.path().join(".env");
|
|
fs::write(&target, "").unwrap();
|
|
|
|
Command::cargo_bin("fermata")
|
|
.unwrap()
|
|
.args(["check", "--op", "read", target.to_str().unwrap()])
|
|
.assert()
|
|
.failure()
|
|
.code(1)
|
|
.stdout(predicate::str::contains(".env"));
|
|
}
|
|
|
|
#[test]
|
|
fn check_allows_unmatched() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
fs::write(tmp.path().join(".botignore"), ".env\n").unwrap();
|
|
let target = tmp.path().join("src.rs");
|
|
fs::write(&target, "").unwrap();
|
|
|
|
Command::cargo_bin("fermata")
|
|
.unwrap()
|
|
.args(["check", "--op", "read", target.to_str().unwrap()])
|
|
.assert()
|
|
.success();
|
|
}
|
|
|
|
#[test]
|
|
fn check_emits_json_with_flag() {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
fs::write(tmp.path().join(".botignore"), ".env\n").unwrap();
|
|
let target = tmp.path().join(".env");
|
|
fs::write(&target, "").unwrap();
|
|
|
|
let out = Command::cargo_bin("fermata")
|
|
.unwrap()
|
|
.args(["check", "--op", "read", "--json", target.to_str().unwrap()])
|
|
.assert()
|
|
.failure()
|
|
.get_output()
|
|
.stdout
|
|
.clone();
|
|
let v: serde_json::Value = serde_json::from_slice(&out).unwrap();
|
|
assert_eq!(v["kind"], "deny");
|
|
}
|
|
|
|
#[test]
|
|
fn check_exits_2_and_names_the_line_of_a_broken_config() {
|
|
for (config, line) in [("[polcy]\nread = 1\n", 1), ("[files]\n[polcy]\nread = 1\n", 2), ("[enforcement]\nmode = \"strict\"\n", 2)] {
|
|
let tmp = tempfile::tempdir().unwrap();
|
|
let home = tempfile::tempdir().unwrap();
|
|
fs::write(tmp.path().join(".botsecrets"), config).unwrap();
|
|
let target = tmp.path().join("a.txt");
|
|
fs::write(&target, "").unwrap();
|
|
|
|
Command::cargo_bin("fermata")
|
|
.unwrap()
|
|
.args(["check", "--op", "read", target.to_str().unwrap()])
|
|
.env("HOME", home.path())
|
|
.assert()
|
|
.code(2)
|
|
.stderr(predicate::str::contains(".botsecrets").and(predicate::str::contains(format!("line {line}"))));
|
|
}
|
|
}
|