diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-03-18 20:30:26 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-03-18 20:30:26 -0400 |
commit | df9faa55f3724a07f8133b972ab831860e927b95 (patch) | |
tree | 2ec72c5f22c7a634d9e707ca8f377cb0186c7df9 | |
parent | 06cde909bbc36e4704a2602caddf0a9f425463f5 (diff) | |
download | cvez-df9faa55f3724a07f8133b972ab831860e927b95.tar.bz2 cvez-df9faa55f3724a07f8133b972ab831860e927b95.zip |
dbstore/dbstore_test.go: fix TestCisaSearch()
-rw-r--r-- | dbstore/dbstore_test.go | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/dbstore/dbstore_test.go b/dbstore/dbstore_test.go index 1f98150..5e81338 100644 --- a/dbstore/dbstore_test.go +++ b/dbstore/dbstore_test.go @@ -14,6 +14,7 @@ import ( "github.com/pablotron/cvez/cpedict" "github.com/pablotron/cvez/cpematch" nvd_feed "github.com/pablotron/cvez/feed" + "github.com/pablotron/cvez/rfc3339" io_fs "io/fs" "os" "path/filepath" @@ -1465,12 +1466,26 @@ func TestCisaSearch(t *testing.T) { ctx := context.Background() tests := []struct { - val string - exp []CisaSearchRow + val string + cves []string + adds []string + dues []string + exp []CisaSearchRow } {{ val: "wordpad", + cves: []string { "CVE-2017-0199" }, + adds: []string { "2021-11-03" }, + dues: []string { "2022-05-03" }, exp: []CisaSearchRow { CisaSearchRow { + Id: 184, + CatId: 0, + Vendor: "Microsoft", + Product: "Windows, Windows Server, Microsoft Office", + Name: "Microsoft Office/WordPad Remote Code Execution Vulnerability with Windows API", + Description: "Allows remote attackers to execute arbitrary code via a crafted document, aka \"Microsoft Office/WordPad Remote Code Execution Vulnerability w/Windows API.\"", + Action: "Apply updates per vendor instructions.", + Rank: -8.090183, }, }, }} @@ -1484,6 +1499,36 @@ func TestCisaSearch(t *testing.T) { for _, test := range(tests) { t.Run(test.val, func(t *testing.T) { + // parse cve ids + for i, val := range(test.cves) { + if cve, err := nvd_feed.NewCveId(val); err != nil { + t.Error(err) + return + } else { + test.exp[i].CveId = cve + } + } + + // parse add dates + for i, val := range(test.adds) { + if d, err := rfc3339.NewDate([]byte(val)); err != nil { + t.Error(err) + return + } else { + test.exp[i].AddedAt = d + } + } + + // parse due dates + for i, val := range(test.dues) { + if d, err := rfc3339.NewDate([]byte(val)); err != nil { + t.Error(err) + return + } else { + test.exp[i].DueAt = d + } + } + if got, err := db.CisaSearch(ctx, test.val); err != nil { t.Error(err) } else if !reflect.DeepEqual(got, test.exp) { |