aboutsummaryrefslogtreecommitdiff
path: root/dbstore
diff options
context:
space:
mode:
authorPaul Duncan <pabs@pablotron.org>2022-02-26 17:46:18 -0500
committerPaul Duncan <pabs@pablotron.org>2022-02-26 17:46:18 -0500
commit163666e3966058e906b9d19687da9acc62158232 (patch)
tree9797bc3658e622283ff495d73ea6bba6baa1b824 /dbstore
parentff10190e5ec9876e3ba672ca8c4004bacb8f0c69 (diff)
downloadcvez-163666e3966058e906b9d19687da9acc62158232.tar.bz2
cvez-163666e3966058e906b9d19687da9acc62158232.zip
dbstore/dbstore_test.go: update skip messages for several tests, add TestAddCveFeed(), add use readonly.db to test Init() failure in several tests
Diffstat (limited to 'dbstore')
-rw-r--r--dbstore/dbstore_test.go90
1 files changed, 86 insertions, 4 deletions
diff --git a/dbstore/dbstore_test.go b/dbstore/dbstore_test.go
index 1b5d498..df7dd62 100644
--- a/dbstore/dbstore_test.go
+++ b/dbstore/dbstore_test.go
@@ -517,7 +517,7 @@ func TestQueryRow(t *testing.T) {
func TestAddCpeDictionaryPass(t *testing.T) {
if testing.Short() {
- t.Skip("skipping TestAddCveFeeds() in short mode")
+ t.Skip("skipping TestAddCpeDictionaryPass() in short mode")
return
}
@@ -547,7 +547,7 @@ func TestAddCpeDictionaryPass(t *testing.T) {
func TestAddCpeDictionaryFail(t *testing.T) {
if testing.Short() {
- t.Skip("skipping TestAddCveFeeds() in short mode")
+ t.Skip("skipping TestAddCpeDictionaryFail() in short mode")
return
}
@@ -770,11 +770,23 @@ func TestCpeSearch(t *testing.T) {
}
})
}
+
+ // readonly-db test (init failure)
+ t.Run("readonly", func(t *testing.T) {
+ q := "advisory AND book"
+ if db, err := Open("testdata/readonly.db"); err != nil {
+ t.Error(err)
+ } else {
+ if got, err := db.CpeSearch(ctx, CpeSearchAll, q); err == nil {
+ t.Errorf("got %v, exp error", got)
+ }
+ }
+ })
}
func TestAddCpeMatches(t *testing.T) {
if testing.Short() {
- t.Skip("skipping TestAddCveFeeds() in short mode")
+ t.Skip("skipping TestAddCpeMatches() in short mode")
return
}
@@ -1091,6 +1103,17 @@ func TestAddCpeMatches(t *testing.T) {
}
})
}
+
+ // readonly-db test (init failure)
+ t.Run("readonly", func(t *testing.T) {
+ matches := cpematch.Matches { Matches: passTests[0].matches }
+
+ if db, err := Open("testdata/readonly.db"); err != nil {
+ t.Error(err)
+ } else if err = db.AddCpeMatches(ctx, matches); err == nil {
+ t.Errorf("got success, exp error")
+ }
+ })
}
func TestCpeMatchSearch(t *testing.T) {
@@ -1193,6 +1216,17 @@ func TestCpeMatchSearch(t *testing.T) {
}
})
}
+
+ // readonly-db test (init failure)
+ t.Run("readonly", func(t *testing.T) {
+ q := "cpe:2.3:a:101_project:101:*:*:*:*:*:node.js:*:*"
+
+ if db, err := Open("testdata/readonly.db"); err != nil {
+ t.Error(err)
+ } else if got, err := db.CpeMatchSearch(ctx, q); err == nil {
+ t.Errorf("got %v, exp error", got)
+ }
+ })
}
func TestAddCveFeeds(t *testing.T) {
@@ -1210,7 +1244,7 @@ func TestAddCveFeeds(t *testing.T) {
}
// create test db
- db, err := createTestDb(ctx, "testdata/test-addcvefeed.db")
+ db, err := createTestDb(ctx, "testdata/test-addcvefeeds.db")
if err != nil {
t.Error(err)
return
@@ -1237,6 +1271,43 @@ func TestAddCveFeeds(t *testing.T) {
}
}
+func TestAddCveFeed(t *testing.T) {
+ ctx := context.Background()
+
+ if testing.Short() {
+ t.Skip("skipping TestAddCveFeed() in short mode")
+ return
+ }
+
+ // get feed
+ feed, err := getFeed("testdata/nvdcve-1.1-2002.json.gz")
+ if err != nil {
+ t.Error(err)
+ }
+
+ t.Run("pass", func(t *testing.T) {
+ // create test db
+ db, err := createTestDb(ctx, "testdata/test-addcvefeed.db")
+ if err != nil {
+ t.Error(err)
+ return
+ }
+
+ // add feed
+ if _, err = db.AddCveFeed(ctx, feed); err != nil {
+ t.Error(err)
+ }
+ })
+
+ t.Run("fail", func(t *testing.T) {
+ if db, err := Open("testdata/readonly.db"); err != nil {
+ t.Error(err)
+ } else if _, err = db.AddCveFeed(ctx, feed); err == nil {
+ t.Errorf("got success, exp err")
+ }
+ })
+}
+
func getTestCveId(t *testing.T, s string) nvd_feed.CveId {
r, err := nvd_feed.NewCveId(s)
if err != nil {
@@ -1293,4 +1364,15 @@ func TestCveSearch(t *testing.T) {
}
})
}
+
+ // readonly-db test (init failure)
+ t.Run("readonly", func(t *testing.T) {
+ q := "cisco anyconnect ipc dll mobility secure"
+
+ if db, err := Open("testdata/readonly.db"); err != nil {
+ t.Error(err)
+ } else if got, err := db.CveSearch(ctx, q); err == nil {
+ t.Errorf("got %v, exp error", got)
+ }
+ })
}