0
Fork 0
mirror of https://github.com/project-zot/zot.git synced 2024-12-16 21:56:37 -05:00

test: minimize trivy db download tests to avoid api rate limit

This commit is contained in:
Shivam Mishra 2020-10-14 10:29:17 -07:00
parent 0dcff98c1f
commit 25ad71787a
2 changed files with 8 additions and 54 deletions

1
go.mod
View file

@ -31,6 +31,7 @@ require (
github.com/smartystreets/goconvey v1.6.4 github.com/smartystreets/goconvey v1.6.4
github.com/spf13/cobra v0.0.5 github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.6.1 github.com/spf13/viper v1.6.1
github.com/stretchr/testify v1.6.1
github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e github.com/swaggo/http-swagger v0.0.0-20190614090009-c2865af9083e
github.com/swaggo/swag v1.6.3 github.com/swaggo/swag v1.6.3
github.com/vektah/gqlparser/v2 v2.0.1 github.com/vektah/gqlparser/v2 v2.0.1

View file

@ -365,12 +365,10 @@ func makeHtpasswdFile() string {
} }
func TestDownloadDB(t *testing.T) { func TestDownloadDB(t *testing.T) {
Convey("Download DB", t, func() { Convey("Download DB passing invalid dir", t, func() {
err := testSetup() err := testSetup()
So(err, ShouldBeNil) So(err, ShouldBeNil)
err = cveinfo.UpdateCVEDb(dbDir, cve.Log) // Test Invalid dir download
So(err, ShouldBeNil)
err = cveinfo.UpdateCVEDb("./testdata1", cve.Log) err = cveinfo.UpdateCVEDb("./testdata1", cve.Log)
So(err, ShouldNotBeNil) So(err, ShouldNotBeNil)
}) })
@ -462,6 +460,8 @@ func TestImageTag(t *testing.T) {
func TestCVESearch(t *testing.T) { func TestCVESearch(t *testing.T) {
Convey("Test image vulenrability scanning", t, func() { Convey("Test image vulenrability scanning", t, func() {
updateDuration, _ := time.ParseDuration("1h")
expectedDuration, _ := time.ParseDuration("2h")
config := api.NewConfig() config := api.NewConfig()
config.HTTP.Port = SecurePort1 config.HTTP.Port = SecurePort1
htpasswdPath := makeHtpasswdFile() htpasswdPath := makeHtpasswdFile()
@ -476,7 +476,7 @@ func TestCVESearch(t *testing.T) {
defer os.RemoveAll(dbDir) defer os.RemoveAll(dbDir)
c.Config.Storage.RootDirectory = dbDir c.Config.Storage.RootDirectory = dbDir
cveConfig := &api.CVEConfig{ cveConfig := &api.CVEConfig{
UpdateInterval: 2, UpdateInterval: updateDuration,
} }
searchConfig := &api.SearchConfig{ searchConfig := &api.SearchConfig{
CVE: cveConfig, CVE: cveConfig,
@ -508,6 +508,8 @@ func TestCVESearch(t *testing.T) {
_ = c.Server.Shutdown(ctx) _ = c.Server.Shutdown(ctx)
}() }()
So(c.Config.Extensions.Search.CVE.UpdateInterval, ShouldEqual, expectedDuration)
// without creds, should get access error // without creds, should get access error
resp, err := resty.R().Get(BaseURL1 + "/v2/") resp, err := resty.R().Get(BaseURL1 + "/v2/")
So(err, ShouldBeNil) So(err, ShouldBeNil)
@ -684,52 +686,3 @@ func TestCVESearch(t *testing.T) {
So(resp.StatusCode(), ShouldEqual, 200) So(resp.StatusCode(), ShouldEqual, 200)
}) })
} }
func TestCveConfig(t *testing.T) {
updateDuration, _ := time.ParseDuration("1h")
expectedDuration, _ := time.ParseDuration("2h")
Convey("Make a new cve config", t, func() {
config := api.NewConfig()
config.HTTP.Port = SecurePort1
cveConfig := &api.CVEConfig{
UpdateInterval: updateDuration,
}
searchConfig := &api.SearchConfig{
CVE: cveConfig,
}
config.Extensions = &api.ExtensionConfig{
Search: searchConfig,
}
c := api.NewController(config)
dir, err := ioutil.TempDir("", "oci-repo-test")
if err != nil {
panic(err)
}
defer os.RemoveAll(dir)
c.Config.Storage.RootDirectory = dir
go func() {
// this blocks
if err := c.Run(); err != nil {
return
}
}()
// wait till ready
for {
_, err := resty.R().Get(BaseURL1)
if err == nil {
break
}
time.Sleep(100 * time.Millisecond)
}
So(c.Config.Extensions.Search.CVE.UpdateInterval, ShouldEqual, expectedDuration)
defer func() {
ctx := context.Background()
_ = c.Server.Shutdown(ctx)
}()
})
}