fix(derive): reject form impostor parameters
Tighten generated-form handler checking so a parameter must look like slhx::Form<T> or imported Form<T>, not a nongeneric local Form or unrelated path with a Form suffix. req: form/004 req: form/006
This commit is contained in:
@@ -324,6 +324,60 @@ fn create(_form: slhx::Form<CreateTodo>) -> impl slhx::IntoEffect {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn form_handle_rejects_nongeneric_form_impostor() {
|
||||
// req: form/004 req: form/006 req: test/003
|
||||
let fixture = Fixture::new("slhx-derive-form-handler-nongeneric-impostor-fail");
|
||||
fixture.write(
|
||||
"Cargo.toml",
|
||||
&format!(
|
||||
r#"[package]
|
||||
name = "slhx-derive-form-handler-nongeneric-impostor-fail"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
slhx = {{ path = {:?} }}
|
||||
"#,
|
||||
repo_path("slhx")
|
||||
),
|
||||
);
|
||||
fixture.write(
|
||||
"build.rs",
|
||||
r#"fn main() {
|
||||
let out = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
||||
std::fs::write(
|
||||
out.join("slhx.syms"),
|
||||
"slhx-syms-v1\nhandle\ttemplates/app.heml::create\tcreate\t1\nhandle_form\tcreate\tnew_todo\n",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
fixture.write(
|
||||
"src/lib.rs",
|
||||
r#"struct Form;
|
||||
|
||||
#[slhx::handler]
|
||||
fn create(_form: Form) -> impl slhx::IntoEffect {
|
||||
slhx::EffectBatch::default()
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
let output = check_fixture(&fixture);
|
||||
|
||||
assert!(!output.status.success(), "fixture unexpectedly compiled");
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
stderr.contains("slhx handler `create` handles a generated form and must accept slhx::Form<_>"),
|
||||
"missing nongeneric form diagnostic in stderr:\n{stderr}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn form_handle_rejects_form_name_suffix_impostor() {
|
||||
// req: form/004 req: form/006 req: test/003
|
||||
|
||||
Reference in New Issue
Block a user