2021-09-14 13:58:35 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"path/filepath"
|
|
|
|
"regexp"
|
|
|
|
"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"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
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()
|
|
|
|
expected := `[-] Downloading CPE database... Done
|
|
|
|
[-] Downloading CVE data streams... Done
|
|
|
|
[+] Data streams successfully downloaded!
|
|
|
|
`
|
|
|
|
assert.Equal(t,
|
|
|
|
expected,
|
|
|
|
runAppForTest(t, []string{"vulnerability-data-stream", "--dir", vulnPath}),
|
|
|
|
)
|
|
|
|
assert.FileExists(t, path.Join(vulnPath, "cpe.sqlite"))
|
|
|
|
|
|
|
|
var files []string
|
|
|
|
require.NoError(t, filepath.Walk(vulnPath, func(path string, info os.FileInfo, err error) error {
|
|
|
|
if match, err := regexp.MatchString("nvdcve.*\\.gz$", path); !match || err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
files = append(files, path)
|
|
|
|
return nil
|
|
|
|
}))
|
|
|
|
assert.Greater(t, len(files), 0)
|
|
|
|
}
|