-
-
Notifications
You must be signed in to change notification settings - Fork 31
fix: add offline advisory db sync hint #407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -522,6 +522,57 @@ describe("CLI integration", () => { | |
| expect(stripAnsi(result.stdout[2] ?? "")).toContain("Advisory DB freshness: synced"); | ||
| }); | ||
|
|
||
| it("prints the advisories sync hint when the offline DB cannot be opened", async () => { | ||
| const createAdvisorySourceMock = (await import("../src/scanner.js")).createAdvisorySource as jest.Mock; | ||
| createAdvisorySourceMock.mockImplementationOnce(() => { | ||
| throw new Error("file does not exist"); | ||
| }); | ||
|
|
||
| parseArgsMock.mockReturnValue({ | ||
| command: "scan", | ||
| options: { | ||
| offline: true, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The four options const BASE_SCAN_OPTIONS = {
failOn: "critical",
batchSize: "100",
searchDepth: "4",
minSeverity: "medium",
} as const;
// then per test:
options: { offline: true, ...BASE_SCAN_OPTIONS }
options: { offlineDb: "/tmp/custom-advisories.db", ...BASE_SCAN_OPTIONS } |
||
| failOn: "critical", | ||
| batchSize: "100", | ||
| searchDepth: "4", | ||
| minSeverity: "medium", | ||
| }, | ||
| projectArg: ".", | ||
| }); | ||
|
|
||
| const result = await runIndexModule(); | ||
|
|
||
| expect(result.exitCode).toBe(1); | ||
| expect(stripAnsi(result.stderr.join("\n"))).toContain("Offline advisory database is not available: file does not exist"); | ||
| expect(stripAnsi(result.stderr.join("\n"))).toContain("To build it, run: cve-lite advisories sync"); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
const stderr = stripAnsi(result.stderr.join("\n"));
expect(stderr).toContain("Offline advisory database is not available: file does not exist");
expect(stderr).toContain("To build it, run: cve-lite advisories sync"); |
||
| }); | ||
|
|
||
| it("prints the requested output path when a custom offline DB cannot be opened", async () => { | ||
| const createAdvisorySourceMock = (await import("../src/scanner.js")).createAdvisorySource as jest.Mock; | ||
| createAdvisorySourceMock.mockImplementationOnce(() => { | ||
| throw new Error("permission denied"); | ||
| }); | ||
|
|
||
| parseArgsMock.mockReturnValue({ | ||
| command: "scan", | ||
| options: { | ||
| offlineDb: "/tmp/custom-advisories.db", | ||
| failOn: "critical", | ||
| batchSize: "100", | ||
| searchDepth: "4", | ||
| minSeverity: "medium", | ||
| }, | ||
| projectArg: ".", | ||
| }); | ||
|
|
||
| const result = await runIndexModule(); | ||
|
|
||
| expect(result.exitCode).toBe(1); | ||
| expect(stripAnsi(result.stderr.join("\n"))).toContain("Offline advisory database is not available: permission denied"); | ||
| expect(stripAnsi(result.stderr.join("\n"))).toContain("To build it, run: cve-lite advisories sync"); | ||
| expect(stripAnsi(result.stderr.join("\n"))).toContain("cve-lite advisories sync --output /tmp/custom-advisories.db"); | ||
| }); | ||
|
|
||
| it("warns when the local advisory DB appears stale", async () => { | ||
| const createAdvisorySourceMock = (await import("../src/scanner.js")).createAdvisorySource as jest.Mock; | ||
| createAdvisorySourceMock.mockReturnValueOnce({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string
"To build it, run: cve-lite advisories sync"appears in both branches — it's the full else value and also the opening line of the if branch. If the command ever changes, it needs updating in two places. Worth extracting to a constant: