2021-09-14 13:58:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-06-01 16:06:57 +00:00
|
|
|
"fmt"
|
2023-11-21 18:30:07 +00:00
|
|
|
"os"
|
2021-09-14 13:58:35 +00:00
|
|
|
"path"
|
|
|
|
"testing"
|
|
|
|
|
2022-05-10 14:52:33 +00:00
|
|
|
"github.com/fleetdm/fleet/v4/pkg/nettest"
|
2021-09-14 13:58:35 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2022-06-09 13:36:37 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-09-14 13:58:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestVulnerabilityDataStream(t *testing.T) {
|
2022-05-10 14:52:33 +00:00
|
|
|
nettest.Run(t)
|
2021-09-20 18:09:38 +00:00
|
|
|
|
2021-09-14 13:58:35 +00:00
|
|
|
runAppCheckErr(t, []string{"vulnerability-data-stream"}, "No directory provided")
|
|
|
|
|
|
|
|
vulnPath := t.TempDir()
|
2022-06-09 13:36:37 +00:00
|
|
|
expectedOutput := `[-] Downloading CPE database... Done
|
2022-09-01 16:02:07 +00:00
|
|
|
[-] Downloading CPE translations... Done
|
2022-06-01 16:06:57 +00:00
|
|
|
[-] Downloading NVD CVE feed... Done
|
|
|
|
[-] Downloading EPSS feed... Done
|
|
|
|
[-] Downloading CISA known exploits feed... Done
|
2022-06-08 01:09:47 +00:00
|
|
|
[-] Downloading Oval definitions... Done
|
2022-10-28 15:12:21 +00:00
|
|
|
[-] Downloading MSRC artifacts... Done
|
2023-02-24 18:18:25 +00:00
|
|
|
[-] Downloading MacOffice release notes... Done
|
2021-09-14 13:58:35 +00:00
|
|
|
[+] Data streams successfully downloaded!
|
|
|
|
`
|
2022-06-09 13:36:37 +00:00
|
|
|
|
2023-11-21 18:30:07 +00:00
|
|
|
// 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")
|
|
|
|
|
2022-06-09 13:36:37 +00:00
|
|
|
var actualOutput string
|
|
|
|
err := nettest.RunWithNetRetry(t, func() error {
|
|
|
|
w, err := runAppNoChecks([]string{"vulnerability-data-stream", "--dir", vulnPath})
|
|
|
|
actualOutput = w.String()
|
|
|
|
return err
|
|
|
|
})
|
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, expectedOutput, actualOutput)
|
|
|
|
|
2021-09-14 13:58:35 +00:00
|
|
|
assert.FileExists(t, path.Join(vulnPath, "cpe.sqlite"))
|
|
|
|
|
2022-06-01 16:06:57 +00:00
|
|
|
files := []string{
|
|
|
|
"cpe.sqlite",
|
|
|
|
"epss_scores-current.csv",
|
|
|
|
"known_exploited_vulnerabilities.json",
|
|
|
|
}
|
2023-11-21 18:30:07 +00:00
|
|
|
for y := 2008; y <= 2023; y++ {
|
2022-06-01 16:06:57 +00:00
|
|
|
files = append(
|
|
|
|
files,
|
2023-11-21 18:30:07 +00:00
|
|
|
fmt.Sprintf("nvdcve-1.1-%d.json", y),
|
2022-06-01 16:06:57 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
for _, file := range files {
|
|
|
|
assert.FileExists(t, path.Join(vulnPath, file))
|
|
|
|
}
|
2021-09-14 13:58:35 +00:00
|
|
|
}
|