[core] Schema: reject wildcard header names, cap file size and upstreams, require <hostname>.toml
This commit is contained in:
+71
-20
@@ -336,7 +336,13 @@ fn accepts_good_hostnames() {
|
||||
] {
|
||||
let contents = format!("hostname = {good:?}\nupstreams = [\"http://127.0.0.1:1\"]\n");
|
||||
let name = format!("hosts/{good}.toml");
|
||||
let r = load(&site(), &[SourceFile { name: &name, contents: &contents }]);
|
||||
let r = load(
|
||||
&site(),
|
||||
&[SourceFile {
|
||||
name: &name,
|
||||
contents: &contents,
|
||||
}],
|
||||
);
|
||||
assert!(r.is_ok(), "{good}: {r:?}");
|
||||
}
|
||||
}
|
||||
@@ -785,7 +791,13 @@ fn never_panics_on_garbage() {
|
||||
|
||||
#[test]
|
||||
fn file_name_must_match_the_hostname() {
|
||||
let r = load(&site(), &[SourceFile { name: "hosts/other.test.toml", contents: MINIMAL }]);
|
||||
let r = load(
|
||||
&site(),
|
||||
&[SourceFile {
|
||||
name: "hosts/other.test.toml",
|
||||
contents: MINIMAL,
|
||||
}],
|
||||
);
|
||||
let errs = r.unwrap_err();
|
||||
assert_eq!(
|
||||
errs.errors(),
|
||||
@@ -817,14 +829,24 @@ fn rejects_wildcards_in_copy_headers() {
|
||||
name: "ianitor.toml",
|
||||
contents: "[forward_auth]\nurl = \"http://127.0.0.1:9091/x\"\ncopy_headers = [\"Remote-*\"]\n",
|
||||
},
|
||||
&[SourceFile { name: "app.test.toml", contents: MINIMAL }],
|
||||
&[SourceFile {
|
||||
name: "app.test.toml",
|
||||
contents: MINIMAL,
|
||||
}],
|
||||
);
|
||||
assert!(
|
||||
r.unwrap_err()
|
||||
.errors()
|
||||
.iter()
|
||||
.any(|e| matches!(e, ValidationError::InvalidHeaderName { .. }))
|
||||
);
|
||||
assert!(r.unwrap_err().errors().iter().any(|e| matches!(e, ValidationError::InvalidHeaderName { .. })));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_fragment_in_health_check_path() {
|
||||
let e = single_error(&format!("{MINIMAL}[health_check]\npath = \"/h#x\"\ninterval_secs = 5\n"));
|
||||
let e = single_error(&format!(
|
||||
"{MINIMAL}[health_check]\npath = \"/h#x\"\ninterval_secs = 5\n"
|
||||
));
|
||||
assert!(matches!(e, ValidationError::BadHealthCheck { .. }), "{e:?}");
|
||||
}
|
||||
|
||||
@@ -834,23 +856,43 @@ fn rejects_oversized_route_files() {
|
||||
let e = single_error(&big);
|
||||
assert!(matches!(e, ValidationError::FileTooLarge { .. }), "{e:?}");
|
||||
let r = load(
|
||||
&SourceFile { name: "ianitor.toml", contents: &big },
|
||||
&[SourceFile { name: "app.test.toml", contents: MINIMAL }],
|
||||
&SourceFile {
|
||||
name: "ianitor.toml",
|
||||
contents: &big,
|
||||
},
|
||||
&[SourceFile {
|
||||
name: "app.test.toml",
|
||||
contents: MINIMAL,
|
||||
}],
|
||||
);
|
||||
assert!(r
|
||||
.unwrap_err()
|
||||
.errors()
|
||||
.iter()
|
||||
.any(|e| matches!(e, ValidationError::FileTooLarge { file, .. } if file == "ianitor.toml")));
|
||||
assert!(r.unwrap_err().errors().iter().any(
|
||||
|e| matches!(e, ValidationError::FileTooLarge { file, .. } if file == "ianitor.toml")
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_too_many_upstreams() {
|
||||
let ups: Vec<String> = (1..=65).map(|p| format!("\"http://127.0.0.1:{p}\"")).collect();
|
||||
let e = single_error(&format!("hostname = \"app.test\"\nupstreams = [{}]\n", ups.join(", ")));
|
||||
assert!(matches!(e, ValidationError::TooManyUpstreams { .. }), "{e:?}");
|
||||
let ups: Vec<String> = (1..=64).map(|p| format!("\"http://127.0.0.1:{p}\"")).collect();
|
||||
assert!(one(&format!("hostname = \"app.test\"\nupstreams = [{}]\n", ups.join(", "))).is_ok());
|
||||
let ups: Vec<String> = (1..=65)
|
||||
.map(|p| format!("\"http://127.0.0.1:{p}\""))
|
||||
.collect();
|
||||
let e = single_error(&format!(
|
||||
"hostname = \"app.test\"\nupstreams = [{}]\n",
|
||||
ups.join(", ")
|
||||
));
|
||||
assert!(
|
||||
matches!(e, ValidationError::TooManyUpstreams { .. }),
|
||||
"{e:?}"
|
||||
);
|
||||
let ups: Vec<String> = (1..=64)
|
||||
.map(|p| format!("\"http://127.0.0.1:{p}\""))
|
||||
.collect();
|
||||
assert!(
|
||||
one(&format!(
|
||||
"hostname = \"app.test\"\nupstreams = [{}]\n",
|
||||
ups.join(", ")
|
||||
))
|
||||
.is_ok()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -861,11 +903,20 @@ fn identity_headers_stay_protected_with_a_custom_copy_list() {
|
||||
"{MINIMAL}auth = \"forward-auth\"\n[[request_headers]]\naction = \"set\"\nname = \"{header}\"\nvalue = \"x\"\n"
|
||||
);
|
||||
let r = load(
|
||||
&SourceFile { name: "ianitor.toml", contents: site },
|
||||
&[SourceFile { name: "hosts/app.test.toml", contents: &host }],
|
||||
&SourceFile {
|
||||
name: "ianitor.toml",
|
||||
contents: site,
|
||||
},
|
||||
&[SourceFile {
|
||||
name: "hosts/app.test.toml",
|
||||
contents: &host,
|
||||
}],
|
||||
);
|
||||
assert!(
|
||||
r.unwrap_err().errors().iter().any(|e| matches!(e, ValidationError::ProtectedHeader { .. })),
|
||||
r.unwrap_err()
|
||||
.errors()
|
||||
.iter()
|
||||
.any(|e| matches!(e, ValidationError::ProtectedHeader { .. })),
|
||||
"{header}"
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user