[core] Tests first: share tokens, prefix escapes, repo layout, exact host path, error codes (red)

This commit is contained in:
2026-11-07 17:32:09 +01:00
parent 027bf3a553
commit 73a9f3da45
13 changed files with 1342 additions and 106 deletions
+35 -52
View File
@@ -148,11 +148,11 @@ value = "max-age=31536000"
#[test]
fn hosts_are_sorted_by_hostname_whatever_the_file_order() {
let a = SourceFile {
name: "b.test.toml",
name: "hosts/b.test.toml",
contents: "hostname = \"b.test\"\nupstreams = [\"http://127.0.0.1:1\"]\n",
};
let b = SourceFile {
name: "a.test.toml",
name: "hosts/a.test.toml",
contents: "hostname = \"a.test\"\nupstreams = [\"http://127.0.0.1:1\"]\n",
};
let m1 = load(&site(), &[a, b]).unwrap();
@@ -175,7 +175,7 @@ fn empty_site_file_is_allowed() {
contents: "",
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
}],
);
@@ -236,7 +236,7 @@ fn rejects_unknown_field_in_site_file() {
contents: "secrets = []\nsecret_values = { a = \"b\" }\n",
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
}],
);
@@ -348,10 +348,11 @@ fn accepts_good_hostnames() {
}
#[test]
fn rejects_duplicate_hostnames_across_files() {
let r = load(
&site(),
&[
fn a_second_file_for_the_same_host_is_refused_by_its_path() {
// With the exact `hosts/<hostname>.toml` rule, two files can never hold one hostname:
// the second one is in the wrong place, whatever the file order.
for order in [false, true] {
let mut files = vec![
SourceFile {
name: "hosts/app.test.toml",
contents: MINIMAL,
@@ -360,38 +361,19 @@ fn rejects_duplicate_hostnames_across_files() {
name: "other/app.test.toml",
contents: MINIMAL,
},
],
);
let errs = r.unwrap_err();
assert_eq!(
errs.errors(),
[ValidationError::DuplicateHostname {
hostname: "app.test".into(),
first: "hosts/app.test.toml".into(),
second: "other/app.test.toml".into()
}]
);
}
#[test]
fn duplicate_detection_is_independent_of_file_order() {
let r = load(
&site(),
&[
SourceFile {
name: "other/app.test.toml",
contents: MINIMAL,
},
SourceFile {
name: "hosts/app.test.toml",
contents: MINIMAL,
},
],
);
let errs = r.unwrap_err();
assert!(
matches!(&errs.errors()[0], ValidationError::DuplicateHostname { first, second, .. } if first == "hosts/app.test.toml" && second == "other/app.test.toml")
);
];
if order {
files.reverse();
}
let errs = load(&site(), &files).unwrap_err();
assert_eq!(
errs.errors(),
[ValidationError::FileNameMismatch {
file: "other/app.test.toml".into(),
hostname: "app.test".into()
}]
);
}
}
#[test]
@@ -400,11 +382,11 @@ fn rejects_duplicate_source_file_names() {
&site(),
&[
SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
},
SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
},
],
@@ -485,7 +467,8 @@ fn rejects_undefined_secret_reference() {
e,
ValidationError::UndefinedSecret {
file: "hosts/app.test.toml".into(),
secret: "nope".into()
secret: "nope".into(),
field: "request_headers[0].secret".into()
}
);
}
@@ -498,7 +481,7 @@ fn undefined_secret_is_reported_when_site_declares_none() {
contents: "",
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: &format!(
"{MINIMAL}[[request_headers]]\naction = \"set\"\nname = \"X-K\"\nsecret = \"api_key\"\n"
),
@@ -532,7 +515,7 @@ fn rejects_bad_secret_names_in_site_file() {
contents: &format!("secrets = [{bad:?}]\n"),
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
}],
);
@@ -678,7 +661,7 @@ fn forward_auth_requires_site_configuration() {
contents: "",
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: &format!("{MINIMAL}auth = \"forward-auth\"\n"),
}],
);
@@ -704,7 +687,7 @@ fn rejects_bad_forward_auth_site_config() {
contents: &format!("[forward_auth]\nurl = {bad:?}\n"),
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
}],
);
@@ -743,15 +726,15 @@ fn collects_errors_from_every_file() {
&site(),
&[
SourceFile {
name: "a.test.toml",
name: "hosts/a.test.toml",
contents: "hostname = \"a.test\"\nupstreams = [\"ftp://x\"]\n",
},
SourceFile {
name: "B.test.toml",
name: "hosts/B.test.toml",
contents: "hostname = \"B.test\"\nupstreams = [\"http://127.0.0.1:1\"]\n",
},
SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
},
],
@@ -830,7 +813,7 @@ fn rejects_wildcards_in_copy_headers() {
contents: "[forward_auth]\nurl = \"http://127.0.0.1:9091/x\"\ncopy_headers = [\"Remote-*\"]\n",
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
}],
);
@@ -861,7 +844,7 @@ fn rejects_oversized_route_files() {
contents: &big,
},
&[SourceFile {
name: "app.test.toml",
name: "hosts/app.test.toml",
contents: MINIMAL,
}],
);