2022-04-27 01:00:20 -05:00
|
|
|
//go:build search
|
|
|
|
// +build search
|
2021-10-15 10:05:00 -05:00
|
|
|
|
2022-10-05 05:21:14 -05:00
|
|
|
//nolint:gochecknoinits
|
2021-05-26 12:22:31 -05:00
|
|
|
package digestinfo_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-09-30 12:32:32 -05:00
|
|
|
"net/url"
|
2021-05-26 12:22:31 -05:00
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"gopkg.in/resty.v1"
|
2022-10-20 11:39:20 -05:00
|
|
|
|
2021-12-03 22:50:58 -05:00
|
|
|
"zotregistry.io/zot/pkg/api"
|
|
|
|
"zotregistry.io/zot/pkg/api/config"
|
2022-02-24 15:31:36 -05:00
|
|
|
"zotregistry.io/zot/pkg/api/constants"
|
2021-12-03 22:50:58 -05:00
|
|
|
extconf "zotregistry.io/zot/pkg/extensions/config"
|
|
|
|
"zotregistry.io/zot/pkg/extensions/monitoring"
|
|
|
|
digestinfo "zotregistry.io/zot/pkg/extensions/search/digest"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
2023-02-15 14:34:07 -05:00
|
|
|
"zotregistry.io/zot/pkg/meta/repodb"
|
2021-12-03 22:50:58 -05:00
|
|
|
"zotregistry.io/zot/pkg/storage"
|
2022-09-30 12:35:16 -05:00
|
|
|
"zotregistry.io/zot/pkg/storage/local"
|
2022-01-19 14:54:17 -05:00
|
|
|
. "zotregistry.io/zot/pkg/test"
|
2021-05-26 12:22:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type ImgResponseForDigest struct {
|
|
|
|
ImgListForDigest ImgListForDigest `json:"data"`
|
|
|
|
Errors []ErrorGQL `json:"errors"`
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
//nolint:tagliatelle // graphQL schema
|
2021-05-26 12:22:31 -05:00
|
|
|
type ImgListForDigest struct {
|
2023-02-15 14:34:07 -05:00
|
|
|
PaginatedImagesResult `json:"ImageListForDigest"`
|
2021-05-26 12:22:31 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
//nolint:tagliatelle // graphQL schema
|
2021-05-26 12:22:31 -05:00
|
|
|
type ImgInfo struct {
|
2022-01-19 10:57:10 -05:00
|
|
|
RepoName string `json:"RepoName"`
|
|
|
|
Tag string `json:"Tag"`
|
|
|
|
ConfigDigest string `json:"ConfigDigest"`
|
|
|
|
Digest string `json:"Digest"`
|
|
|
|
Size string `json:"Size"`
|
2021-05-26 12:22:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
type ErrorGQL struct {
|
|
|
|
Message string `json:"message"`
|
|
|
|
Path []string `json:"path"`
|
|
|
|
}
|
|
|
|
|
2023-02-15 14:34:07 -05:00
|
|
|
type PaginatedImagesResult struct {
|
|
|
|
Results []ImgInfo `json:"results"`
|
|
|
|
Page repodb.PageInfo `json:"page"`
|
|
|
|
}
|
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
func testSetup(t *testing.T) (string, string, *digestinfo.DigestInfo) {
|
|
|
|
t.Helper()
|
|
|
|
dir := t.TempDir()
|
|
|
|
subDir := t.TempDir()
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
rootDir := dir
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
subRootDir := subDir
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-05-26 12:22:31 -05:00
|
|
|
// Test images used/copied:
|
|
|
|
// IMAGE NAME TAG DIGEST CONFIG LAYERS SIZE
|
|
|
|
// zot-test 0.0.1 2bacca16 adf3bb6c 76MB
|
|
|
|
// 2d473b07 76MB
|
|
|
|
// zot-cve-test 0.0.1 63a795ca 8dd57e17 75MB
|
|
|
|
// 7a0437f0 75MB
|
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
err := os.Mkdir(subDir+"/a", 0o700)
|
2021-09-30 08:27:13 -05:00
|
|
|
if err != nil {
|
2022-10-26 11:14:16 -05:00
|
|
|
panic(err)
|
2021-09-30 08:27:13 -05:00
|
|
|
}
|
|
|
|
|
2023-01-19 11:54:05 -05:00
|
|
|
CopyTestFiles("../../../../test/data", rootDir)
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2023-01-19 11:54:05 -05:00
|
|
|
CopyTestFiles("../../../../test/data", subDir+"/a/")
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-05-26 12:22:31 -05:00
|
|
|
log := log.NewLogger("debug", "")
|
2021-10-15 10:05:00 -05:00
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
2022-01-20 23:11:44 -05:00
|
|
|
storeController := storage.StoreController{
|
2022-11-02 17:53:08 -05:00
|
|
|
DefaultStore: local.NewImageStore(rootDir, false, storage.DefaultGCDelay, false, false, log, metrics, nil, nil),
|
2022-01-20 23:11:44 -05:00
|
|
|
}
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
digestInfo := digestinfo.NewDigestInfo(storeController, log)
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
return rootDir, subRootDir, digestInfo
|
2021-05-26 12:22:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDigestInfo(t *testing.T) {
|
|
|
|
Convey("Test image tag", t, func() {
|
2022-10-26 11:14:16 -05:00
|
|
|
_, _, digestInfo := testSetup(t)
|
2022-05-10 03:28:26 -05:00
|
|
|
|
2022-01-19 10:57:10 -05:00
|
|
|
// Search by manifest digest
|
2022-10-26 11:14:16 -05:00
|
|
|
imageTags, err := digestInfo.GetImageTagsByDigest("zot-cve-test",
|
|
|
|
GetTestBlobDigest("zot-cve-test", "manifest").Encoded())
|
2021-05-26 12:22:31 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(imageTags), ShouldEqual, 1)
|
2022-01-19 10:57:10 -05:00
|
|
|
So(imageTags[0].Tag, ShouldEqual, "0.0.1")
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// Search by config digest
|
2022-10-26 11:14:16 -05:00
|
|
|
imageTags, err = digestInfo.GetImageTagsByDigest("zot-test", GetTestBlobDigest("zot-test", "config").Encoded())
|
2021-05-26 12:22:31 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(imageTags), ShouldEqual, 1)
|
2022-01-19 10:57:10 -05:00
|
|
|
So(imageTags[0].Tag, ShouldEqual, "0.0.1")
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// Search by layer digest
|
2022-10-26 11:14:16 -05:00
|
|
|
imageTags, err = digestInfo.GetImageTagsByDigest("zot-cve-test", GetTestBlobDigest("zot-cve-test", "layer").Encoded())
|
2021-05-26 12:22:31 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(imageTags), ShouldEqual, 1)
|
2022-01-19 10:57:10 -05:00
|
|
|
So(imageTags[0].Tag, ShouldEqual, "0.0.1")
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// Search by non-existent image
|
2022-10-26 11:14:16 -05:00
|
|
|
imageTags, err = digestInfo.GetImageTagsByDigest("zot-tes", GetTestBlobDigest("zot-test", "manifest").Encoded())
|
2021-05-26 12:22:31 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(len(imageTags), ShouldEqual, 0)
|
|
|
|
|
|
|
|
// Search by non-existent digest
|
2021-09-30 08:27:13 -05:00
|
|
|
imageTags, err = digestInfo.GetImageTagsByDigest("zot-test", "111")
|
2021-05-26 12:22:31 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(imageTags), ShouldEqual, 0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDigestSearchHTTP(t *testing.T) {
|
|
|
|
Convey("Test image search by digest scanning", t, func() {
|
2022-10-26 11:14:16 -05:00
|
|
|
rootDir, _, _ := testSetup(t)
|
|
|
|
|
2021-11-10 09:31:03 -05:00
|
|
|
port := GetFreePort()
|
|
|
|
baseURL := GetBaseURL(port)
|
2021-06-08 15:11:18 -05:00
|
|
|
conf := config.New()
|
2021-11-10 09:31:03 -05:00
|
|
|
conf.HTTP.Port = port
|
2021-06-08 15:11:18 -05:00
|
|
|
conf.Storage.RootDirectory = rootDir
|
2021-12-28 08:29:30 -05:00
|
|
|
defaultVal := true
|
2021-06-08 15:11:18 -05:00
|
|
|
conf.Extensions = &extconf.ExtensionConfig{
|
2022-10-21 07:33:54 -05:00
|
|
|
Search: &extconf.SearchConfig{BaseConfig: extconf.BaseConfig{Enable: &defaultVal}},
|
2021-05-26 12:22:31 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
ctlr := api.NewController(conf)
|
2023-01-19 11:54:05 -05:00
|
|
|
ctrlManager := NewControllerManager(ctlr)
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2023-01-19 11:54:05 -05:00
|
|
|
ctrlManager.StartAndWait(port)
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// shut down server
|
2023-01-19 11:54:05 -05:00
|
|
|
defer ctrlManager.StopServer()
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2021-11-10 09:31:03 -05:00
|
|
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2022-10-18 22:46:06 -05:00
|
|
|
resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix)
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
2022-07-15 06:10:51 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 422)
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// "sha" should match all digests in all images
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2022-10-18 22:46:06 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + `?query={ImageListForDigest(id:"sha")` +
|
2023-02-15 14:34:07 -05:00
|
|
|
`{Results{RepoName%20Tag%20Digest%20ConfigDigest%20Size%20Layers%20{%20Digest}}}}`,
|
2022-01-19 10:57:10 -05:00
|
|
|
)
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
var responseStruct ImgResponseForDigest
|
|
|
|
err = json.Unmarshal(resp.Body(), &responseStruct)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(responseStruct.Errors), ShouldEqual, 0)
|
2023-02-15 14:34:07 -05:00
|
|
|
So(len(responseStruct.ImgListForDigest.Results), ShouldEqual, 2)
|
|
|
|
So(responseStruct.ImgListForDigest.Results[0].Tag, ShouldEqual, "0.0.1")
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// Call should return {"data":{"ImageListForDigest":[{"Name":"zot-test","Tags":["0.0.1"]}]}}
|
2022-10-26 11:14:16 -05:00
|
|
|
// GetTestBlobDigest("zot-test", "manifest").Encoded() should match the manifest of 1 image
|
2022-09-30 12:32:32 -05:00
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
gqlQuery := url.QueryEscape(`{ImageListForDigest(id:"` + GetTestBlobDigest("zot-test", "manifest").Encoded() + `")
|
2023-02-15 14:34:07 -05:00
|
|
|
{Results{RepoName Tag Digest ConfigDigest Size Layers { Digest }}}}`)
|
2022-10-18 22:46:06 -05:00
|
|
|
targetURL := baseURL + constants.FullSearchPrefix + `?query=` + gqlQuery
|
2022-09-30 12:32:32 -05:00
|
|
|
|
|
|
|
resp, err = resty.R().Get(targetURL)
|
|
|
|
So(string(resp.Body()), ShouldNotBeNil)
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &responseStruct)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(responseStruct.Errors), ShouldEqual, 0)
|
2023-02-15 14:34:07 -05:00
|
|
|
So(len(responseStruct.ImgListForDigest.Results), ShouldEqual, 1)
|
|
|
|
So(responseStruct.ImgListForDigest.Results[0].RepoName, ShouldEqual, "zot-test")
|
|
|
|
So(responseStruct.ImgListForDigest.Results[0].Tag, ShouldEqual, "0.0.1")
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2022-10-26 11:14:16 -05:00
|
|
|
// GetTestBlobDigest("zot-test", "config").Encoded() should match the config of 1 image.
|
|
|
|
gqlQuery = url.QueryEscape(`{ImageListForDigest(id:"` + GetTestBlobDigest("zot-test", "config").Encoded() + `")
|
2023-02-15 14:34:07 -05:00
|
|
|
{Results{RepoName Tag Digest ConfigDigest Size Layers { Digest }}}}`)
|
2022-09-30 12:32:32 -05:00
|
|
|
|
2022-10-18 22:46:06 -05:00
|
|
|
targetURL = baseURL + constants.FullSearchPrefix + `?query=` + gqlQuery
|
2022-09-30 12:32:32 -05:00
|
|
|
resp, err = resty.R().Get(targetURL)
|
|
|
|
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &responseStruct)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(responseStruct.Errors), ShouldEqual, 0)
|
2023-02-15 14:34:07 -05:00
|
|
|
So(len(responseStruct.ImgListForDigest.Results), ShouldEqual, 1)
|
|
|
|
So(responseStruct.ImgListForDigest.Results[0].RepoName, ShouldEqual, "zot-test")
|
|
|
|
So(responseStruct.ImgListForDigest.Results[0].Tag, ShouldEqual, "0.0.1")
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// Call should return {"data":{"ImageListForDigest":[{"Name":"zot-cve-test","Tags":["0.0.1"]}]}}
|
2022-10-26 11:14:16 -05:00
|
|
|
// GetTestBlobDigest("zot-cve-test", "layer").Encoded() should match the layer of 1 image
|
|
|
|
gqlQuery = url.QueryEscape(`{ImageListForDigest(id:"` + GetTestBlobDigest("zot-cve-test", "layer").Encoded() + `")
|
2023-02-15 14:34:07 -05:00
|
|
|
{Results{RepoName Tag Digest ConfigDigest Size Layers { Digest }}}}`)
|
2022-10-18 22:46:06 -05:00
|
|
|
targetURL = baseURL + constants.FullSearchPrefix + `?query=` + gqlQuery
|
2022-09-30 12:32:32 -05:00
|
|
|
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2022-09-30 12:32:32 -05:00
|
|
|
targetURL,
|
2022-01-19 10:57:10 -05:00
|
|
|
)
|
2022-09-30 12:32:32 -05:00
|
|
|
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2022-09-30 12:32:32 -05:00
|
|
|
var responseStruct2 ImgResponseForDigest
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2022-09-30 12:32:32 -05:00
|
|
|
err = json.Unmarshal(resp.Body(), &responseStruct2)
|
2021-05-26 12:22:31 -05:00
|
|
|
So(err, ShouldBeNil)
|
2022-09-30 12:32:32 -05:00
|
|
|
So(len(responseStruct2.Errors), ShouldEqual, 0)
|
2023-02-15 14:34:07 -05:00
|
|
|
So(len(responseStruct2.ImgListForDigest.Results), ShouldEqual, 1)
|
|
|
|
So(responseStruct2.ImgListForDigest.Results[0].RepoName, ShouldEqual, "zot-cve-test")
|
|
|
|
So(responseStruct2.ImgListForDigest.Results[0].Tag, ShouldEqual, "0.0.1")
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// Call should return {"data":{"ImageListForDigest":[]}}
|
|
|
|
// "1111111" should match 0 images
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2022-10-18 22:46:06 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + `?query={ImageListForDigest(id:"1111111")` +
|
2023-02-15 14:34:07 -05:00
|
|
|
`{Results{RepoName%20Tag%20Digest%20ConfigDigest%20Size%20Layers%20{%20Digest}}}}`,
|
2022-01-19 10:57:10 -05:00
|
|
|
)
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &responseStruct)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(responseStruct.Errors), ShouldEqual, 0)
|
2023-02-15 14:34:07 -05:00
|
|
|
So(len(responseStruct.ImgListForDigest.Results), ShouldEqual, 0)
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
// Call should return {"errors": [{....}]", data":null}}
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2022-10-18 22:46:06 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + `?query={ImageListForDigest(id:"1111111")` +
|
2023-02-15 14:34:07 -05:00
|
|
|
`{Results{RepoName%20Tag343s}}}`,
|
2022-01-19 10:57:10 -05:00
|
|
|
)
|
2021-05-26 12:22:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 422)
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &responseStruct)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(responseStruct.Errors), ShouldEqual, 1)
|
2021-09-30 08:27:13 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDigestSearchHTTPSubPaths(t *testing.T) {
|
|
|
|
Convey("Test image search by digest scanning using storage subpaths", t, func() {
|
2022-10-26 11:14:16 -05:00
|
|
|
_, subRootDir, _ := testSetup(t)
|
|
|
|
|
2021-11-10 09:31:03 -05:00
|
|
|
port := GetFreePort()
|
|
|
|
baseURL := GetBaseURL(port)
|
2021-06-08 15:11:18 -05:00
|
|
|
conf := config.New()
|
2021-11-10 09:31:03 -05:00
|
|
|
conf.HTTP.Port = port
|
2021-12-28 08:29:30 -05:00
|
|
|
defaultVal := true
|
2021-06-08 15:11:18 -05:00
|
|
|
conf.Extensions = &extconf.ExtensionConfig{
|
2022-10-21 07:33:54 -05:00
|
|
|
Search: &extconf.SearchConfig{BaseConfig: extconf.BaseConfig{Enable: &defaultVal}},
|
2021-09-30 08:27:13 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
ctlr := api.NewController(conf)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2023-02-02 14:39:03 -05:00
|
|
|
globalDir := t.TempDir()
|
2021-09-30 08:27:13 -05:00
|
|
|
defer os.RemoveAll(globalDir)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
ctlr.Config.Storage.RootDirectory = globalDir
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
subPathMap := make(map[string]config.StorageConfig)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
subPathMap["/a"] = config.StorageConfig{RootDirectory: subRootDir}
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
ctlr.Config.Storage.SubPaths = subPathMap
|
2023-01-19 11:54:05 -05:00
|
|
|
ctrlManager := NewControllerManager(ctlr)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2023-01-19 11:54:05 -05:00
|
|
|
ctrlManager.StartAndWait(port)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
|
|
|
// shut down server
|
2023-01-19 11:54:05 -05:00
|
|
|
defer ctrlManager.StopServer()
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-11-10 09:31:03 -05:00
|
|
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
2021-09-30 08:27:13 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2022-10-18 22:46:06 -05:00
|
|
|
resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix)
|
2021-09-30 08:27:13 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
2022-07-15 06:10:51 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 422)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2022-10-18 22:46:06 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + `?query={ImageListForDigest(id:"sha")` +
|
2023-02-15 14:34:07 -05:00
|
|
|
`{Results{RepoName%20Tag%20Digest%20ConfigDigest%20Size%20Layers%20{%20Digest}}}}`,
|
2022-01-19 10:57:10 -05:00
|
|
|
)
|
2021-09-30 08:27:13 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
var responseStruct ImgResponseForDigest
|
|
|
|
err = json.Unmarshal(resp.Body(), &responseStruct)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(responseStruct.Errors), ShouldEqual, 0)
|
2023-02-15 14:34:07 -05:00
|
|
|
So(len(responseStruct.ImgListForDigest.Results), ShouldEqual, 2)
|
2021-05-26 12:22:31 -05:00
|
|
|
})
|
|
|
|
}
|
2021-06-08 13:37:31 -05:00
|
|
|
|
|
|
|
func TestDigestSearchDisabled(t *testing.T) {
|
|
|
|
Convey("Test disabling image search", t, func() {
|
2021-12-28 08:29:30 -05:00
|
|
|
var disabled bool
|
2021-11-10 09:31:03 -05:00
|
|
|
port := GetFreePort()
|
|
|
|
baseURL := GetBaseURL(port)
|
2021-06-08 15:11:18 -05:00
|
|
|
conf := config.New()
|
2021-11-10 09:31:03 -05:00
|
|
|
conf.HTTP.Port = port
|
2022-03-07 03:55:12 -05:00
|
|
|
conf.Storage.RootDirectory = t.TempDir()
|
2021-06-08 15:11:18 -05:00
|
|
|
conf.Extensions = &extconf.ExtensionConfig{
|
2022-10-21 07:33:54 -05:00
|
|
|
Search: &extconf.SearchConfig{BaseConfig: extconf.BaseConfig{Enable: &disabled}},
|
2021-06-08 13:37:31 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
ctlr := api.NewController(conf)
|
2023-01-19 11:54:05 -05:00
|
|
|
ctrlManager := NewControllerManager(ctlr)
|
2021-06-08 13:37:31 -05:00
|
|
|
|
2023-01-19 11:54:05 -05:00
|
|
|
ctrlManager.StartAndWait(port)
|
2021-06-08 13:37:31 -05:00
|
|
|
|
|
|
|
// shut down server
|
2023-01-19 11:54:05 -05:00
|
|
|
defer ctrlManager.StopServer()
|
2021-06-08 13:37:31 -05:00
|
|
|
|
2021-11-10 09:31:03 -05:00
|
|
|
resp, err := resty.R().Get(baseURL + "/v2/")
|
2021-06-08 13:37:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2022-10-18 22:46:06 -05:00
|
|
|
resp, err = resty.R().Get(baseURL + constants.FullSearchPrefix)
|
2021-06-08 13:37:31 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
}
|