2022-04-27 01:00:20 -05:00
|
|
|
//go:build search
|
|
|
|
// +build search
|
2021-10-15 10:05:00 -05:00
|
|
|
|
2023-03-24 07:32:02 -05:00
|
|
|
package search_test
|
2021-05-26 12:22:31 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2022-09-30 12:32:32 -05:00
|
|
|
"net/url"
|
2021-05-26 12:22:31 -05:00
|
|
|
"os"
|
|
|
|
"testing"
|
2023-03-24 07:32:02 -05:00
|
|
|
"time"
|
2021-05-26 12:22:31 -05:00
|
|
|
|
2023-03-24 07:32:02 -05:00
|
|
|
godigest "github.com/opencontainers/go-digest"
|
|
|
|
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
2021-05-26 12:22:31 -05:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"gopkg.in/resty.v1"
|
2022-10-20 11:39:20 -05:00
|
|
|
|
2024-01-31 23:34:07 -05:00
|
|
|
"zotregistry.dev/zot/pkg/api"
|
|
|
|
"zotregistry.dev/zot/pkg/api/config"
|
|
|
|
"zotregistry.dev/zot/pkg/api/constants"
|
|
|
|
"zotregistry.dev/zot/pkg/common"
|
|
|
|
extconf "zotregistry.dev/zot/pkg/extensions/config"
|
|
|
|
. "zotregistry.dev/zot/pkg/test/common"
|
|
|
|
. "zotregistry.dev/zot/pkg/test/image-utils"
|
2021-05-26 12:22:31 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type ImgResponseForDigest struct {
|
2023-05-25 13:27:49 -05:00
|
|
|
ImgListForDigest ImgListForDigest `json:"data"`
|
|
|
|
Errors []common.ErrorGQL `json:"errors"`
|
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 ImgListForDigest struct {
|
2023-04-18 13:07:47 -05:00
|
|
|
PaginatedImagesResultForDigest `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
|
|
|
}
|
|
|
|
|
2023-04-18 13:07:47 -05:00
|
|
|
type PaginatedImagesResultForDigest struct {
|
2023-02-15 14:34:07 -05:00
|
|
|
Results []ImgInfo `json:"results"`
|
2023-05-25 13:27:49 -05:00
|
|
|
Page common.PageInfo `json:"page"`
|
2023-02-15 14:34:07 -05:00
|
|
|
}
|
|
|
|
|
2021-05-26 12:22:31 -05:00
|
|
|
func TestDigestSearchHTTP(t *testing.T) {
|
|
|
|
Convey("Test image search by digest scanning", t, func() {
|
2023-03-24 07:32:02 -05:00
|
|
|
rootDir := t.TempDir()
|
2022-10-26 11:14:16 -05:00
|
|
|
|
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
|
|
|
|
2023-03-24 07:32:02 -05:00
|
|
|
createdTime1 := time.Date(2009, 1, 1, 12, 0, 0, 0, time.UTC)
|
|
|
|
layers1 := [][]byte{
|
|
|
|
{3, 2, 2},
|
|
|
|
}
|
2024-01-22 12:10:34 -05:00
|
|
|
|
|
|
|
image1 := CreateImageWith().
|
|
|
|
LayerBlobs(layers1).
|
|
|
|
ImageConfig(ispec.Image{
|
2023-03-24 07:32:02 -05:00
|
|
|
Created: &createdTime1,
|
|
|
|
History: []ispec.History{
|
|
|
|
{
|
|
|
|
Created: &createdTime1,
|
|
|
|
},
|
|
|
|
},
|
2024-01-22 12:10:34 -05:00
|
|
|
}).Build()
|
2023-03-24 07:32:02 -05:00
|
|
|
|
2023-04-24 13:13:15 -05:00
|
|
|
const ver001 = "0.0.1"
|
2023-07-28 09:53:46 -05:00
|
|
|
|
2024-01-22 12:10:34 -05:00
|
|
|
err := UploadImage(image1, baseURL, "zot-cve-test", ver001)
|
2023-03-24 07:32:02 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
createdTime2 := time.Date(2010, 1, 1, 12, 0, 0, 0, time.UTC)
|
2024-01-22 12:10:34 -05:00
|
|
|
|
|
|
|
image2 := CreateImageWith().
|
|
|
|
LayerBlobs([][]byte{{0, 0, 2}}).
|
|
|
|
ImageConfig(ispec.Image{
|
2023-03-24 07:32:02 -05:00
|
|
|
History: []ispec.History{{Created: &createdTime2}},
|
|
|
|
Platform: ispec.Platform{
|
|
|
|
Architecture: "amd64",
|
|
|
|
OS: "linux",
|
|
|
|
},
|
2024-01-22 12:10:34 -05:00
|
|
|
}).Build()
|
2023-03-24 07:32:02 -05:00
|
|
|
|
2023-07-26 05:08:04 -05:00
|
|
|
manifestDigest := image2.Digest()
|
2023-03-24 07:32:02 -05:00
|
|
|
|
2023-07-28 09:53:46 -05:00
|
|
|
err = UploadImage(image2, baseURL, "zot-test", ver001)
|
2023-03-24 07:32:02 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
configBlob, err := json.Marshal(image2.Config)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
configDigest := godigest.FromBytes(configBlob)
|
|
|
|
|
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
|
2023-02-27 14:23:18 -05:00
|
|
|
query := `{
|
|
|
|
ImageListForDigest(id:"sha") {
|
|
|
|
Results {
|
|
|
|
RepoName Tag
|
|
|
|
Manifests {
|
|
|
|
Digest ConfigDigest Size
|
|
|
|
Layers { Digest }
|
|
|
|
}
|
|
|
|
Size
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2023-02-27 14:23:18 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query),
|
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
|
|
|
|
2023-03-24 07:32:02 -05:00
|
|
|
gqlQuery := url.QueryEscape(`{ImageListForDigest(id:"` + manifestDigest.Encoded() + `")
|
2023-02-27 14:23:18 -05:00
|
|
|
{Results{RepoName Tag Manifests {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
|
|
|
|
2023-03-24 07:32:02 -05:00
|
|
|
gqlQuery = url.QueryEscape(`{ImageListForDigest(id:"` + configDigest.Encoded() + `")
|
2023-02-27 14:23:18 -05:00
|
|
|
{Results{RepoName Tag Manifests {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
|
2023-03-24 07:32:02 -05:00
|
|
|
layerDigest1 := godigest.FromBytes((layers1[0]))
|
|
|
|
gqlQuery = url.QueryEscape(`{ImageListForDigest(id:"` + layerDigest1.Encoded() + `")
|
2023-02-27 14:23:18 -05:00
|
|
|
{Results{RepoName Tag Manifests {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)
|
2024-07-29 12:32:51 -05:00
|
|
|
|
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
|
2023-02-27 14:23:18 -05:00
|
|
|
query = `
|
|
|
|
{
|
|
|
|
ImageListForDigest(id:"1111111") {
|
|
|
|
Results {
|
|
|
|
RepoName Tag
|
|
|
|
Manifests {
|
|
|
|
Digest ConfigDigest Size
|
|
|
|
Layers { Digest }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2023-02-27 14:23:18 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query),
|
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}}
|
2023-02-27 14:23:18 -05:00
|
|
|
query = `{
|
|
|
|
ImageListForDigest(id:"1111111") {
|
|
|
|
Results {
|
|
|
|
RepoName Tag343s
|
|
|
|
}
|
|
|
|
}`
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2023-02-27 14:23:18 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query),
|
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() {
|
2023-03-24 07:32:02 -05:00
|
|
|
subRootDir := t.TempDir()
|
2022-10-26 11:14:16 -05:00
|
|
|
|
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
|
|
|
|
2024-01-22 12:10:34 -05:00
|
|
|
image := CreateDefaultImage()
|
2023-03-24 07:32:02 -05:00
|
|
|
|
2024-01-22 12:10:34 -05:00
|
|
|
err := UploadImage(image, baseURL, "a/zot-cve-test", "0.0.1")
|
2023-03-24 07:32:02 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2024-01-22 12:10:34 -05:00
|
|
|
err = UploadImage(image, baseURL, "a/zot-test", "0.0.1")
|
2023-03-24 07:32:02 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
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
|
|
|
|
2023-02-27 14:23:18 -05:00
|
|
|
query := `{
|
|
|
|
ImageListForDigest(id:"sha") {
|
|
|
|
Results {
|
|
|
|
RepoName Tag
|
|
|
|
Manifests {
|
|
|
|
Digest ConfigDigest Size
|
|
|
|
Layers { Digest }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
2022-01-19 10:57:10 -05:00
|
|
|
resp, err = resty.R().Get(
|
2023-02-27 14:23:18 -05:00
|
|
|
baseURL + constants.FullSearchPrefix + "?query=" + url.QueryEscape(query),
|
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)
|
|
|
|
})
|
|
|
|
}
|