fleet/cmd/fleetctl/integrationtest/vuln/vulnerability_data_stream_test.go
Victor Lyuboslavsky 33396a5d91
Moved some integration tests into their own package. (#28978)
For #27927 

Refactoring to speed up fleetctl tests, no functional changes. Mostly
changing test files.

fleetctl is no longer the long pole in CI, the long pole is mysql,
followed by vuln.

<img width="389" alt="image"
src="https://github.com/user-attachments/assets/9ada64e2-b5e8-42e3-b120-4eb36183ae38"
/>
2025-05-09 09:26:57 -05:00

61 lines
1.6 KiB
Go

package vuln
import (
"fmt"
"os"
"path"
"testing"
"github.com/fleetdm/fleet/v4/cmd/fleetctl/fleetctl"
"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)
fleetctl.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
[+] 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 := fleetctl.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))
}
}