Files
fleet/cmd/fleetctl/integrationtest/vuln/vulnerability_data_stream_test.go
Lucas Manuel Rodriguez e447a685f0 Rename fleetctl's testing_utils.go to testing_utils_test.go and create separate test package (#45585)
Resolves #45220 (one of several PRs, we are very close)

## Testing

- [X] QA'd all new/changed functionality manually

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Tests**
* Improved test infrastructure for the CLI: consolidated and renamed
test helpers, added a dedicated in-process CLI test helper, and updated
many test cases to use the new helpers.
* Tightened several test assertions and standardized output/error
validation across unit and integration tests to improve reliability.

<!-- review_stack_entry_start -->

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/fleetdm/fleet/pull/45585)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-05-15 11:59:18 -03:00

73 lines
2.2 KiB
Go

package vuln
import (
"fmt"
"os"
"path"
"path/filepath"
"testing"
"github.com/fleetdm/fleet/v4/cmd/fleetctl/fleetctl/fleetctltest"
"github.com/fleetdm/fleet/v4/pkg/nettest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestIntegrationsVulnerabilityDataStream(t *testing.T) {
nettest.Run(t)
fleetctltest.RunAppCheckErr(t, []string{"vulnerability-data-stream"}, "No directory provided")
vulnPath := t.TempDir()
expectedOutput := `[-] Downloading CPE database... Done
[-] Downloading CPE translations... Done
[-] Downloading NVD CVE feed... Done
[-] Downloading EPSS feed... Done
[-] Downloading CISA known exploits feed... Done
[-] Downloading Oval definitions... Done
[-] Downloading MSRC artifacts... Done
[-] Downloading MacOffice release notes... Done
[-] Downloading OSV artifacts... Done
[+] Data streams successfully downloaded!
`
// Set start and end indexes otherwise a full sync using the NVD API 2.0 takes a long time (>15m).
os.Setenv("NETWORK_TEST_NVD_CVE_START_IDX", "220000")
os.Setenv("NETWORK_TEST_NVD_CVE_END_IDX", "226000")
var actualOutput string
err := nettest.RunWithNetRetry(t, func() error {
w, err := fleetctltest.RunAppNoChecks([]string{"vulnerability-data-stream", "--dir", vulnPath})
actualOutput = w.String()
return err
})
require.NoError(t, err)
assert.Equal(t, expectedOutput, actualOutput)
assert.FileExists(t, path.Join(vulnPath, "cpe.sqlite"))
files := []string{
"cpe.sqlite",
"epss_scores-current.csv",
"known_exploited_vulnerabilities.json",
}
for y := 2008; y <= 2023; y++ {
files = append(
files,
fmt.Sprintf("nvdcve-1.1-%d.json.gz", y),
)
}
for _, file := range files {
assert.FileExists(t, path.Join(vulnPath, file))
}
// Verify OSV artifacts were actually written to disk, not just logged.
ubuntuMatches, err := filepath.Glob(filepath.Join(vulnPath, "osv-ubuntu-*.json.gz"))
require.NoError(t, err)
assert.NotEmpty(t, ubuntuMatches, "expected at least one Ubuntu OSV artifact in %s", vulnPath)
rhelMatches, err := filepath.Glob(filepath.Join(vulnPath, "osv-rhel-*.json.gz"))
require.NoError(t, err)
assert.NotEmpty(t, rhelMatches, "expected at least one RHEL OSV artifact in %s", vulnPath)
}