Repository navigation
fix(config): reject a bare ~ as a configured path and test the auth config rules in ox-core - #737
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
hakula139
force-pushed
the
test/auth-shape-tests-in-core
branch
from
October 28, 2026 18:06
d001fb5 to
b1d7d22
Compare
~ as a configured path and test the auth config rules in ox-core
The client.auth shape rules and the user-layer redaction of private config values had no ox-core test. Their only pins were a 19-case table and a relative-path test in crates/ox/tests/cli.rs, which spawned `ox config check` once per case, so a broken rule showed up as a subprocess failure far from the code that owns it. schema.rs now tests LoginAuth and AuthValue parsing and inline_secret directly, with exact messages, and load.rs tests that read_layer names the shape of each malformed private value without echoing it. One end-to-end test keeps two cases, a type error and a TOML syntax error, to show that a rejected credential stays out of stderr and the run's files. The 1,674-line cli.rs becomes the tests/cli/ binary: main.rs holds the shared helpers and declares one module per area (startup, config check, native auth, headless, REPL, sessions, signals), whose test names drop the area's prefix. The suite still links as one test binary, and the testing conventions describe the layout.
The empty `client.auth.value` case lost its parse-level test when the CLI table moved. A parsed empty value, a bare `~`, and `~/token` under a relative home directory now pin each `client.auth.file` rule through the shared `expand_absolute` check, and `require_absolute` splits that check from `expand_user` so a test can reach the message for a home directory that cannot be found. The testing conventions scope the one-binary rule to the mock-backed tests and name `tests/live.rs`.
`expand_absolute` accepted `~`, which expands to the home directory, so `client.auth.file = "~"` passed `ox config check` and failed only when `ox` read the token, with "Access is denied" on Windows. Every caller needs a path other than the home directory: the credential file and the CA bundle name files, and an extra root already rejects `$HOME`. The helper now rejects `~` and `~/`, which keeps the documented "absolute or `~/`" rule true. `expand_user` no longer quotes the raw path in its error, so no caller can leak a pasted secret through it, and `require_absolute` goes away. The bare-`~` and relative-home cases move into `expand_absolute`'s own tests, and the testing conventions name what `tests/cli/` holds.
hakula139
force-pushed
the
test/auth-shape-tests-in-core
branch
from
October 28, 2026 20:34
3791724 to
7b5e455
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
client.authshape rules inox-core/src/config/schema.rs("client.auth requires exactly one of value or file", "client.auth type login takes no other keys", "invalid client.auth.file: expected an absolute or~/path") and the user-layer redaction of private config values inconfig/load.rshad noox-coretest. Their only pins were the 19-caseINVALID_AUTH_CONFIGStable and a relative-path test incrates/ox/tests/cli.rs, which spawnedox config checkonce per case, so a broken rule failed far from the code that owns it. Those rules now have unit tests next to their code, and the 1,674-linetests/cli.rsbecomes one test binary with a file per area.config::schematestsLoginAuthandAuthValueparsing throughtoml::from_str::<FileConfig>andinline_secretdirectly, asserting exact messages. They cover an inline value, absolute and~/files (with the home directory pinned), neither or both sources, an empty value, keys besidetype = 'login', and a header-unsafe value. The file check is the sharedexpand_absolute, whose own tests now hold its path cases.~(user-visible):expand_absolute, whichclient.auth.file,client.extra_ca_certs, andpermission.extra_rootsshare, accepted~and~/because they expand to the absolute home directory.client.auth.file = "~"then passedox config checkand Home Manager'scheckConfigand failed only whenoxread the token, on Windows with a misleading "Access is denied". No caller can use the home directory itself: the credential file and the CA bundle name files, and an extra root already rejects$HOMEas too broad. The helper now rejects both spellings with "expected an absolute or~/path", so the rule the authentication, configuration, and permissions guides state holds. Its tests pin~,~/,~alice/..., a relative path, and~/ca.pemunder a relative home directory. The extra-root test pins the too-broad message with the home directory's absolute spelling.expand_user's missing-home error no longer quotes the raw path and uses the spellingrule.rsalready has ("failed to expand~: no home directory"). Every caller that shows the path already names it in its own context, so "errors never quoteraw" now holds by construction, andexpand_absoluteneeds no remap. The missing-home message stays untested, as onmain, since no environment variable can forcehome_dir()to return nothing.config::load::read_layergains a 16-case table of malformed private values in a user file, covering type errors, an unknown type, unknown fields, header errors, each custom message prefix thatsafe_messagepasses through, and a TOML syntax error. Each error must start withinvalid config at <path>:, name the expected shape, and contain none of the private sentinels. Before this, only a project-layer case pinned redaction inox-core.config_check::rejects_a_malformed_credential_without_echoing_itkeeps two cases, a type error and a syntax error, to show thatox config checkprints the headline afterError:and that neither stderr nor any file the run writes contains the value.crates/ox/tests/cli/main.rsholds the shared helpers (ox,config_check,write_user_config,tree,assert_private_auth_run,request_header) and declaresstartup,config_check,native_auth,headless,repl,sessions, andsignalsmodules, the last gated once oncfg(unix). Each module starts withuse super::*;, and its test names drop the area's prefix, as inconfig_check::rejects_an_unknown_key_with_its_file. Test bodies are unchanged apart from the moved auth cases.tests/live.rsbuilds as the onetests/cli/binary, and the Home Manager module's comment points attests/cli/config_check.rs.Design decisions:
load.rs, rule tests inschema.rs. The design review proposed moving the table intoschema.rs, but most of its expected messages (in \client.auth`: expected a string, the custom-prefix pass-through, the TOML syntax error) are composed byread_layer's redaction, so the table testsread_layer. The rules themselves (LoginAuth,AuthValue,inline_secret`) are tested where they are defined, so each case lives in the module whose behavior it asserts.tests/is its own crate and link step, while atests/cli/main.rswith modules links once and keeps the shared helpers in one place, as Codex'sexec/tests/all.rsdoes.Test plan
cargo fmt --check,cargo build, bothcargo clippyruns,cargo doc --no-deps,cargo llvm-cov,pnpm format,pnpm lint,pnpm spellcheck). After a test-helper fix in the final commit,cargo fmt,cargo clippy --all-targets, andcargo llvm-covpassed again: 1,924ox-core, 1,461ox-tui, 129oxunit, and 40 CLI tests.cargo test --test clilists every test under its area module (40 before the rebase, 42 after feat(session)!: store sessions in SQLite #729 added two).tests/cli.rschanges (thesaved_sessions/exportedhelpers, the export-based resume tests, and the store-backed assertions) intomain.rs,sessions.rs,headless.rs, andnative_auth.rs, the verification block passed at 7b5e455 with 42 CLI tests.{ type = 'bearer' }andvalue = '') are now parse-levelschema.rscases, and thelogin+filerow is covered bylogin_auth::try_from::rejects_any_other_key.