Skip to content

test: add unit coverage for src/cli/config.ts (#1002) - #1006

Merged
sonukapoor merged 1 commit into
OWASP:mainfrom
chiliec:test/config-unit-coverage
Aug 23, 2026
Merged

sonukapoor merged 1 commit into
OWASP:mainfrom
chiliec:test/config-unit-coverage

Conversation

@chiliec

@chiliec chiliec commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

What

Adds tests/cli/config.test.ts, the missing unit coverage for src/cli/config.ts requested in #1002.

Closes #1002

Coverage

validateCaCertFile(filePath) — one assertion per failure path plus the happy path:

  • missing path → throws /cannot read file/
  • a directory → throws /not a file/
  • an empty file → throws /file is empty/
  • a whitespace-only file → throws /file is empty/ (exercises the content.trim() branch)
  • a non-PEM file → throws /not a valid PEM certificate/
  • a file starting with -----BEGIN CERTIFICATE----- → does not throw
  • a PEM with leading whitespace → does not throw (exercises the trimStart() branch)

getConfigDir() / getConfigPath() — assert they end with .cve-lite-cli and .cve-lite-cli/config.json, and that getConfigPath() lives inside getConfigDir().

Temp files are created with fs.mkdtempSync(path.join(os.tmpdir(), ...)) and removed in a finally block, matching the existing tests/osv-cache.test.ts style. Left readConfig/writeConfig out per the issue's "optional stretch" note (they touch the real home dir).

Validation (Node 20.18.1)

$ npm test tests/cli/config.test.ts
PASS tests/cli/config.test.ts
Tests: 9 passed, 9 total
  • npm run build (tsc) — clean, no type errors.
  • Test-hygiene gate (pretest) passes: no .only, no Mocha-isms.
  • RED→GREEN proof the tests are real: temporarily removing the empty-file and PEM guards from validateCaCertFile makes exactly the three corresponding tests fail; restoring them makes all 9 pass again.

Note: the repo's tests/e2e/* and tests/audit-log/* suites currently fail on a clean main checkout too (they assert on CLI report output / "Override hygiene", unrelated to config.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/writeConfig stretch coverage if you'd like it.

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

@sonukapoor sonukapoor left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comprehensive config test coverage - getConfigDir, getConfigPath, and validateCaCertFile are all covered including the error paths. Merging.

@sonukapoor
sonukapoor merged commit e63a38e into OWASP:main Aug 23, 2026
6 checks passed
@sonukapoor

Copy link
Copy Markdown
Collaborator

Merged - thank you @chiliec!

@chiliec

chiliec commented Aug 26, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging, @sonukapoor! Glad to add more coverage / pick up other items on cve-lite-cli — I'm a TS/Go engineer with a security-tooling focus, currently open to remote contract work if that'd help. Let me know what's most useful to tackle next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test: add unit coverage for src/cli/config.ts

2 participants