fix(fermata): a certificate file is judged by all of its text, not by its armor labels

API_TOKEN=x, a lowercase private block or a raw key beside a certificate block no longer
pass the read gate. Bag Attributes, subject= and issuer=, a CA bundle's comments and the
head of x509 -text stay allowed, so real PEMs keep passing.
This commit is contained in:
2026-11-07 09:02:19 +01:00
parent f78fed95ef
commit 8998540375
3 changed files with 69 additions and 12 deletions
+5 -8
View File
@@ -453,20 +453,17 @@ fn a_new_file_named_to_a_verb_off_the_writing_list_is_not_checked() {
assert!(denied(&p.bash("tool > vendor/new")), "control");
}
/// A key file holding only certificates passes, and that is read from its armor labels:
/// other text beside a certificate block is not looked at.
/// Text a certificate file may carry around its blocks is let through: a comment line and
/// an indented attribute. A value spelled as one of them passes.
#[test]
fn a_certificate_file_is_judged_by_its_armor_labels() {
fn a_comment_or_an_attribute_line_beside_a_certificate_passes() {
const CERT: &str = "-----BEGIN CERTIFICATE-----\nFAKEFAKEfakeFAKEfake\n-----END CERTIFICATE-----\n";
for extra in ["API_TOKEN=fake-beside-a-cert\n", "-----begin private key-----\nfake-beside-a-cert\n", "fake-beside-a-cert\n"] {
let content = format!("{CERT}{extra}");
for extra in ["# fake-beside-a-cert\n", " api_token: fake-beside-a-cert\n"] {
let content = format!("{extra}{CERT}");
let p = project(&[("server.pem", content.as_bytes())]);
assert!(passes(&p.read("server.pem")), "{extra}");
assert!(passes(&p.bash("cat server.pem")), "{extra}");
assert!(p.after_read("server.pem", &content).contains("fake-beside-a-cert"), "{extra}");
}
let p = project(&[("server.pem", b"# -----BEGIN CERTIFICATE-----\nfake-beside-a-cert\n")]);
assert!(passes(&p.read("server.pem")));
}
/// Only `~` in a command is expanded. In Grep's `path` it stays text, so the file is not found.