2023-05-25 06:46:52 -05:00
|
|
|
//go:build !search && !mgmt && !userprefs
|
|
|
|
|
|
|
|
package extensions_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
distext "github.com/opencontainers/distribution-spec/specs-go/v1/extensions"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"gopkg.in/resty.v1"
|
|
|
|
|
|
|
|
"zotregistry.io/zot/pkg/api"
|
|
|
|
"zotregistry.io/zot/pkg/api/config"
|
|
|
|
"zotregistry.io/zot/pkg/api/constants"
|
|
|
|
extconf "zotregistry.io/zot/pkg/extensions/config"
|
|
|
|
"zotregistry.io/zot/pkg/test"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetExensionsDisabled(t *testing.T) {
|
|
|
|
Convey("start zot server with extensions but no extensions built", t, func(c C) {
|
|
|
|
conf := config.New()
|
|
|
|
port := test.GetFreePort()
|
|
|
|
baseURL := test.GetBaseURL(port)
|
|
|
|
|
|
|
|
conf.HTTP.Port = port
|
|
|
|
|
|
|
|
defaultVal := true
|
|
|
|
|
2023-08-02 13:58:34 -05:00
|
|
|
conf.Extensions = &extconf.ExtensionConfig{}
|
|
|
|
conf.Extensions.Search = &extconf.SearchConfig{}
|
|
|
|
conf.Extensions.Search.Enable = &defaultVal
|
|
|
|
conf.Extensions.Search.CVE = nil
|
|
|
|
conf.Extensions.UI = &extconf.UIConfig{}
|
|
|
|
conf.Extensions.UI.Enable = &defaultVal
|
2023-05-25 06:46:52 -05:00
|
|
|
|
|
|
|
logFile, err := os.CreateTemp("", "zot-log*.txt")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
conf.Log.Output = logFile.Name()
|
|
|
|
defer os.Remove(logFile.Name()) // clean up
|
|
|
|
|
2023-08-18 03:46:11 -05:00
|
|
|
ctlr := makeController(conf, t.TempDir())
|
2023-05-25 06:46:52 -05:00
|
|
|
|
|
|
|
cm := test.NewControllerManager(ctlr)
|
|
|
|
cm.StartAndWait(port)
|
|
|
|
defer cm.StopServer()
|
|
|
|
|
|
|
|
var extensionList distext.ExtensionList
|
|
|
|
|
|
|
|
resp, err := resty.R().Get(baseURL + constants.RoutePrefix + constants.ExtOciDiscoverPrefix)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
err = json.Unmarshal(resp.Body(), &extensionList)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(extensionList.Extensions), ShouldEqual, 0)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-08-18 03:46:11 -05:00
|
|
|
func makeController(conf *config.Config, dir string) *api.Controller {
|
2023-05-25 06:46:52 -05:00
|
|
|
ctlr := api.NewController(conf)
|
|
|
|
ctlr.Config.Storage.RootDirectory = dir
|
|
|
|
|
|
|
|
return ctlr
|
|
|
|
}
|