Repository navigation
fix: reject wrong-typed optional action params - #701
Conversation
|
The first Linux CI run caught a borrow mismatch in the certificate-domain conversion. I fixed it in |
vladimirrott
left a comment
There was a problem hiding this comment.
Reviewed at d4c15c34.
Thanks, Danny. You went past the issue's list in the right places: besides the numeric and boolean sites #668 listed, you converted every loose optional string and array read in build_action_spec, and you moved the domain read above the if let, so a wrong-typed domain gets refused even when domains wins. The {"domains": [...], "domain": 42} row pins that case.
I ran clippy and the suite in a no-network container at d4c15c34 (2,007 tests plus the 15 GUI ones gives your 2,022), then put each converted read back to its old .and_then(|v| v.as_*()) form, one at a time. 35 of the 36 sites went red, each on its own row, and so did the optional_validated helper and the all-at-once revert.
One decision first, and it's mine to make: null. Your tables assert that "min_days": null gets refused. On main a null optional reads as absent, and str_array_or_empty still says so in its doc comment, so after this PR SetKernelArguments {"remove": null} passes while GrubSetKargs {"delete": null} fails. ObtainCertificate settles it for me: it takes domains or domain, and a client that fills its schema with "domains": null, "domain": "example.com" worked before and would now get InvalidParam("domains"). The operator approved a preview showing null, and applying nothing for that key matches what they saw. So I'd like null to mean absent for optional params: None | Some(Value::Null) => Ok(None) in the helpers, json!(null) out of the two invalid lists, and GrubSetKargs and ResolvectlSetDns can call the existing str_array_or_empty, which leaves optional_str_array for ObtainCertificate alone. Strings, negatives and floats keep failing, and those are the #668 bug.
While you're in there, the mutants found three behaviours that no test covers. The old code had no test for them either, so none of this is a regression of yours:
ObtainCertificate {"domains": ["example.com", 42]}should giveInvalidParam("domains"). Main refused it too; swappingoptional_str_arrayfor afilter_mappasses all 1,152 daemon tests. This is the row I'd add.GrubSetKargs {"append": "quiet"}, a string where an array goes, now givesInvalidParam("append"). Your change fixed that, and a row would keep it fixed.SetAptPin {"priority": "500"}givesInvalidParam("priority"). Optional; the action fails either way.
#703 landed on main while this was open and touches executor.rs next to you in two places: ConfigureLogRotation now validates path after rotate, and #703 rewrote the kernel-argument doc comment below str_array_or_empty. Keep #703's let path = validated_log_rotation(...) line above your compress line, and put your optional_str_array above #703's new comment. The test count on the merge comes to 2,093. That conflict comes from my side, so if you'd rather not touch it, say so and I'll resolve it when I merge.
|
The sign-off note on #698 applies here too: the same three commands, run from this branch, clear the |
d4c15c3 to
fc22892
Compare
vladimirrott
left a comment
There was a problem hiding this comment.
Reviewed at fc22892a. Approved.
Thanks, Danny. You took the null decision the way I asked and pinned it from both sides: each table now asserts that null reads as absent before it asserts that the wrong types fail. The ResolvectlSetDns special case is right too, since a null servers should still end in MissingParam("servers"). All three rows I listed are in, and the rebase onto #703 kept its validated_log_rotation line and its kernel-argument comment where they belong.
I ran the daemon's executor tests in a no-network container at fc22892a (cargo test -p sysknife-daemon --lib --offline --locked executor::tests, 114 tests), then took the Some(Value::Null) arm out of each helper in turn:
| helper without the null arm | first failing assertion |
|---|---|
optional_str |
InstallFlatpak.remote must treat null as absent |
optional_bool |
GetJournalLog.boot must treat null as absent |
optional_u64 |
GetJournalLog.lines must treat null as absent |
optional_i64 |
SetPasswordPolicy.dcredit must treat null as absent |
optional_str_array |
ObtainCertificate.domains must treat null as absent |
str_array_or_empty |
GrubSetKargs.append must treat null as absent |
Each mutant fails on its own row. One other test, a_child_that_outlives_a_stdout_read_failure_is_stopped_not_orphaned, failed in every run, the unmutated one included. It fails the same way on main at 093436f0 in that container, it passes in CI, and your diff does not touch it, so it is my sandbox's problem and not yours. The test count moves from 2,091 to 2,093 with your two new tests, which matches workspace-tests.json.
Like #698 and #700, the branch is one commit behind main (the 0.29.0 release, version bumps only, no conflict). Once you rebase and the checks go green, I'll merge, provided the push changes nothing beyond the rebase. I'll write the CHANGELOG line then.
|
This is approved at I'll merge as soon as CI is green on the new head. |
Signed-off-by: Danny Ward <[email protected]>
Signed-off-by: Danny Ward <[email protected]>
Signed-off-by: Danny Ward <[email protected]>
Signed-off-by: Danny Ward <[email protected]>
fc22892 to
86a55be
Compare
|
Rebased onto current |
Resolve the test baseline after lacs-project#701: main is at 2093 with lacs-project#701's two tests, and this branch adds two more, so the count is 2095. Both sides edited 2091 to 2093 identically, so git merged them silently to 2093. Signed-off-by: Vladimir Rotariu <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
Refresh the Rust test baseline: main is at 2095 after lacs-project#701 and lacs-project#695, and this branch adds five tests, so 2100. Move async-trait below the sysknife-daemon comment in the CLI's dev-dependencies, where it split that comment from the line it describes. Signed-off-by: Vladimir Rotariu <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01UpyrhbDTW1gBwzGAC44GYU
Summary
Rejects present optional action parameters with the wrong JSON type while preserving the established meaning of
nullas absent. Optional strings, numbers, booleans, and arrays now treat null consistently;GrubSetKargsandResolvectlSetDnsuse the shared string-array reader, whileObtainCertificateretains its null-aware optional array so a singledomaincan be used as a fallback.Related issue
Closes #668
Validation
SetAptPin.priority.main, preserving fix: security fixes for 0.28.0 #703's log-rotation path validation; updated the workspace test baseline to 2,093.git diff --check— passed.fc22892a;container-smokeis skipped as configured.Assisted by Codex (GPT-6).
Notes for Reviewers
Null remains equivalent to omission for optional action parameters, matching existing request behavior. A null
domainsvalue falls through to the singledomainform forObtainCertificate.