From df9faa55f3724a07f8133b972ab831860e927b95 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Fri, 18 Mar 2022 20:30:26 -0400 Subject: dbstore/dbstore_test.go: fix TestCisaSearch() --- dbstore/dbstore_test.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) (limited to 'dbstore') 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) { -- cgit v1.2.3