mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
feat: verifying and enabling necessary extensions for ui (#1369)
Signed-off-by: Ana-Roberta Lisca <ana.kagome@yahoo.com>
This commit is contained in:
committed by
GitHub
parent
7d7bc9d5e4
commit
e262fbea64
@@ -314,6 +314,20 @@ func validateCacheConfig(cfg *config.Config) error {
|
||||
}
|
||||
|
||||
func validateExtensionsConfig(cfg *config.Config) error {
|
||||
if cfg.Extensions != nil && cfg.Extensions.UI != nil && cfg.Extensions.UI.Enable != nil && *cfg.Extensions.UI.Enable {
|
||||
if cfg.Extensions.Mgmt == nil || !*cfg.Extensions.Mgmt.Enable {
|
||||
log.Warn().Err(errors.ErrBadConfig).Msg("UI functionality can't be used without mgmt extension.")
|
||||
|
||||
return errors.ErrBadConfig
|
||||
}
|
||||
|
||||
if cfg.Extensions.Search == nil || !*cfg.Extensions.Search.Enable {
|
||||
log.Warn().Err(errors.ErrBadConfig).Msg("UI functionality can't be used without search extension.")
|
||||
|
||||
return errors.ErrBadConfig
|
||||
}
|
||||
}
|
||||
|
||||
//nolint:lll
|
||||
if cfg.Storage.StorageDriver != nil && cfg.Extensions != nil && cfg.Extensions.Search != nil &&
|
||||
cfg.Extensions.Search.Enable != nil && *cfg.Extensions.Search.Enable && cfg.Extensions.Search.CVE != nil {
|
||||
|
||||
@@ -1018,6 +1018,100 @@ func TestVerify(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestValidateExtensionsConfig(t *testing.T) {
|
||||
Convey("Test missing extensions for UI to work", t, func(c C) {
|
||||
config := config.New()
|
||||
tmpfile, err := os.CreateTemp("", "zot-test*.json")
|
||||
So(err, ShouldBeNil)
|
||||
defer os.Remove(tmpfile.Name())
|
||||
content := []byte(`{
|
||||
"storage": {
|
||||
"rootDirectory": "%/tmp/zot"
|
||||
},
|
||||
"http": {
|
||||
"address": "127.0.0.1",
|
||||
"port": "8080"
|
||||
},
|
||||
"log": {
|
||||
"level": "debug"
|
||||
},
|
||||
"extensions": {
|
||||
"ui": {
|
||||
"enable": "true"
|
||||
}
|
||||
}
|
||||
}`)
|
||||
err = os.WriteFile(tmpfile.Name(), content, 0o0600)
|
||||
So(err, ShouldBeNil)
|
||||
err = cli.LoadConfiguration(config, tmpfile.Name())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Test missing extensions for UI to work", t, func(c C) {
|
||||
config := config.New()
|
||||
tmpfile, err := os.CreateTemp("", "zot-test*.json")
|
||||
So(err, ShouldBeNil)
|
||||
defer os.Remove(tmpfile.Name())
|
||||
|
||||
content := []byte(`{
|
||||
"storage": {
|
||||
"rootDirectory": "%/tmp/zot"
|
||||
},
|
||||
"http": {
|
||||
"address": "127.0.0.1",
|
||||
"port": "8080"
|
||||
},
|
||||
"log": {
|
||||
"level": "debug"
|
||||
},
|
||||
"extensions": {
|
||||
"ui": {
|
||||
"enable": "true"
|
||||
},
|
||||
"mgmt": {
|
||||
"enable": "true"
|
||||
}
|
||||
}
|
||||
}`)
|
||||
err = os.WriteFile(tmpfile.Name(), content, 0o0600)
|
||||
So(err, ShouldBeNil)
|
||||
err = cli.LoadConfiguration(config, tmpfile.Name())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
|
||||
Convey("Test missing mgmt extension for UI to work", t, func(c C) {
|
||||
config := config.New()
|
||||
tmpfile, err := os.CreateTemp("", "zot-test*.json")
|
||||
So(err, ShouldBeNil)
|
||||
defer os.Remove(tmpfile.Name())
|
||||
|
||||
content := []byte(`{
|
||||
"storage": {
|
||||
"rootDirectory": "%/tmp/zot"
|
||||
},
|
||||
"http": {
|
||||
"address": "127.0.0.1",
|
||||
"port": "8080"
|
||||
},
|
||||
"log": {
|
||||
"level": "debug"
|
||||
},
|
||||
"extensions": {
|
||||
"ui": {
|
||||
"enable": "true"
|
||||
},
|
||||
"search": {
|
||||
"enable": "true"
|
||||
}
|
||||
}
|
||||
}`)
|
||||
err = os.WriteFile(tmpfile.Name(), content, 0o0600)
|
||||
So(err, ShouldBeNil)
|
||||
err = cli.LoadConfiguration(config, tmpfile.Name())
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestLoadConfig(t *testing.T) {
|
||||
Convey("Test viper load config", t, func(c C) {
|
||||
config := config.New()
|
||||
|
||||
Reference in New Issue
Block a user