test: add unit coverage for src/cli/config.ts (#1002) - #1006
Open
chiliec wants to merge 1 commit into
Open
Conversation
Covers validateCaCertFile (missing path, directory, empty/whitespace file, non-PEM content, and a valid -----BEGIN CERTIFICATE----- file, incl. leading whitespace) plus getConfigDir/getConfigPath path assertions, per OWASP#1002. Temp files via fs.mkdtempSync + cleanup in finally. Closes OWASP#1002
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
Adds
tests/cli/config.test.ts, the missing unit coverage forsrc/cli/config.tsrequested in #1002.Closes #1002
Coverage
validateCaCertFile(filePath)— one assertion per failure path plus the happy path:/cannot read file//not a file//file is empty//file is empty/(exercises thecontent.trim()branch)/not a valid PEM certificate/-----BEGIN CERTIFICATE-----→ does not throwtrimStart()branch)getConfigDir()/getConfigPath()— assert they end with.cve-lite-cliand.cve-lite-cli/config.json, and thatgetConfigPath()lives insidegetConfigDir().Temp files are created with
fs.mkdtempSync(path.join(os.tmpdir(), ...))and removed in afinallyblock, matching the existingtests/osv-cache.test.tsstyle. LeftreadConfig/writeConfigout per the issue's "optional stretch" note (they touch the real home dir).Validation (Node 20.18.1)
npm run build(tsc) — clean, no type errors.pretest) passes: no.only, no Mocha-isms.validateCaCertFilemakes exactly the three corresponding tests fail; restoring them makes all 9 pass again.Note: the repo's
tests/e2e/*andtests/audit-log/*suites currently fail on a cleanmaincheckout too (they assert on CLI report output / "Override hygiene", unrelated toconfig.ts) — those failures are pre-existing and outside this diff. This PR only adds one test file and changes no source.First-time contributor here — happy to adjust naming, split cases, or add the
readConfig/writeConfigstretch coverage if you'd like it.