mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
test(refactor): refactor tests that use zot-test to use smaller images (#1690)
Signed-off-by: Laurentiu Niculae <niculae.laurentiu1@gmail.com>
This commit is contained in:
parent
e510df7c22
commit
0731fd3828
24 changed files with 536 additions and 194 deletions
1
Makefile
1
Makefile
|
@ -139,6 +139,7 @@ $(TESTDATA): check-skopeo
|
|||
skopeo --insecure-policy copy -q docker://ghcr.io/project-zot/test-images/java:0.0.1 oci:${TESTDATA}/zot-cve-java-test:0.0.1; \
|
||||
skopeo --insecure-policy copy -q docker://ghcr.io/project-zot/test-images/alpine:3.17.3 oci:${TESTDATA}/alpine:3.17.3; \
|
||||
chmod -R a=rwx ${TESTDATA}
|
||||
ls -R -l ${TESTDATA}
|
||||
|
||||
.PHONY: run-bench
|
||||
run-bench: binary bench
|
||||
|
|
|
@ -300,7 +300,7 @@ func TestRunAlreadyRunningServer(t *testing.T) {
|
|||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
||||
cm.StartAndWait(port)
|
||||
|
@ -324,7 +324,7 @@ func TestAutoPortSelection(t *testing.T) {
|
|||
conf.Log.Output = logFile.Name()
|
||||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartServer()
|
||||
|
@ -377,7 +377,7 @@ func TestObjectStorageController(t *testing.T) {
|
|||
"name": storageConstants.S3StorageDriverName,
|
||||
}
|
||||
conf.Storage.StorageDriver = storageDriverParams
|
||||
ctlr := makeController(conf, "zot", "")
|
||||
ctlr := makeController(conf, "zot")
|
||||
So(ctlr, ShouldNotBeNil)
|
||||
|
||||
err := ctlr.Init(context.Background())
|
||||
|
@ -402,7 +402,7 @@ func TestObjectStorageController(t *testing.T) {
|
|||
}
|
||||
|
||||
conf.Storage.StorageDriver = storageDriverParams
|
||||
ctlr := makeController(conf, "/", "")
|
||||
ctlr := makeController(conf, "/")
|
||||
So(ctlr, ShouldNotBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
@ -476,7 +476,7 @@ func TestObjectStorageController(t *testing.T) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, "/", "")
|
||||
ctlr := makeController(conf, "/")
|
||||
So(ctlr, ShouldNotBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
@ -507,7 +507,7 @@ func TestObjectStorageControllerSubPaths(t *testing.T) {
|
|||
"skipverify": false,
|
||||
}
|
||||
conf.Storage.StorageDriver = storageDriverParams
|
||||
ctlr := makeController(conf, "zot", "")
|
||||
ctlr := makeController(conf, "zot")
|
||||
So(ctlr, ShouldNotBeNil)
|
||||
|
||||
subPathMap := make(map[string]config.StorageConfig)
|
||||
|
@ -548,7 +548,7 @@ func TestHtpasswdSingleCred(t *testing.T) {
|
|||
|
||||
conf.HTTP.AllowOrigin = conf.HTTP.Address
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -689,7 +689,7 @@ func TestHtpasswdTwoCreds(t *testing.T) {
|
|||
Path: htpasswdPath,
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
@ -738,7 +738,7 @@ func TestHtpasswdFiveCreds(t *testing.T) {
|
|||
Path: htpasswdPath,
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -770,7 +770,7 @@ func TestRatelimit(t *testing.T) {
|
|||
conf.HTTP.Ratelimit = &config.RatelimitConfig{
|
||||
Rate: &rate,
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
||||
cm.StartAndWait(port)
|
||||
|
@ -805,7 +805,7 @@ func TestRatelimit(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -841,7 +841,7 @@ func TestRatelimit(t *testing.T) {
|
|||
},
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -876,7 +876,7 @@ func TestBasicAuth(t *testing.T) {
|
|||
Path: htpasswdPath,
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -909,7 +909,7 @@ func TestBlobReferenced(t *testing.T) {
|
|||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -964,7 +964,7 @@ func TestInterruptedBlobUpload(t *testing.T) {
|
|||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1233,7 +1233,7 @@ func TestMultipleInstance(t *testing.T) {
|
|||
}
|
||||
globalDir := t.TempDir()
|
||||
subDir := t.TempDir()
|
||||
ctlr := makeController(conf, globalDir, "")
|
||||
ctlr := makeController(conf, globalDir)
|
||||
subPathMap := make(map[string]config.StorageConfig)
|
||||
subPathMap["/a"] = config.StorageConfig{RootDirectory: subDir}
|
||||
|
||||
|
@ -1276,7 +1276,7 @@ func TestMultipleInstance(t *testing.T) {
|
|||
globalDir := t.TempDir()
|
||||
subDir := t.TempDir()
|
||||
|
||||
ctlr := makeController(conf, globalDir, "")
|
||||
ctlr := makeController(conf, globalDir)
|
||||
subPathMap := make(map[string]config.StorageConfig)
|
||||
subPathMap["/a"] = config.StorageConfig{RootDirectory: globalDir, Dedupe: true, GC: true}
|
||||
subPathMap["/b"] = config.StorageConfig{RootDirectory: subDir, Dedupe: true, GC: true}
|
||||
|
@ -1351,7 +1351,7 @@ func TestTLSWithBasicAuth(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1418,7 +1418,7 @@ func TestTLSWithBasicAuthAllowReadAccess(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1488,7 +1488,7 @@ func TestMutualTLSAuthWithUserPermissions(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1580,7 +1580,7 @@ func TestMutualTLSAuthWithoutCN(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1620,7 +1620,7 @@ func TestTLSMutualAuth(t *testing.T) {
|
|||
CACert: CACert,
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1694,7 +1694,7 @@ func TestTLSMutualAuthAllowReadAccess(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1774,7 +1774,7 @@ func TestTLSMutualAndBasicAuth(t *testing.T) {
|
|||
CACert: CACert,
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -1858,7 +1858,7 @@ func TestTLSMutualAndBasicAuthAllowReadAccess(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -2020,7 +2020,7 @@ func TestBasicAuthWithLDAP(t *testing.T) {
|
|||
UserAttribute: "uid",
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -2102,7 +2102,7 @@ func TestGroupsPermissionsForLDAP(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -2174,7 +2174,7 @@ func TestBearerAuth(t *testing.T) {
|
|||
Service: aurl.Host,
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -2334,7 +2334,7 @@ func TestBearerAuthWrongAuthorizer(t *testing.T) {
|
|||
Service: "blablabla",
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
||||
So(func() {
|
||||
|
@ -2365,7 +2365,7 @@ func TestBearerAuthWithAllowReadAccess(t *testing.T) {
|
|||
Service: aurl.Host,
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
conf.HTTP.AccessControl = &config.AccessControlConfig{
|
||||
Repositories: config.Repositories{
|
||||
|
@ -2769,7 +2769,7 @@ func TestOpenIDMiddleware(t *testing.T) {
|
|||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
// calling endpoint should fail with unathorized access
|
||||
// calling endpoint should fail with unauthorized access
|
||||
resp, err = client.R().
|
||||
SetHeader(constants.SessionClientHeaderName, constants.SessionClientHeaderValue).
|
||||
Get(baseURL + "/v2/_catalog")
|
||||
|
@ -2835,7 +2835,7 @@ func TestOpenIDMiddleware(t *testing.T) {
|
|||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
// calling endpoint should fail with unathorized access
|
||||
// calling endpoint should fail with unauthorized access
|
||||
resp, err = client.R().
|
||||
SetHeader(constants.SessionClientHeaderName, constants.SessionClientHeaderValue).
|
||||
Get(baseURL + "/v2/_catalog")
|
||||
|
@ -2901,7 +2901,7 @@ func TestOpenIDMiddleware(t *testing.T) {
|
|||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
// calling endpoint should fail with unathorized access
|
||||
// calling endpoint should fail with unauthorized access
|
||||
resp, err = client.R().
|
||||
SetHeader(constants.SessionClientHeaderName, constants.SessionClientHeaderValue).
|
||||
Get(baseURL + "/v2/_catalog")
|
||||
|
@ -3602,7 +3602,12 @@ func TestAuthorization(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "../../test/data")
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1",
|
||||
test.GetDefaultStoreController(ctlr.Config.Storage.RootDirectory, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -3633,7 +3638,12 @@ func TestAuthorization(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("with basic auth", func() {
|
||||
ctlr := makeController(conf, t.TempDir(), "../../test/data")
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1",
|
||||
test.GetDefaultStoreController(ctlr.Config.Storage.RootDirectory, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -3664,7 +3674,7 @@ func TestGetUsername(t *testing.T) {
|
|||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -3722,7 +3732,7 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) {
|
|||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
@ -3908,7 +3918,8 @@ func TestAuthorizationWithOnlyAnonymousPolicy(t *testing.T) {
|
|||
err = os.Mkdir(path.Join(dir, "zot-test"), storageConstants.DefaultDirPerms)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, "zot-test"))
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "tag", ctlr.StoreController)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// should not have read rights on zot-test
|
||||
resp, err = resty.R().Get(baseURL + "/v2/_catalog")
|
||||
|
@ -3980,7 +3991,7 @@ func TestAuthorizationWithAnonymousPolicyBasicAuthAndSessionHeader(t *testing.T)
|
|||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
@ -4212,7 +4223,12 @@ func TestAuthorizationWithMultiplePolicies(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, dir, "../../test/data")
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1",
|
||||
test.GetDefaultStoreController(ctlr.Config.Storage.RootDirectory, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -4265,7 +4281,13 @@ func TestAuthorizationWithMultiplePolicies(t *testing.T) {
|
|||
|
||||
Convey("with basic auth", func() {
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "../../test/data")
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1",
|
||||
test.GetDefaultStoreController(ctlr.Config.Storage.RootDirectory, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -4300,7 +4322,7 @@ func TestInvalidCases(t *testing.T) {
|
|||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -4374,7 +4396,7 @@ func TestHTTPReadOnly(t *testing.T) {
|
|||
Path: htpasswdPath,
|
||||
},
|
||||
}
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -4421,12 +4443,15 @@ func TestCrossRepoMount(t *testing.T) {
|
|||
dir := t.TempDir()
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-cve-test", path.Join(dir, "zot-cve-test"))
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
ctlr.Config.Storage.RemoteCache = false
|
||||
ctlr.Config.Storage.Dedupe = false
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-cve-test", "test", storage.StoreController{
|
||||
DefaultStore: test.GetDefaultImageStore(dir, ctlr.Log),
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr) //nolint: varnamelen
|
||||
cm.StartAndWait(port)
|
||||
|
||||
|
@ -4627,15 +4652,24 @@ func TestCrossRepoMount(t *testing.T) {
|
|||
}
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "../../test/data")
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
ctlr.Config.Storage.Dedupe = false
|
||||
ctlr.Config.Storage.GC = false
|
||||
|
||||
image := test.CreateImageWith().RandomLayers(1, 10).DefaultConfig().Build()
|
||||
|
||||
err := test.WriteImageToFileSystem(image, "zot-cve-test", "0.0.1",
|
||||
test.GetDefaultStoreController(dir, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
digest := test.GetTestBlobDigest("zot-cve-test", "layer").String()
|
||||
// digest := test.GetTestBlobDigest("zot-cve-test", "layer").String()
|
||||
digest := godigest.FromBytes(image.Layers[0])
|
||||
name := "zot-c-test"
|
||||
client := resty.New()
|
||||
headResponse, err := client.R().SetBasicAuth(username, passphrase).
|
||||
|
@ -4765,9 +4799,18 @@ func TestParallelRequests(t *testing.T) {
|
|||
subPaths["/a"] = config.StorageConfig{RootDirectory: firstSubDir}
|
||||
subPaths["/b"] = config.StorageConfig{RootDirectory: secondSubDir}
|
||||
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
ctlr.Config.Storage.SubPaths = subPaths
|
||||
|
||||
testImagesDir := t.TempDir()
|
||||
testImagesController := test.GetDefaultStoreController(testImagesDir, ctlr.Log)
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testImagesController)
|
||||
assert.Equal(t, err, nil, "Error should be nil")
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-cve-test", "0.0.1", testImagesController)
|
||||
assert.Equal(t, err, nil, "Error should be nil")
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
||||
|
@ -4785,7 +4828,7 @@ func TestParallelRequests(t *testing.T) {
|
|||
assert.Equal(t, err, nil, "Error should be nil")
|
||||
assert.NotEqual(t, tagResponse.StatusCode(), http.StatusBadRequest, "bad request")
|
||||
|
||||
manifestList := getAllManifests(path.Join("../../test/data", testcase.srcImageName))
|
||||
manifestList := getAllManifests(path.Join(testImagesDir, testcase.srcImageName))
|
||||
|
||||
for _, manifest := range manifestList {
|
||||
headResponse, err := client.R().SetBasicAuth(username, passphrase).
|
||||
|
@ -4799,7 +4842,7 @@ func TestParallelRequests(t *testing.T) {
|
|||
assert.Equal(t, getResponse.StatusCode(), http.StatusNotFound, "response status code should return 404")
|
||||
}
|
||||
|
||||
blobList := getAllBlobs(path.Join("../../test/data", testcase.srcImageName))
|
||||
blobList := getAllBlobs(path.Join(testImagesDir, testcase.srcImageName))
|
||||
|
||||
for _, blob := range blobList {
|
||||
// Get request of blob
|
||||
|
@ -4819,7 +4862,7 @@ func TestParallelRequests(t *testing.T) {
|
|||
assert.NotEqual(t, getResponse.StatusCode(), http.StatusInternalServerError,
|
||||
"internal server error should not occurred")
|
||||
|
||||
blobPath := path.Join("../../test/data", testcase.srcImageName, "blobs/sha256", blob)
|
||||
blobPath := path.Join(testImagesDir, testcase.srcImageName, "blobs/sha256", blob)
|
||||
|
||||
buf, err := os.ReadFile(blobPath)
|
||||
if err != nil {
|
||||
|
@ -4979,7 +5022,7 @@ func TestHardLink(t *testing.T) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
subPaths := make(map[string]config.StorageConfig)
|
||||
|
||||
subPaths["/a"] = config.StorageConfig{RootDirectory: subDir, Dedupe: true}
|
||||
|
@ -5013,7 +5056,7 @@ func TestImageSignatures(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
// this blocks
|
||||
cm.StartAndWait(port)
|
||||
|
@ -5246,7 +5289,7 @@ func TestManifestValidation(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
// this blocks
|
||||
cm.StartServer()
|
||||
|
@ -5466,7 +5509,7 @@ func TestArtifactReferences(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
// this blocks
|
||||
cm.StartServer()
|
||||
|
@ -5725,7 +5768,7 @@ func TestRouteFailures(t *testing.T) {
|
|||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
ctlr.Config.Storage.Commit = true
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
@ -6307,7 +6350,7 @@ func TestStorageCommit(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
ctlr.Config.Storage.Commit = true
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
@ -6462,7 +6505,7 @@ func TestManifestImageIndex(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -6872,7 +6915,7 @@ func TestManifestCollision(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
|
||||
conf.HTTP.AccessControl = &config.AccessControlConfig{
|
||||
Repositories: config.Repositories{
|
||||
|
@ -6955,7 +6998,7 @@ func TestPullRange(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -7115,7 +7158,7 @@ func TestInjectInterruptedImageManifest(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -7224,7 +7267,7 @@ func TestInjectTooManyOpenFiles(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
conf.Storage.RemoteCache = false
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
@ -7421,7 +7464,7 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) {
|
|||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
Convey("Garbage collect signatures without subject and manifests without tags", func(c C) {
|
||||
dir := t.TempDir()
|
||||
|
@ -7431,7 +7474,9 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) {
|
|||
|
||||
ctlr.Config.Storage.Dedupe = false
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, repoName))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), repoName, tag,
|
||||
test.GetDefaultStoreController(dir, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartServer()
|
||||
|
@ -7607,7 +7652,9 @@ func TestGCSignaturesAndUntaggedManifests(t *testing.T) {
|
|||
ctlr.Config.Storage.GC = true
|
||||
ctlr.Config.Storage.GCDelay = 500 * time.Millisecond
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, repoName))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), repoName, tag,
|
||||
test.GetDefaultStoreController(dir, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -7704,7 +7751,9 @@ func TestPeriodicGC(t *testing.T) {
|
|||
ctlr.Config.Storage.GCInterval = 1 * time.Hour
|
||||
ctlr.Config.Storage.GCDelay = 1 * time.Second
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, repoName))
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultImage(), repoName, "0.0.1",
|
||||
test.GetDefaultStoreController(dir, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -7733,7 +7782,7 @@ func TestPeriodicGC(t *testing.T) {
|
|||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
||||
dir := t.TempDir()
|
||||
ctlr := makeController(conf, dir, "")
|
||||
ctlr := makeController(conf, dir)
|
||||
subDir := t.TempDir()
|
||||
|
||||
subPaths := make(map[string]config.StorageConfig)
|
||||
|
@ -7778,7 +7827,9 @@ func TestPeriodicGC(t *testing.T) {
|
|||
ctlr.Config.Storage.GCInterval = 1 * time.Hour
|
||||
ctlr.Config.Storage.GCDelay = 1 * time.Second
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, repoName))
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultImage(), repoName, "0.0.1",
|
||||
test.GetDefaultStoreController(dir, ctlr.Log))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(os.Chmod(dir, 0o000), ShouldBeNil)
|
||||
|
||||
|
@ -7808,7 +7859,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
conf.HTTP.Port = port
|
||||
tempDir := t.TempDir()
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
|
||||
cm.StartAndWait(port)
|
||||
|
@ -7897,7 +7948,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8042,7 +8093,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8129,7 +8180,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8197,7 +8248,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8265,7 +8316,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8319,7 +8370,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8383,7 +8434,7 @@ func TestSearchRoutes(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
ctlr := makeController(conf, tempDir, "")
|
||||
ctlr := makeController(conf, tempDir)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8423,7 +8474,7 @@ func TestDistSpecExtensions(t *testing.T) {
|
|||
conf.Log.Output = logFile.Name()
|
||||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8471,7 +8522,7 @@ func TestDistSpecExtensions(t *testing.T) {
|
|||
conf.Log.Output = logFile.Name()
|
||||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8513,7 +8564,7 @@ func TestDistSpecExtensions(t *testing.T) {
|
|||
conf.Log.Output = logFile.Name()
|
||||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8544,7 +8595,7 @@ func TestDistSpecExtensions(t *testing.T) {
|
|||
conf.Log.Output = logFile.Name()
|
||||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -8746,12 +8797,9 @@ func getAllManifests(imagePath string) []string {
|
|||
return manifestList
|
||||
}
|
||||
|
||||
func makeController(conf *config.Config, dir string, copyTestDataDest string) *api.Controller {
|
||||
func makeController(conf *config.Config, dir string) *api.Controller {
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
if copyTestDataDest != "" {
|
||||
test.CopyTestFiles(copyTestDataDest, dir)
|
||||
}
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
return ctlr
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/api/constants"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
mTypes "zotregistry.io/zot/pkg/meta/types"
|
||||
localCtx "zotregistry.io/zot/pkg/requestcontext"
|
||||
storageTypes "zotregistry.io/zot/pkg/storage/types"
|
||||
|
@ -395,7 +396,7 @@ func TestRoutes(t *testing.T) {
|
|||
statusCode := testDeleteBlob(
|
||||
map[string]string{
|
||||
"name": "ErrUnexpectedError",
|
||||
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
|
||||
"digest": "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621",
|
||||
},
|
||||
&mocks.MockedImageStore{
|
||||
DeleteBlobFn: func(repo string, digest godigest.Digest) error {
|
||||
|
@ -420,7 +421,7 @@ func TestRoutes(t *testing.T) {
|
|||
statusCode = testDeleteBlob(
|
||||
map[string]string{
|
||||
"name": "ErrBlobNotFound",
|
||||
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
|
||||
"digest": "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621",
|
||||
},
|
||||
&mocks.MockedImageStore{
|
||||
DeleteBlobFn: func(repo string, digest godigest.Digest) error {
|
||||
|
@ -433,7 +434,7 @@ func TestRoutes(t *testing.T) {
|
|||
statusCode = testDeleteBlob(
|
||||
map[string]string{
|
||||
"name": "ErrRepoNotFound",
|
||||
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
|
||||
"digest": "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621",
|
||||
},
|
||||
&mocks.MockedImageStore{
|
||||
DeleteBlobFn: func(repo string, digest godigest.Digest) error {
|
||||
|
@ -543,7 +544,7 @@ func TestRoutes(t *testing.T) {
|
|||
statusCode := testGetBlob(
|
||||
map[string]string{
|
||||
"name": "ErrRepoNotFound",
|
||||
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
|
||||
"digest": "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621",
|
||||
},
|
||||
&mocks.MockedImageStore{
|
||||
GetBlobFn: func(repo string, digest godigest.Digest, mediaType string) (io.ReadCloser, int64, error) {
|
||||
|
@ -556,7 +557,7 @@ func TestRoutes(t *testing.T) {
|
|||
statusCode = testGetBlob(
|
||||
map[string]string{
|
||||
"name": "ErrRepoNotFound",
|
||||
"digest": test.GetTestBlobDigest("zot-cve-test", "layer").String(),
|
||||
"digest": "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621",
|
||||
},
|
||||
&mocks.MockedImageStore{
|
||||
GetBlobFn: func(repo string, digest godigest.Digest, mediaType string) (io.ReadCloser, int64, error) {
|
||||
|
@ -979,7 +980,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status := testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "",
|
||||
|
@ -995,7 +996,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "100",
|
||||
|
@ -1011,7 +1012,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "100",
|
||||
|
@ -1031,7 +1032,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "100",
|
||||
|
@ -1051,7 +1052,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "100",
|
||||
|
@ -1071,7 +1072,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "100",
|
||||
|
@ -1094,7 +1095,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1114,7 +1115,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1134,7 +1135,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1154,7 +1155,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1174,7 +1175,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1524,7 +1525,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status := testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1544,7 +1545,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1564,7 +1565,7 @@ func TestRoutes(t *testing.T) {
|
|||
|
||||
status = testUpdateBlobUpload(
|
||||
[]struct{ k, v string }{
|
||||
{"digest", test.GetTestBlobDigest("zot-cve-test", "layer").String()},
|
||||
{"digest", "sha256:7b8437f04f83f084b7ed68ad8c4a4947e12fc4e1b006b38129bac89114ec3621"},
|
||||
},
|
||||
map[string]string{
|
||||
"Content-Length": "0",
|
||||
|
@ -1584,3 +1585,19 @@ func TestRoutes(t *testing.T) {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
type readerThatFails struct{}
|
||||
|
||||
func (r readerThatFails) Read(p []byte) (int, error) {
|
||||
return 0, zerr.ErrInjected
|
||||
}
|
||||
|
||||
func TestWriteDataFromReader(t *testing.T) {
|
||||
Convey("", t, func() {
|
||||
response := httptest.NewRecorder()
|
||||
api.WriteDataFromReader(response, 200, 100, ispec.MediaTypeImageManifest, readerThatFails{},
|
||||
log.NewLogger("debug", ""))
|
||||
|
||||
So(response.Code, ShouldEqual, 200)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -85,7 +85,9 @@ func TestTLSWithAuth(t *testing.T) {
|
|||
|
||||
home := os.Getenv("HOME")
|
||||
destCertsDir := filepath.Join(home, certsDir1)
|
||||
test.CopyTestFiles(sourceCertsDir, destCertsDir)
|
||||
err := test.CopyTestKeysAndCerts(destCertsDir)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
defer os.RemoveAll(destCertsDir)
|
||||
|
||||
args := []string{"imagetest", "--name", "dummyImageName", "--url", HOST1}
|
||||
|
@ -94,7 +96,7 @@ func TestTLSWithAuth(t *testing.T) {
|
|||
imageCmd.SetOut(imageBuff)
|
||||
imageCmd.SetErr(imageBuff)
|
||||
imageCmd.SetArgs(args)
|
||||
err := imageCmd.Execute()
|
||||
err = imageCmd.Execute()
|
||||
So(err, ShouldNotBeNil)
|
||||
So(imageBuff.String(), ShouldContainSubstring, "invalid URL format")
|
||||
|
||||
|
|
|
@ -398,7 +398,9 @@ func TestNegativeServerResponse(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-cve-test", path.Join(dir, "zot-cve-test"))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
conf.Storage.RootDirectory = dir
|
||||
trivyConfig := &extconf.TrivyConfig{
|
||||
|
|
|
@ -31,6 +31,7 @@ import (
|
|||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/common"
|
||||
extconf "zotregistry.io/zot/pkg/extensions/config"
|
||||
zlog "zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
|
||||
|
@ -1419,9 +1420,11 @@ func TestServerResponseGQLWithoutPermissions(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, "zot-test"))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, zlog.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err := os.Chmod(path.Join(dir, "zot-test", "blobs"), 0o000)
|
||||
err = os.Chmod(path.Join(dir, "zot-test", "blobs"), 0o000)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -407,7 +407,7 @@ func (search cveByImageSearcherGQL) search(config searchConfig) (bool, error) {
|
|||
}
|
||||
|
||||
if len(cveList.Data.CVEListForImage.CVEList) > 0 &&
|
||||
(*config.outputFormat == defaultOutoutFormat || *config.outputFormat == "") {
|
||||
(*config.outputFormat == defaultOutputFormat || *config.outputFormat == "") {
|
||||
printCVETableHeader(&builder, *config.verbose, 0, 0, 0)
|
||||
fmt.Fprint(config.resultWriter, builder.String())
|
||||
}
|
||||
|
@ -799,7 +799,7 @@ func collectResults(config searchConfig, wg *sync.WaitGroup, imageErr chan strin
|
|||
return
|
||||
}
|
||||
|
||||
if !foundResult && (*config.outputFormat == defaultOutoutFormat || *config.outputFormat == "") {
|
||||
if !foundResult && (*config.outputFormat == defaultOutputFormat || *config.outputFormat == "") {
|
||||
var builder strings.Builder
|
||||
|
||||
printHeader(&builder, *config.verbose, 0, 0, 0)
|
||||
|
@ -970,7 +970,7 @@ func printCVETableHeader(writer io.Writer, verbose bool, maxImgLen, maxTagLen, m
|
|||
}
|
||||
|
||||
func printReferrersTableHeader(config searchConfig, writer io.Writer, maxArtifactTypeLen int) {
|
||||
if *config.outputFormat != "" && *config.outputFormat != defaultOutoutFormat {
|
||||
if *config.outputFormat != "" && *config.outputFormat != defaultOutputFormat {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -1081,7 +1081,7 @@ func printImageResult(config searchConfig, imageList []imageStruct) error {
|
|||
}
|
||||
}
|
||||
|
||||
if *config.outputFormat == defaultOutoutFormat || *config.outputFormat == "" {
|
||||
if *config.outputFormat == defaultOutputFormat || *config.outputFormat == "" {
|
||||
printImageTableHeader(&builder, *config.verbose, maxImgNameLen, maxTagLen, maxPlatformLen)
|
||||
}
|
||||
|
||||
|
@ -1117,7 +1117,7 @@ func printRepoResults(config searchConfig, repoList []repoStruct) error {
|
|||
}
|
||||
}
|
||||
|
||||
if len(repoList) > 0 && (*config.outputFormat == defaultOutoutFormat || *config.outputFormat == "") {
|
||||
if len(repoList) > 0 && (*config.outputFormat == defaultOutputFormat || *config.outputFormat == "") {
|
||||
printRepoTableHeader(config.resultWriter, maxRepoNameLen, maxTimeLen, *config.verbose)
|
||||
}
|
||||
|
||||
|
|
|
@ -57,17 +57,17 @@ type SearchService interface { //nolint:interfacebloat
|
|||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getCveByImage(ctx context.Context, config searchConfig, username, password, imageName, searchedCVE string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImagesByCveID(ctx context.Context, config searchConfig, username, password, cvid string,
|
||||
getImagesByCveID(ctx context.Context, config searchConfig, username, password, cveid string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImagesByDigest(ctx context.Context, config searchConfig, username, password, digest string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getFixedTagsForCVE(ctx context.Context, config searchConfig, username, password, imageName, cvid string,
|
||||
getFixedTagsForCVE(ctx context.Context, config searchConfig, username, password, imageName, cveid string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getRepos(ctx context.Context, config searchConfig, username, password string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImageByName(ctx context.Context, config searchConfig, username, password, imageName string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getImageByNameAndCVEID(ctx context.Context, config searchConfig, username, password, imageName, cvid string,
|
||||
getImageByNameAndCVEID(ctx context.Context, config searchConfig, username, password, imageName, cveid string,
|
||||
channel chan stringResult, wtgrp *sync.WaitGroup)
|
||||
getReferrers(ctx context.Context, config searchConfig, username, password string, repo, digest string,
|
||||
) (referrersResult, error)
|
||||
|
@ -577,7 +577,7 @@ func getImage(ctx context.Context, config searchConfig, username, password, imag
|
|||
}
|
||||
|
||||
func (service searchService) getImagesByCveID(ctx context.Context, config searchConfig, username,
|
||||
password, cvid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
password, cveid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
) {
|
||||
defer wtgrp.Done()
|
||||
defer close(rch)
|
||||
|
@ -604,7 +604,7 @@ func (service searchService) getImagesByCveID(ctx context.Context, config search
|
|||
}
|
||||
}
|
||||
}`,
|
||||
cvid)
|
||||
cveid)
|
||||
|
||||
result := &common.ImagesForCve{}
|
||||
|
||||
|
@ -723,7 +723,7 @@ func (service searchService) getImagesByDigest(ctx context.Context, config searc
|
|||
}
|
||||
|
||||
func (service searchService) getImageByNameAndCVEID(ctx context.Context, config searchConfig, username,
|
||||
password, imageName, cvid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
password, imageName, cveid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
) {
|
||||
defer wtgrp.Done()
|
||||
defer close(rch)
|
||||
|
@ -750,7 +750,7 @@ func (service searchService) getImageByNameAndCVEID(ctx context.Context, config
|
|||
}
|
||||
}
|
||||
}`,
|
||||
cvid)
|
||||
cveid)
|
||||
|
||||
result := &common.ImagesForCve{}
|
||||
|
||||
|
@ -854,7 +854,7 @@ func (service searchService) getCveByImage(ctx context.Context, config searchCon
|
|||
}
|
||||
|
||||
func (service searchService) getFixedTagsForCVE(ctx context.Context, config searchConfig,
|
||||
username, password, imageName, cvid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
username, password, imageName, cveid string, rch chan stringResult, wtgrp *sync.WaitGroup,
|
||||
) {
|
||||
defer wtgrp.Done()
|
||||
defer close(rch)
|
||||
|
@ -880,7 +880,7 @@ func (service searchService) getFixedTagsForCVE(ctx context.Context, config sear
|
|||
IsSigned
|
||||
}
|
||||
}
|
||||
}`, cvid, imageName)
|
||||
}`, cveid, imageName)
|
||||
|
||||
result := &common.ImageListWithCVEFixedResponse{}
|
||||
|
||||
|
@ -1092,7 +1092,7 @@ type cveData struct {
|
|||
|
||||
func (cve cveResult) string(format string) (string, error) {
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return cve.stringPlainText()
|
||||
case jsonFormat:
|
||||
return cve.stringJSON()
|
||||
|
@ -1151,7 +1151,7 @@ type referrersResult []common.Referrer
|
|||
|
||||
func (ref referrersResult) string(format string, maxArtifactTypeLen int) (string, error) {
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return ref.stringPlainText(maxArtifactTypeLen)
|
||||
case jsonFormat:
|
||||
return ref.stringJSON()
|
||||
|
@ -1215,7 +1215,7 @@ type repoStruct common.RepoSummary
|
|||
|
||||
func (repo repoStruct) string(format string, maxImgNameLen, maxTimeLen int, verbose bool) (string, error) { //nolint: lll
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return repo.stringPlainText(maxImgNameLen, maxTimeLen, verbose)
|
||||
case jsonFormat:
|
||||
return repo.stringJSON()
|
||||
|
@ -1234,7 +1234,7 @@ func (repo repoStruct) stringPlainText(repoMaxLen, maxTimeLen int, verbose bool)
|
|||
table.SetColMinWidth(repoNameIndex, repoMaxLen)
|
||||
table.SetColMinWidth(repoSizeIndex, sizeWidth)
|
||||
table.SetColMinWidth(repoLastUpdatedIndex, maxTimeLen)
|
||||
table.SetColMinWidth(repoDownloadsIndex, dounloadsWidth)
|
||||
table.SetColMinWidth(repoDownloadsIndex, downloadsWidth)
|
||||
table.SetColMinWidth(repoStarsIndex, signedWidth)
|
||||
|
||||
if verbose {
|
||||
|
@ -1307,7 +1307,7 @@ type imageStruct common.ImageSummary
|
|||
|
||||
func (img imageStruct) string(format string, maxImgNameLen, maxTagLen, maxPlatformLen int, verbose bool) (string, error) { //nolint: lll
|
||||
switch strings.ToLower(format) {
|
||||
case "", defaultOutoutFormat:
|
||||
case "", defaultOutputFormat:
|
||||
return img.stringPlainText(maxImgNameLen, maxTagLen, maxPlatformLen, verbose)
|
||||
case jsonFormat:
|
||||
return img.stringJSON()
|
||||
|
@ -1677,7 +1677,7 @@ const (
|
|||
platformWidth = 14
|
||||
sizeWidth = 10
|
||||
isSignedWidth = 8
|
||||
dounloadsWidth = 10
|
||||
downloadsWidth = 10
|
||||
signedWidth = 10
|
||||
lastUpdatedWidth = 14
|
||||
configWidth = 8
|
||||
|
@ -1692,7 +1692,7 @@ const (
|
|||
colCVESeverityIndex = 1
|
||||
colCVETitleIndex = 2
|
||||
|
||||
defaultOutoutFormat = "text"
|
||||
defaultOutputFormat = "text"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -24,7 +24,7 @@ func TestHTTPClient(t *testing.T) {
|
|||
So(err, ShouldNotBeNil)
|
||||
|
||||
tempDir := t.TempDir()
|
||||
err = test.CopyFiles("../../test/data", tempDir)
|
||||
err = test.CopyTestKeysAndCerts(tempDir)
|
||||
So(err, ShouldBeNil)
|
||||
err = os.Chmod(path.Join(tempDir, "ca.crt"), 0o000)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -34,7 +34,7 @@ func TestHTTPClient(t *testing.T) {
|
|||
|
||||
Convey("test CreateHTTPClient() no permissions on certificate", t, func() {
|
||||
tempDir := t.TempDir()
|
||||
err := test.CopyFiles("../../test/data", tempDir)
|
||||
err := test.CopyTestKeysAndCerts(tempDir)
|
||||
So(err, ShouldBeNil)
|
||||
err = os.Chmod(path.Join(tempDir, "ca.crt"), 0o000)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -45,7 +45,7 @@ func TestHTTPClient(t *testing.T) {
|
|||
|
||||
Convey("test CreateHTTPClient() no permissions on key", t, func() {
|
||||
tempDir := t.TempDir()
|
||||
err := test.CopyFiles("../../test/data", tempDir)
|
||||
err := test.CopyTestKeysAndCerts(tempDir)
|
||||
So(err, ShouldBeNil)
|
||||
err = os.Chmod(path.Join(tempDir, "client.key"), 0o000)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -63,7 +63,7 @@ func TestHTTPClient(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
tempDir := t.TempDir()
|
||||
err := test.CopyFiles("../../test/data", tempDir)
|
||||
err := test.CopyTestKeysAndCerts(tempDir)
|
||||
So(err, ShouldBeNil)
|
||||
ctlr.Config.Storage.RootDirectory = tempDir
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ func TestGetExensionsDisabled(t *testing.T) {
|
|||
conf.Log.Output = logFile.Name()
|
||||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
||||
ctlr := makeController(conf, t.TempDir(), "")
|
||||
ctlr := makeController(conf, t.TempDir())
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -58,12 +58,8 @@ func TestGetExensionsDisabled(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func makeController(conf *config.Config, dir string, copyTestDataDest string) *api.Controller {
|
||||
func makeController(conf *config.Config, dir string) *api.Controller {
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
if copyTestDataDest != "" {
|
||||
test.CopyTestFiles(copyTestDataDest, dir)
|
||||
}
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
return ctlr
|
||||
|
|
|
@ -54,8 +54,10 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
dir := t.TempDir()
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, ctlr.Log)
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
|
@ -99,8 +101,10 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
dir := t.TempDir()
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, ctlr.Log)
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
|
@ -145,7 +149,9 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
ctlr := api.NewController(conf)
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, ctlr.Log)
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
|
@ -196,7 +202,9 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
ctlr := api.NewController(conf)
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, ctlr.Log)
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
|
@ -282,7 +290,9 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
ctlr := api.NewController(conf)
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, ctlr.Log)
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
|
@ -367,7 +377,9 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
ctlr := api.NewController(conf)
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, ctlr.Log)
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
|
@ -416,7 +428,9 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
ctlr := api.NewController(conf)
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, ctlr.Log)
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
files, err := os.ReadDir(dir)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -469,7 +483,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var index ispec.Index
|
||||
|
||||
|
@ -499,7 +515,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var index ispec.Index
|
||||
|
||||
|
@ -529,7 +547,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var index ispec.Index
|
||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||
|
@ -590,7 +610,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var index ispec.Index
|
||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||
|
@ -650,7 +672,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var index ispec.Index
|
||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||
|
@ -712,7 +736,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var index ispec.Index
|
||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||
|
@ -783,7 +809,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", dir)
|
||||
testStoreCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateRandomImage(), "zot-test", "0.0.1", testStoreCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var index ispec.Index
|
||||
buf, err := os.ReadFile(path.Join(dir, "zot-test", "index.json"))
|
||||
|
@ -867,5 +895,9 @@ func TestVerifyMandatoryAnnotationsFunction(t *testing.T) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
pass, err = linter.CheckMandatoryAnnotations("zot-test", digest, imgStore)
|
||||
So(err, ShouldBeNil)
|
||||
So(pass, ShouldBeTrue)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ package monitoring_test
|
|||
|
||||
import (
|
||||
"net/http"
|
||||
"path"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -55,7 +54,10 @@ func TestExtensionMetrics(t *testing.T) {
|
|||
monitoring.IncDownloadCounter(ctlr.Metrics, "alpine")
|
||||
monitoring.IncUploadCounter(ctlr.Metrics, "alpine")
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(rootDir, "alpine"))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(rootDir, ctlr.Log)
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "alpine", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
monitoring.SetStorageUsage(ctlr.Metrics, rootDir, "alpine")
|
||||
|
||||
monitoring.ObserveStorageLockLatency(ctlr.Metrics, time.Millisecond, rootDir, "RWLock")
|
||||
|
|
|
@ -10,7 +10,6 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
godigest "github.com/opencontainers/go-digest"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
|
@ -62,7 +61,9 @@ func TestScrubExtension(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), repoName, "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
|
@ -104,9 +105,12 @@ func TestScrubExtension(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
var manifestDigest godigest.Digest
|
||||
manifestDigest, _, _ = test.GetOciLayoutDigests("../../../test/data/zot-test")
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
image := test.CreateDefaultVulnerableImage()
|
||||
err = test.WriteImageToFileSystem(image, repoName, "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
manifestDigest := image.ManifestDescriptor.Digest
|
||||
|
||||
err = os.Remove(path.Join(dir, repoName, "blobs/sha256", manifestDigest.Encoded()))
|
||||
if err != nil {
|
||||
|
@ -153,7 +157,11 @@ func TestScrubExtension(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
image := test.CreateDefaultVulnerableImage()
|
||||
|
||||
err = test.WriteImageToFileSystem(image, repoName, "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(os.Chmod(path.Join(dir, repoName), 0o000), ShouldBeNil)
|
||||
|
||||
|
@ -193,7 +201,11 @@ func TestRunScrubRepo(t *testing.T) {
|
|||
imgStore := local.NewImageStore(dir, true, 1*time.Second, true,
|
||||
true, log, metrics, nil, cacheDriver)
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log)
|
||||
image := test.CreateDefaultVulnerableImage()
|
||||
|
||||
err = test.WriteImageToFileSystem(image, repoName, "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = scrub.RunScrubRepo(imgStore, repoName, log)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -225,9 +237,13 @@ func TestRunScrubRepo(t *testing.T) {
|
|||
imgStore := local.NewImageStore(dir, true, 1*time.Second, true,
|
||||
true, log, metrics, nil, cacheDriver)
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
var manifestDigest godigest.Digest
|
||||
manifestDigest, _, _ = test.GetOciLayoutDigests("../../../test/data/zot-test")
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log)
|
||||
image := test.CreateDefaultVulnerableImage()
|
||||
|
||||
err = test.WriteImageToFileSystem(image, repoName, "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
manifestDigest := image.ManifestDescriptor.Digest
|
||||
|
||||
err = os.Remove(path.Join(dir, repoName, "blobs/sha256", manifestDigest.Encoded()))
|
||||
if err != nil {
|
||||
|
@ -264,7 +280,11 @@ func TestRunScrubRepo(t *testing.T) {
|
|||
true, true, log, metrics, nil, cacheDriver,
|
||||
)
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log)
|
||||
image := test.CreateDefaultVulnerableImage()
|
||||
|
||||
err = test.WriteImageToFileSystem(image, repoName, "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(os.Chmod(path.Join(dir, repoName), 0o000), ShouldBeNil)
|
||||
|
||||
|
|
|
@ -88,7 +88,14 @@ func testSetup(t *testing.T) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
|
||||
err = CopyFiles("../../../../test/data", dir)
|
||||
testStorageCtrl := GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
|
||||
err = WriteImageToFileSystem(CreateRandomVulnerableImage(), "zot-test", "0.0.1", testStorageCtrl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
err = WriteImageToFileSystem(CreateRandomVulnerableImage(), "zot-cve-test", "0.0.1", testStorageCtrl)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -180,7 +180,8 @@ func TestTrivyLibraryErrors(t *testing.T) {
|
|||
// Create temporary directory
|
||||
rootDir := t.TempDir()
|
||||
|
||||
err := test.CopyFiles("../../../../../test/data/zot-test", path.Join(rootDir, "zot-test"))
|
||||
storageCtlr := test.GetDefaultStoreController(rootDir, log.NewLogger("debug", ""))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-test", "0.0.1", storageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
log := log.NewLogger("debug", "")
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package trivy_test
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -24,6 +25,45 @@ import (
|
|||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
)
|
||||
|
||||
func TestScanBigTestFile(t *testing.T) {
|
||||
Convey("Scan zot-test", t, func() {
|
||||
projRootDir, err := test.GetProjectRootDir()
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
testImage := filepath.Join(projRootDir, "test/data/zot-test")
|
||||
|
||||
tempDir := t.TempDir()
|
||||
port := test.GetFreePort()
|
||||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
defaultVal := true
|
||||
conf.Storage.RootDirectory = tempDir
|
||||
conf.Extensions = &extconf.ExtensionConfig{
|
||||
Search: &extconf.SearchConfig{
|
||||
BaseConfig: extconf.BaseConfig{Enable: &defaultVal},
|
||||
},
|
||||
}
|
||||
ctlr := api.NewController(conf)
|
||||
So(ctlr, ShouldNotBeNil)
|
||||
|
||||
err = test.CopyFiles(testImage, filepath.Join(tempDir, "zot-test"))
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
// scan
|
||||
scanner := trivy.NewScanner(ctlr.StoreController, ctlr.MetaDB, "ghcr.io/project-zot/trivy-db", "", ctlr.Log)
|
||||
|
||||
err = scanner.UpdateDB()
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
cveMap, err := scanner.ScanImage("zot-test:0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(cveMap, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestScanningByDigest(t *testing.T) {
|
||||
Convey("Scan the individual manifests inside an index", t, func() {
|
||||
// start server
|
||||
|
@ -46,7 +86,7 @@ func TestScanningByDigest(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
// push index with 2 manifests: one with vulns and one without
|
||||
vulnImage := test.CreateVulnerableImage()
|
||||
vulnImage := test.CreateDefaultVulnerableImage()
|
||||
|
||||
simpleImage := test.CreateRandomImage()
|
||||
|
||||
|
|
|
@ -448,7 +448,10 @@ func TestConvertDockerToOCI(t *testing.T) {
|
|||
Convey("test converting docker to oci functions", t, func() {
|
||||
dir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, "zot-test"))
|
||||
srcStorageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
imageRef, err := layout.NewReference(path.Join(dir, "zot-test"), "0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
|
|
|
@ -42,6 +42,7 @@ import (
|
|||
extconf "zotregistry.io/zot/pkg/extensions/config"
|
||||
syncconf "zotregistry.io/zot/pkg/extensions/config/sync"
|
||||
"zotregistry.io/zot/pkg/extensions/sync"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/meta/signatures"
|
||||
mTypes "zotregistry.io/zot/pkg/meta/types"
|
||||
storageConstants "zotregistry.io/zot/pkg/storage/constants"
|
||||
|
@ -134,8 +135,17 @@ func makeUpstreamServer(
|
|||
srcConfig.Storage.GC = false
|
||||
|
||||
srcDir := t.TempDir()
|
||||
srcStorageCtrl := test.GetDefaultStoreController(srcDir, log.NewLogger("debug", ""))
|
||||
|
||||
test.CopyTestFiles("../../../test/data", srcDir)
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtrl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", srcStorageCtrl)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
srcConfig.Storage.RootDirectory = srcDir
|
||||
|
||||
|
@ -3045,8 +3055,13 @@ func TestSubPaths(t *testing.T) {
|
|||
srcDir := t.TempDir()
|
||||
|
||||
subpath := "/subpath"
|
||||
srcStorageCtlr := test.GetDefaultStoreController(path.Join(srcDir, subpath), log.NewLogger("debug", ""))
|
||||
|
||||
test.CopyTestFiles("../../../test/data", path.Join(srcDir, subpath))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
srcConfig.Storage.RootDirectory = srcDir
|
||||
|
||||
|
@ -4514,7 +4529,13 @@ func TestOnDemandRetryGoroutine(t *testing.T) {
|
|||
|
||||
srcDir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", srcDir)
|
||||
srcStorageCtlr := test.GetDefaultStoreController(srcDir, log.NewLogger("debug", ""))
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
srcConfig.Storage.RootDirectory = srcDir
|
||||
|
||||
|
@ -4721,7 +4742,13 @@ func TestOnDemandMultipleImage(t *testing.T) {
|
|||
|
||||
srcDir := t.TempDir()
|
||||
|
||||
test.CopyTestFiles("../../../test/data", srcDir)
|
||||
srcStorageCtlr := test.GetDefaultStoreController(srcDir, log.NewLogger("debug", ""))
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
srcConfig.Storage.RootDirectory = srcDir
|
||||
|
||||
|
@ -5363,7 +5390,13 @@ func TestSyncOnlyDiff(t *testing.T) {
|
|||
destDir := t.TempDir()
|
||||
|
||||
// copy images so we have them before syncing, sync should not pull them again
|
||||
test.CopyTestFiles("../../../test/data", destDir)
|
||||
destStorageCtrl := test.GetDefaultStoreController(destDir, log.NewLogger("debug", ""))
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", destStorageCtrl)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", destStorageCtrl)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
destConfig.Storage.RootDirectory = destDir
|
||||
destConfig.Storage.Dedupe = false
|
||||
|
@ -5443,7 +5476,13 @@ func TestSyncWithDiffDigest(t *testing.T) {
|
|||
destDir := t.TempDir()
|
||||
|
||||
// copy images so we have them before syncing, sync should not pull them again
|
||||
test.CopyTestFiles("../../../test/data", destDir)
|
||||
srcStorageCtlr := test.GetDefaultStoreController(destDir, log.NewLogger("debug", ""))
|
||||
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-cve-test", "0.0.1", srcStorageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
destConfig.Storage.RootDirectory = destDir
|
||||
destConfig.Storage.Dedupe = false
|
||||
|
|
|
@ -48,7 +48,6 @@ type AuditLog struct {
|
|||
func TestAuditLogMessages(t *testing.T) {
|
||||
Convey("Make a new controller", t, func() {
|
||||
dir := t.TempDir()
|
||||
CopyTestFiles("../../test/data", dir)
|
||||
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
|
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
godigest "github.com/opencontainers/go-digest"
|
||||
|
@ -146,7 +145,8 @@ func TestGetReferrersErrors(t *testing.T) {
|
|||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
err := test.CopyFiles("../../../test/data/zot-test", path.Join(dir, "zot-test"))
|
||||
storageCtlr := storage.StoreController{DefaultStore: imgStore}
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultImage(), "zot-test", "0.0.1", storageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
digest := godigest.FromBytes([]byte("{}"))
|
||||
|
|
|
@ -208,8 +208,11 @@ func TestGetOrasReferrers(t *testing.T) {
|
|||
imgStore := local.NewImageStore(dir, true, storageConstants.DefaultGCDelay, true, true, log, metrics, nil, cacheDriver)
|
||||
|
||||
Convey("Get referrers", t, func(c C) {
|
||||
err := test.CopyFiles("../../../test/data/zot-test", path.Join(dir, "zot-test"))
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-test", "0.0.1", storage.StoreController{
|
||||
DefaultStore: imgStore,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
body := []byte("this is a blob")
|
||||
digest := godigest.FromBytes(body)
|
||||
buf := bytes.NewBuffer(body)
|
||||
|
@ -1083,7 +1086,8 @@ func FuzzGetOrasReferrers(f *testing.F) {
|
|||
imgStore := local.NewImageStore(dir, true, storageConstants.DefaultGCDelay, true, true, *log, metrics, nil,
|
||||
cacheDriver)
|
||||
|
||||
err := test.CopyFiles("../../../test/data/zot-test", path.Join(dir, "zot-test"))
|
||||
storageCtlr := storage.StoreController{DefaultStore: imgStore}
|
||||
err := test.WriteImageToFileSystem(test.CreateDefaultVulnerableImage(), "zot-test", "0.0.1", storageCtlr)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
@ -2551,11 +2555,14 @@ func TestGarbageCollectForImageStore(t *testing.T) {
|
|||
imgStore := local.NewImageStore(dir, true, 1*time.Second, true, true, log, metrics, nil, cacheDriver)
|
||||
repoName := "gc-all-repos-short"
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
image := test.CreateDefaultVulnerableImage()
|
||||
err := test.WriteImageToFileSystem(image, repoName, "0.0.1", storage.StoreController{
|
||||
DefaultStore: imgStore,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
var manifestDigest godigest.Digest
|
||||
manifestDigest, _, _ = test.GetOciLayoutDigests("../../../test/data/zot-test")
|
||||
err := os.Remove(path.Join(dir, repoName, "blobs/sha256", manifestDigest.Encoded()))
|
||||
manifestDigest := image.ManifestDescriptor.Digest
|
||||
err = os.Remove(path.Join(dir, repoName, "blobs/sha256", manifestDigest.Encoded()))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -2586,11 +2593,15 @@ func TestGarbageCollectForImageStore(t *testing.T) {
|
|||
imgStore := local.NewImageStore(dir, true, 1*time.Second, true, true, log, metrics, nil, cacheDriver)
|
||||
repoName := "gc-all-repos-short"
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, repoName))
|
||||
image := test.CreateDefaultVulnerableImage()
|
||||
err := test.WriteImageToFileSystem(image, repoName, "0.0.1", storage.StoreController{
|
||||
DefaultStore: imgStore,
|
||||
})
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
So(os.Chmod(path.Join(dir, repoName, "index.json"), 0o000), ShouldBeNil)
|
||||
|
||||
err := imgStore.RunGCRepo(repoName)
|
||||
err = imgStore.RunGCRepo(repoName)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
@ -3189,9 +3200,20 @@ func TestGetNextRepository(t *testing.T) {
|
|||
firstRepoName := "repo1"
|
||||
secondRepoName := "repo2"
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, firstRepoName))
|
||||
srcStorageCtlr := storage.StoreController{DefaultStore: imgStore}
|
||||
image := test.CreateDefaultImage()
|
||||
|
||||
test.CopyTestFiles("../../../test/data/zot-test", path.Join(dir, secondRepoName))
|
||||
err := test.WriteImageToFileSystem(image, firstRepoName, "0.0.1", srcStorageCtlr)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
err = test.WriteImageToFileSystem(image, secondRepoName, "0.0.1", srcStorageCtlr)
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
Convey("Return first repository", t, func() {
|
||||
firstRepo, err := imgStore.GetNextRepository("")
|
||||
|
|
|
@ -49,9 +49,14 @@ import (
|
|||
"oras.land/oras-go/v2/registry/remote"
|
||||
"oras.land/oras-go/v2/registry/remote/auth"
|
||||
|
||||
"zotregistry.io/zot/pkg/extensions/monitoring"
|
||||
zLog "zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
storageCommon "zotregistry.io/zot/pkg/storage/common"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
"zotregistry.io/zot/pkg/storage/types"
|
||||
"zotregistry.io/zot/pkg/test/inject"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -228,6 +233,38 @@ func CopyTestFiles(sourceDir, destDir string) {
|
|||
}
|
||||
}
|
||||
|
||||
func CopyTestKeysAndCerts(destDir string) error {
|
||||
files := []string{
|
||||
"ca.crt", "ca.key", "client.cert", "client.csr",
|
||||
"client.key", "server.cert", "server.csr", "server.key",
|
||||
}
|
||||
|
||||
rootPath, err := GetProjectRootDir()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
sourceDir := filepath.Join(rootPath, "test/data")
|
||||
|
||||
sourceMeta, err := os.Stat(sourceDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("CopyFiles os.Stat failed: %w", err)
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(destDir, sourceMeta.Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
err = CopyFile(filepath.Join(sourceDir, file), filepath.Join(destDir, file))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
type Controller interface {
|
||||
Init(ctx context.Context) error
|
||||
Run(ctx context.Context) error
|
||||
|
@ -2029,3 +2066,21 @@ func GetDefaultLayersBlobs() [][]byte {
|
|||
[]byte("xyz"),
|
||||
}
|
||||
}
|
||||
|
||||
func GetDefaultImageStore(rootDir string, log zLog.Logger) types.ImageStore {
|
||||
return local.NewImageStore(rootDir, false, time.Hour, false, false, log,
|
||||
monitoring.NewMetricsServer(false, log),
|
||||
mocks.MockedLint{
|
||||
LintFn: func(repo string, manifestDigest godigest.Digest, imageStore types.ImageStore) (bool, error) {
|
||||
return true, nil
|
||||
},
|
||||
},
|
||||
mocks.CacheMock{},
|
||||
)
|
||||
}
|
||||
|
||||
func GetDefaultStoreController(rootDir string, log zLog.Logger) storage.StoreController {
|
||||
return storage.StoreController{
|
||||
DefaultStore: GetDefaultImageStore(rootDir, log),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"io"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
|
@ -22,6 +23,7 @@ import (
|
|||
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
"zotregistry.io/zot/pkg/test/inject"
|
||||
|
@ -131,9 +133,13 @@ func TestGetOciLayoutDigests(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("no permissions when getting index", t, func() {
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, "test-index"))
|
||||
storageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
image := test.CreateDefaultImage()
|
||||
|
||||
err := os.Chmod(path.Join(dir, "test-index", "index.json"), 0o000)
|
||||
err := test.WriteImageToFileSystem(image, "test-index", "0.0.1", storageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = os.Chmod(path.Join(dir, "test-index", "index.json"), 0o000)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -147,7 +153,11 @@ func TestGetOciLayoutDigests(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("can't access manifest digest", t, func() {
|
||||
test.CopyTestFiles("../../test/data/zot-test", path.Join(dir, "test-manifest"))
|
||||
storageCtlr := test.GetDefaultStoreController(dir, log.NewLogger("debug", ""))
|
||||
image := test.CreateDefaultImage()
|
||||
|
||||
err := test.WriteImageToFileSystem(image, "test-manifest", "0.0.1", storageCtlr)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
buf, err := os.ReadFile(path.Join(dir, "test-manifest", "index.json"))
|
||||
if err != nil {
|
||||
|
@ -1504,3 +1514,46 @@ func TestBearerServer(t *testing.T) {
|
|||
So(func() { test.MakeAuthTestServer("", "") }, ShouldPanic)
|
||||
})
|
||||
}
|
||||
|
||||
func TestCopyTestKeysAndCerts(t *testing.T) {
|
||||
Convey("CopyTestKeysAndCerts", t, func() {
|
||||
// ------- Make test files unreadable -------
|
||||
dir := t.TempDir()
|
||||
file := filepath.Join(dir, "ca.crt")
|
||||
|
||||
_, err := os.Create(file)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = os.Chmod(file, 0o000)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.CopyTestKeysAndCerts(dir)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
err = os.Chmod(file, 0o777)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// ------- Copy fails -------
|
||||
|
||||
err = os.Chmod(dir, 0o000)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.CopyTestKeysAndCerts(file)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
err = os.Chmod(dir, 0o777)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
// ------- Folder creation fails -------
|
||||
|
||||
file = filepath.Join(dir, "a-file.file")
|
||||
_, err = os.Create(file)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
_, err = os.Stat(file)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = test.CopyTestKeysAndCerts(file)
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -156,8 +156,8 @@ func CreateRandomImageWith() ManifestBuilder {
|
|||
return CreateImageWith().RandomLayers(layerCount, layerSize).RandomConfig()
|
||||
}
|
||||
|
||||
// CreateVulnerableImage creates a vulnerable image with the default config.
|
||||
func CreateVulnerableImage() Image {
|
||||
// CreateDefaultVulnerableImage creates a vulnerable image with the default config.
|
||||
func CreateDefaultVulnerableImage() Image {
|
||||
return CreateImageWith().VulnerableLayers().DefaultVulnConfig().Build()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue