diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:01:14 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-02-04 00:01:14 -0500 |
commit | bcc1a56f57aee10fc79a14084f425cdab8b0325b (patch) | |
tree | a8e00cd50f8be0a044ae9c80e1a98092aaae65c8 /internal/cpematch/cpematch_test.go | |
parent | c98ce3189a3171f0594075fe17cc86a40760bee2 (diff) | |
download | cvez-bcc1a56f57aee10fc79a14084f425cdab8b0325b.tar.bz2 cvez-bcc1a56f57aee10fc79a14084f425cdab8b0325b.zip |
add internal/cpematch
Diffstat (limited to 'internal/cpematch/cpematch_test.go')
-rw-r--r-- | internal/cpematch/cpematch_test.go | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/internal/cpematch/cpematch_test.go b/internal/cpematch/cpematch_test.go new file mode 100644 index 0000000..7d69410 --- /dev/null +++ b/internal/cpematch/cpematch_test.go @@ -0,0 +1,100 @@ +package cpematch + +import ( + "compress/gzip" + "encoding/json" + "os" + "reflect" + "testing" +) + +func TestMatchesUnmarshal(t *testing.T) { + // expected data + exp := Matches { + Matches: []Match { + Match { + Cpe23Uri: "cpe:2.3:a:101_project:101:*:*:*:*:*:node.js:*:*", + VersionStartIncluding: "1.0.0", + VersionEndIncluding: "1.6.3", + Names: []Name { + Name { + Cpe23Uri: "cpe:2.3:a:101_project:101:1.0.0:*:*:*:*:node.js:*:*", + }, + + Name { + Cpe23Uri: "cpe:2.3:a:101_project:101:1.1.0:*:*:*:*:node.js:*:*", + }, + + Name { + Cpe23Uri: "cpe:2.3:a:101_project:101:1.1.1:*:*:*:*:node.js:*:*", + }, + }, + }, + + Match { + Cpe23Uri: "cpe:2.3:a:1password:1password:*:*:*:*:*:macos:*:*", + VersionStartIncluding: "7.7.0", + VersionEndExcluding: "7.8.7", + Names: []Name { + Name { + Cpe23Uri: "cpe:2.3:a:1password:1password:7.7.0:*:*:*:*:macos:*:*", + }, + }, + }, + + Match { + Cpe23Uri: "cpe:2.3:a:zimbra:collaboration:*:*:*:*:*:*:*:*", + VersionStartExcluding: "8.8.0", + VersionEndExcluding: "8.8.15", + Names: []Name { + Name { + Cpe23Uri: "cpe:2.3:a:zimbra:collaboration:8.8.6:*:*:*:*:*:*:*", + }, + + Name { + Cpe23Uri: "cpe:2.3:a:zimbra:collaboration:8.8.7:*:*:*:*:*:*:*", + }, + + Name { + Cpe23Uri: "cpe:2.3:a:zimbra:collaboration:8.8.8:-:*:*:*:*:*:*", + }, + + Name { + Cpe23Uri: "cpe:2.3:a:zimbra:collaboration:8.8.8:p1:*:*:*:*:*:*", + }, + }, + }, + }, + } + + // open test data + f, err := os.Open("testdata/test-0.json.gz") + if err != nil { + t.Error(err) + return + } + defer f.Close() + + // create gzip reader + gz, err := gzip.NewReader(f) + if err != nil { + t.Error(err) + return + } + defer gz.Close() + + // create json decoder + d := json.NewDecoder(gz) + var got Matches + + // decode match data, check for error + if err := d.Decode(&got); err != nil { + t.Error(err) + return + } + + // check for match + if !reflect.DeepEqual(got, exp) { + t.Errorf("got \"%v\", exp \"%v\"", got, exp) + } +} |