test: add coverage for the config subcommand (show, set, unset) - #1092
Open
chiliec wants to merge 1 commit into
Open
test: add coverage for the config subcommand (show, set, unset)#1092chiliec wants to merge 1 commit into
chiliec wants to merge 1 commit into
Conversation
Covers runConfigCommand in src/cli/config-command.ts: show with and without a configured ca-cert, set with a valid and an invalid path, and unset. console.log is captured and os.homedir() is stubbed to a temp dir so the real user config is never touched. Closes OWASP#1090
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.
What changed and why
src/cli/config-command.ts(runConfigCommand) had no test coverage. This addstests/cli/config-command.test.tscovering all of its branches:showwith no config printsNo configuration set.and the config file pathshowwith aca-certconfigured prints the key and its valuesetwith a valid PEM path stores it (asserted viareadConfig())setwith an invalid path surfaces thecannot read filevalidation error and writes nothingunsetremoves a previously stored valueunsetwith nothing set reports it is not setThe command writes to
console.log, so the tests capture it withjest.spyOn(console, "log").os.homedir()is stubbed to amkdtempSynctemp dir per test so the real~/.cve-lite-cli/config.jsonis never touched (in-process,os.homedir()ignores$HOME, unlike the child-process e2e tests). Style mirrors the existingtests/cli/config.test.ts.No source changed — test-only.
Validation
RED→GREEN: gutting
runConfigCommand's body turns all 6 tests red; restoring it turns them green, so the tests exercise real behavior rather than passing vacuously.tsc -p tsconfig.test.json --noEmitreports no errors in this file (pre-existing errors in other unrelated test files are untouched). One unrelated test,tests/cli/scan-fix-verify-exitcode.test.ts, fails on a clean checkout here too (independent of this PR, confirmed by removing this file and rerunning) — happy to look if that's unexpected on CI.Closes #1090