mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
fix: tests refactoring (#1950)
Signed-off-by: Alexei Dodon <adodon@cisco.com>
This commit is contained in:
parent
a3d8202345
commit
d2fbd273ba
16 changed files with 624 additions and 504 deletions
|
@ -79,7 +79,9 @@ func TestAPIKeys(t *testing.T) {
|
|||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
mockOIDCServer, err := authutils.MockOIDCRun()
|
||||
|
@ -125,6 +127,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
conf.Extensions.UI.Enable = &defaultVal
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
dir := t.TempDir()
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
@ -145,7 +148,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
Convey("API key retrieved with basic auth", func() {
|
||||
resp, err := resty.R().
|
||||
SetBody(reqBody).
|
||||
SetBasicAuth("test", "test").
|
||||
SetBasicAuth(username, password).
|
||||
Post(baseURL + constants.APIKeyPath)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
|
@ -162,7 +165,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
So(email, ShouldNotBeEmpty)
|
||||
|
||||
resp, err = resty.R().
|
||||
SetBasicAuth("test", apiKeyResponse.APIKey).
|
||||
SetBasicAuth(username, apiKeyResponse.APIKey).
|
||||
Get(baseURL + "/v2/_catalog")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
|
@ -170,7 +173,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
|
||||
// get API key list with basic auth
|
||||
resp, err = resty.R().
|
||||
SetBasicAuth("test", "test").
|
||||
SetBasicAuth(username, password).
|
||||
Get(baseURL + constants.APIKeyPath)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
|
@ -189,7 +192,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
// add another one
|
||||
resp, err = resty.R().
|
||||
SetBody(reqBody).
|
||||
SetBasicAuth("test", "test").
|
||||
SetBasicAuth(username, password).
|
||||
Post(baseURL + constants.APIKeyPath)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
|
@ -199,7 +202,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
|
||||
resp, err = resty.R().
|
||||
SetBasicAuth("test", apiKeyResponse.APIKey).
|
||||
SetBasicAuth(username, apiKeyResponse.APIKey).
|
||||
Get(baseURL + "/v2/_catalog")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
|
@ -207,7 +210,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
|
||||
// get API key list with api key auth
|
||||
resp, err = resty.R().
|
||||
SetBasicAuth("test", apiKeyResponse.APIKey).
|
||||
SetBasicAuth(username, apiKeyResponse.APIKey).
|
||||
Get(baseURL + constants.APIKeyPath)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
|
@ -600,7 +603,7 @@ func TestAPIKeys(t *testing.T) {
|
|||
So(len(apiKeyListResponse.APIKeys), ShouldEqual, 0)
|
||||
|
||||
resp, err = client.R().
|
||||
SetBasicAuth("test", "test").
|
||||
SetBasicAuth(username, password).
|
||||
SetQueryParam("id", apiKeyResponse.UUID).
|
||||
Delete(baseURL + constants.APIKeyPath)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -832,7 +835,9 @@ func TestAPIKeys(t *testing.T) {
|
|||
func TestAPIKeysOpenDBError(t *testing.T) {
|
||||
Convey("Test API keys - unable to create database", t, func() {
|
||||
conf := config.New()
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
mockOIDCServer, err := authutils.MockOIDCRun()
|
||||
|
@ -871,6 +876,7 @@ func TestAPIKeysOpenDBError(t *testing.T) {
|
|||
}
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
dir := t.TempDir()
|
||||
|
||||
err = os.Chmod(dir, 0o000)
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -44,8 +44,11 @@ func TestRoutes(t *testing.T) {
|
|||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
mockOIDCServer, err := mockoidc.Run()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
@ -79,6 +82,7 @@ func TestRoutes(t *testing.T) {
|
|||
}
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
ctlr.Config.Storage.Commit = true
|
||||
|
|
|
@ -25,18 +25,13 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
BaseURL1 = "http://127.0.0.1:8088"
|
||||
BaseSecureURL1 = "https://127.0.0.1:8088"
|
||||
HOST1 = "127.0.0.1:8088"
|
||||
SecurePort1 = "8088"
|
||||
BaseURL2 = "http://127.0.0.1:8089"
|
||||
BaseSecureURL2 = "https://127.0.0.1:8089"
|
||||
SecurePort2 = "8089"
|
||||
BaseURL3 = "http://127.0.0.1:8090"
|
||||
BaseSecureURL3 = "https://127.0.0.1:8090"
|
||||
SecurePort3 = "8090"
|
||||
username = "test"
|
||||
passphrase = "test"
|
||||
ServerCert = "../../../test/data/server.cert"
|
||||
ServerKey = "../../../test/data/server.key"
|
||||
CACert = "../../../test/data/ca.crt"
|
||||
|
@ -55,7 +50,9 @@ func TestTLSWithAuth(t *testing.T) {
|
|||
defer func() { resty.SetTLSClientConfig(nil) }()
|
||||
conf := config.New()
|
||||
conf.HTTP.Port = SecurePort1
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
conf.HTTP.Auth = &config.AuthConfig{
|
||||
|
@ -76,6 +73,7 @@ func TestTLSWithAuth(t *testing.T) {
|
|||
}
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(conf.HTTP.Port)
|
||||
|
@ -116,7 +114,7 @@ func TestTLSWithAuth(t *testing.T) {
|
|||
So(err, ShouldNotBeNil)
|
||||
So(imageBuff.String(), ShouldContainSubstring, "check credentials")
|
||||
|
||||
user := fmt.Sprintf("%s:%s", username, passphrase)
|
||||
user := fmt.Sprintf("%s:%s", username, password)
|
||||
args = []string{"-u", user, "--config", "imagetest"}
|
||||
configPath = makeConfigFile(
|
||||
fmt.Sprintf(`{"configs":[{"_name":"imagetest","url":"%s%s%s","showspinner":false}]}`,
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"time"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
cli "zotregistry.io/zot/pkg/cli/server"
|
||||
test "zotregistry.io/zot/pkg/test/common"
|
||||
|
@ -32,14 +31,7 @@ func TestConfigReloader(t *testing.T) {
|
|||
username := "alice"
|
||||
password := "alice"
|
||||
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), 10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
usernameAndHash := fmt.Sprintf("%s:%s", username, string(hash))
|
||||
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(usernameAndHash)
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
defer os.Remove(logFile.Name()) // clean up
|
||||
|
|
|
@ -22,14 +22,14 @@ func TestProfilingAuthz(t *testing.T) {
|
|||
Convey("Make a new controller", t, func() {
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
adminUsername := "admin"
|
||||
adminPassword := "admin"
|
||||
username := "test"
|
||||
password := "test"
|
||||
authorizationAllRepos := "**"
|
||||
adminUsername, seedAdminUser := test.GenerateRandomString()
|
||||
adminPassword, seedAdminPass := test.GenerateRandomString()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
authorizationAllRepos := test.AuthorizationAllRepos
|
||||
|
||||
testCreds := test.GetCredString(adminUsername, adminPassword) +
|
||||
"\n" + test.GetCredString(username, password)
|
||||
test.GetCredString(username, password)
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(testCreds)
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
|
@ -98,6 +98,9 @@ func TestProfilingAuthz(t *testing.T) {
|
|||
}
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedAdminUser", seedAdminUser).Int64("seedAdminPass", seedAdminPass).
|
||||
Msg("random seed for admin username & password")
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
|
|
@ -140,7 +140,9 @@ func TestMgmtExtension(t *testing.T) {
|
|||
mockOIDCConfig := mockOIDCServer.Config()
|
||||
|
||||
Convey("Verify mgmt auth info route enabled with htpasswd", t, func() {
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
conf.HTTP.Auth.HTPasswd.Path = htpasswdPath
|
||||
|
||||
conf.Extensions = &extconf.ExtensionConfig{}
|
||||
|
@ -154,6 +156,7 @@ func TestMgmtExtension(t *testing.T) {
|
|||
defer os.Remove(logFile.Name()) // cleanup
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
|
||||
subPaths := make(map[string]config.StorageConfig)
|
||||
subPaths["/a"] = config.StorageConfig{RootDirectory: t.TempDir()}
|
||||
|
@ -202,7 +205,7 @@ func TestMgmtExtension(t *testing.T) {
|
|||
So(mgmtResp.HTTP.Auth.LDAP, ShouldBeNil)
|
||||
|
||||
// with credentials
|
||||
resp, err = resty.R().SetBasicAuth("test", "test").Get(baseURL + constants.FullMgmt)
|
||||
resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
|
@ -215,12 +218,13 @@ func TestMgmtExtension(t *testing.T) {
|
|||
So(mgmtResp.HTTP.Auth.LDAP, ShouldBeNil)
|
||||
|
||||
// with wrong credentials
|
||||
resp, err = resty.R().SetBasicAuth("test", "wrong").Get(baseURL + constants.FullMgmt)
|
||||
resp, err = resty.R().SetBasicAuth(username, "wrong").Get(baseURL + constants.FullMgmt)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusUnauthorized)
|
||||
})
|
||||
|
||||
Convey("Verify mgmt auth info route enabled with ldap", t, func() {
|
||||
defer os.Remove(conf.HTTP.Auth.HTPasswd.Path) // cleanup of a file created in previous Convey
|
||||
conf.HTTP.Auth.LDAP = &config.LDAPConfig{
|
||||
BindDN: "binddn",
|
||||
BaseDN: "basedn",
|
||||
|
@ -281,7 +285,10 @@ func TestMgmtExtension(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Verify mgmt auth info route enabled with htpasswd + ldap", t, func() {
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
conf.HTTP.Auth.HTPasswd.Path = htpasswdPath
|
||||
conf.HTTP.Auth.LDAP = &config.LDAPConfig{
|
||||
BindDN: "binddn",
|
||||
|
@ -300,6 +307,7 @@ func TestMgmtExtension(t *testing.T) {
|
|||
defer os.Remove(logFile.Name()) // cleanup
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
|
||||
subPaths := make(map[string]config.StorageConfig)
|
||||
subPaths["/a"] = config.StorageConfig{RootDirectory: t.TempDir()}
|
||||
|
@ -342,7 +350,7 @@ func TestMgmtExtension(t *testing.T) {
|
|||
So(mgmtResp.HTTP.Auth.Bearer, ShouldBeNil)
|
||||
|
||||
// with credentials
|
||||
resp, err = resty.R().SetBasicAuth("test", "test").Get(baseURL + constants.FullMgmt)
|
||||
resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
|
@ -356,7 +364,10 @@ func TestMgmtExtension(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Verify mgmt auth info route enabled with htpasswd + ldap + bearer", t, func() {
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
conf.HTTP.Auth.HTPasswd.Path = htpasswdPath
|
||||
conf.HTTP.Auth.LDAP = &config.LDAPConfig{
|
||||
BindDN: "binddn",
|
||||
|
@ -380,6 +391,7 @@ func TestMgmtExtension(t *testing.T) {
|
|||
defer os.Remove(logFile.Name()) // cleanup
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
|
||||
|
@ -420,7 +432,7 @@ func TestMgmtExtension(t *testing.T) {
|
|||
So(mgmtResp.HTTP.Auth.Bearer.Service, ShouldEqual, "service")
|
||||
|
||||
// with credentials
|
||||
resp, err = resty.R().SetBasicAuth("test", "test").Get(baseURL + constants.FullMgmt)
|
||||
resp, err = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullMgmt)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
|
@ -629,7 +641,10 @@ func TestMgmtExtension(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Verify mgmt auth info route enabled with empty openID provider list", t, func() {
|
||||
htpasswdPath := test.MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
conf.HTTP.Auth.HTPasswd.Path = htpasswdPath
|
||||
conf.HTTP.Auth.LDAP = nil
|
||||
|
@ -652,6 +667,7 @@ func TestMgmtExtension(t *testing.T) {
|
|||
defer os.Remove(logFile.Name()) // cleanup
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
|
||||
ctlr.Config.Storage.RootDirectory = t.TempDir()
|
||||
|
||||
|
|
|
@ -28,19 +28,6 @@ import (
|
|||
ociutils "zotregistry.io/zot/pkg/test/oci-utils"
|
||||
)
|
||||
|
||||
const (
|
||||
username = "test"
|
||||
passphrase = "test"
|
||||
ServerCert = "../../test/data/server.cert"
|
||||
ServerKey = "../../test/data/server.key"
|
||||
CACert = "../../test/data/ca.crt"
|
||||
AuthorizedNamespace = "everyone/isallowed"
|
||||
UnauthorizedNamespace = "fortknox/notallowed"
|
||||
ALICE = "alice"
|
||||
AuthorizationNamespace = "authz/image"
|
||||
AuthorizationAllRepos = "**"
|
||||
)
|
||||
|
||||
func TestVerifyMandatoryAnnotations(t *testing.T) {
|
||||
//nolint: dupl
|
||||
Convey("Mandatory annotations disabled", t, func() {
|
||||
|
@ -67,8 +54,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -114,8 +100,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -161,8 +146,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -214,8 +198,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -232,8 +215,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
|
||||
configDigest := manifest.Config.Digest
|
||||
|
||||
resp, err = resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest))
|
||||
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest))
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -302,8 +284,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -319,8 +300,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
|
||||
configDigest := manifest.Config.Digest
|
||||
|
||||
resp, err = resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest))
|
||||
resp, err = resty.R().Get(baseURL + fmt.Sprintf("/v2/zot-test/blobs/%s", configDigest))
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -389,8 +369,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -445,8 +424,7 @@ func TestVerifyMandatoryAnnotations(t *testing.T) {
|
|||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).
|
||||
Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
resp, err := resty.R().Get(baseURL + "/v2/zot-test/manifests/0.0.1")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
|
|
@ -38,18 +38,13 @@ import (
|
|||
mTypes "zotregistry.io/zot/pkg/meta/types"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
. "zotregistry.io/zot/pkg/test/common"
|
||||
test "zotregistry.io/zot/pkg/test/common"
|
||||
"zotregistry.io/zot/pkg/test/deprecated"
|
||||
. "zotregistry.io/zot/pkg/test/image-utils"
|
||||
"zotregistry.io/zot/pkg/test/mocks"
|
||||
ociutils "zotregistry.io/zot/pkg/test/oci-utils"
|
||||
)
|
||||
|
||||
const (
|
||||
username = "test"
|
||||
passphrase = "test"
|
||||
)
|
||||
|
||||
type CveResult struct {
|
||||
ImgList ImgList `json:"data"`
|
||||
Errors []ErrorGQL `json:"errors"`
|
||||
|
@ -418,11 +413,13 @@ func TestImageFormat(t *testing.T) {
|
|||
|
||||
func TestCVESearchDisabled(t *testing.T) {
|
||||
Convey("Test with CVE search disabled", t, func() {
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
htpasswdPath := MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
conf.HTTP.Auth = &config.AuthConfig{
|
||||
|
@ -453,27 +450,28 @@ func TestCVESearchDisabled(t *testing.T) {
|
|||
writers := io.MultiWriter(os.Stdout, logFile)
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
||||
ctrlManager := NewControllerManager(ctlr)
|
||||
ctrlManager := test.NewControllerManager(ctlr)
|
||||
|
||||
ctrlManager.StartAndWait(port)
|
||||
|
||||
// Wait for trivy db to download
|
||||
found, err := ReadLogFileAndSearchString(logPath, "CVE config not provided, skipping CVE update", 90*time.Second)
|
||||
found, err := test.ReadLogFileAndSearchString(logPath, "CVE config not provided, skipping CVE update", 90*time.Second)
|
||||
So(err, ShouldBeNil)
|
||||
So(found, ShouldBeTrue)
|
||||
|
||||
defer ctrlManager.StopServer()
|
||||
|
||||
resp, _ := resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ := resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(string(resp.Body()), ShouldContainSubstring, "search: CVE search is disabled")
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}")
|
||||
So(string(resp.Body()), ShouldContainSubstring, "search: CVE search is disabled")
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + "randomId" + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + "randomId" + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(string(resp.Body()), ShouldContainSubstring, "search: CVE search is disabled")
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
@ -483,11 +481,13 @@ func TestCVESearchDisabled(t *testing.T) {
|
|||
func TestCVESearch(t *testing.T) {
|
||||
Convey("Test image vulnerability scanning", t, func() {
|
||||
updateDuration, _ := time.ParseDuration("1h")
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
htpasswdPath := MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
dbDir, err := testSetup(t)
|
||||
|
@ -529,14 +529,15 @@ func TestCVESearch(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
||||
ctrlManager := NewControllerManager(ctlr)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
ctrlManager := test.NewControllerManager(ctlr)
|
||||
|
||||
ctrlManager.StartAndWait(port)
|
||||
|
||||
// trivy db download fail
|
||||
err = os.Mkdir(dbDir+"/_trivy", 0o000)
|
||||
So(err, ShouldBeNil)
|
||||
found, err := ReadLogFileAndSearchString(logPath, "Error downloading Trivy DB to destination dir", 180*time.Second)
|
||||
found, err := test.ReadLogFileAndSearchString(logPath, "Error downloading Trivy DB to destination dir", 180*time.Second)
|
||||
So(err, ShouldBeNil)
|
||||
So(found, ShouldBeTrue)
|
||||
|
||||
|
@ -544,7 +545,7 @@ func TestCVESearch(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
|
||||
// Wait for trivy db to download
|
||||
found, err = ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 180*time.Second)
|
||||
found, err = test.ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 180*time.Second)
|
||||
So(err, ShouldBeNil)
|
||||
So(found, ShouldBeTrue)
|
||||
|
||||
|
@ -567,21 +568,21 @@ func TestCVESearch(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
|
||||
// with creds, should get expected status code
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL)
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 404)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/v2/")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix)
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
var cveResult CveResult
|
||||
contains := false
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
err = json.Unmarshal(resp.Body(), &cveResult)
|
||||
So(err, ShouldBeNil)
|
||||
for _, err := range cveResult.Errors {
|
||||
|
@ -592,7 +593,7 @@ func TestCVESearch(t *testing.T) {
|
|||
}
|
||||
So(contains, ShouldBeTrue)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
|
@ -602,7 +603,7 @@ func TestCVESearch(t *testing.T) {
|
|||
|
||||
cveid := cveResult.ImgList.CVEResultForImage.CVEList[0].ID
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
|
@ -611,7 +612,7 @@ func TestCVESearch(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
So(len(imgListWithCVEFixed.Images), ShouldEqual, 0)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-cve-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-cve-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
|
@ -619,11 +620,11 @@ func TestCVESearch(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
So(len(imgListWithCVEFixed.Images), ShouldEqual, 0)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"b/zot-squashfs-test:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"b/zot-squashfs-test:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
|
@ -632,108 +633,108 @@ func TestCVESearch(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
So(len(cveSquashFSResult.ImgList.CVEResultForImage.CVEList), ShouldBeZeroValue)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noindex:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noindex:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noindex\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noindex\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-index:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-index:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-index\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-index\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noblobs:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-noblobs:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noblob\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-noblob\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-test\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-blob:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-invalid-blob:commit-aaa7c6e7-squashfs\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-blob\"){Results{RepoName%20LastUpdated}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListWithCVEFixed(id:\"" + cveid + "\",image:\"zot-squashfs-invalid-blob\"){Results{RepoName%20LastUpdated}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-squashfs-test\"){Tag%20CVEList{Id%20Description%20Severity%20PackageList{Name%20InstalledVersion%20FixedVersion}}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"cntos\"){Tag%20CVEList{Id%20Description%20Severity}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"cntos\"){Tag%20CVEList{Id%20Description%20Severity}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-201-20482\"){Results{RepoName%20Tag}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test\"){Tag%20CVEList{Id%20Description}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Tag}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description%20Severity}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description%20Severity}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description%20Severity}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description%20Severity}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Severity}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Severity}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id%20Description}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Id}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){CVEList{Description}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
|
||||
// Testing Invalid Search URL
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Ta%20CVEList{Id%20Description%20Severity}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(image:\"zot-test:0.0.1\"){Ta%20CVEList{Id%20Description%20Severity}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(tet:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(tet:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageistForCVE(id:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageistForCVE(id:\"CVE-2018-20482\"){Results{RepoName%20Tag}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-2018-20482\"){ame%20Tags}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"CVE-2018-20482\"){ame%20Tags}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(reo:\"zot-test:1.0.0\"){Tag%20CVEList{Id%20Description%20Severity}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={CVEListForImage(reo:\"zot-test:1.0.0\"){Tag%20CVEList{Id%20Description%20Severity}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 422)
|
||||
|
||||
resp, _ = resty.R().SetBasicAuth(username, passphrase).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"" + cveid + "\"){Results{RepoName%20Tag}}}")
|
||||
resp, _ = resty.R().SetBasicAuth(username, password).Get(baseURL + constants.FullSearchPrefix + "?query={ImageListForCVE(id:\"" + cveid + "\"){Results{RepoName%20Tag}}}")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, 200)
|
||||
})
|
||||
|
@ -1615,8 +1616,8 @@ func TestFixedTags(t *testing.T) {
|
|||
func TestFixedTagsWithIndex(t *testing.T) {
|
||||
Convey("Test fixed tags", t, func() {
|
||||
tempDir := t.TempDir()
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
defaultVal := true
|
||||
|
@ -1644,7 +1645,7 @@ func TestFixedTagsWithIndex(t *testing.T) {
|
|||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Logger = ctlr.Log.Output(writers)
|
||||
|
||||
cm := NewControllerManager(ctlr)
|
||||
cm := test.NewControllerManager(ctlr)
|
||||
cm.StartAndWait(port)
|
||||
defer cm.StopServer()
|
||||
// push index with 2 manifests: one with vulns and one without
|
||||
|
@ -1681,7 +1682,7 @@ func TestFixedTagsWithIndex(t *testing.T) {
|
|||
So(err, ShouldBeNil)
|
||||
|
||||
// Wait for trivy db to download
|
||||
found, err := ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 180*time.Second)
|
||||
found, err := test.ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 180*time.Second)
|
||||
So(err, ShouldBeNil)
|
||||
So(found, ShouldBeTrue)
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import (
|
|||
"testing"
|
||||
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"gopkg.in/resty.v1"
|
||||
|
||||
"zotregistry.io/zot/pkg/api"
|
||||
|
@ -23,7 +22,7 @@ import (
|
|||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/storage/local"
|
||||
. "zotregistry.io/zot/pkg/test/common"
|
||||
test "zotregistry.io/zot/pkg/test/common"
|
||||
"zotregistry.io/zot/pkg/test/deprecated"
|
||||
. "zotregistry.io/zot/pkg/test/image-utils"
|
||||
)
|
||||
|
@ -31,8 +30,8 @@ import (
|
|||
//nolint:dupl
|
||||
func TestUserData(t *testing.T) {
|
||||
Convey("Test user stars and bookmarks", t, func(c C) {
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
defaultVal := true
|
||||
|
||||
accessibleRepo := "accessible-repo"
|
||||
|
@ -44,10 +43,9 @@ func TestUserData(t *testing.T) {
|
|||
simpleUser := "test"
|
||||
simpleUserPassword := "test123"
|
||||
|
||||
twoCredTests := fmt.Sprintf("%s\n%s\n\n", getCredString(adminUser, adminPassword),
|
||||
getCredString(simpleUser, simpleUserPassword))
|
||||
|
||||
htpasswdPath := MakeHtpasswdFileFromString(twoCredTests)
|
||||
content := test.GetCredString(adminUser, adminPassword) +
|
||||
test.GetCredString(simpleUser, simpleUserPassword)
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(content)
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
conf := config.New()
|
||||
|
@ -94,7 +92,7 @@ func TestUserData(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
ctlrManager := NewControllerManager(ctlr)
|
||||
ctlrManager := test.NewControllerManager(ctlr)
|
||||
ctlrManager.StartAndWait(port)
|
||||
defer ctlrManager.StopServer()
|
||||
|
||||
|
@ -458,8 +456,8 @@ func TestUserData(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestChangingRepoState(t *testing.T) {
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
defaultVal := true
|
||||
|
||||
simpleUser := "test"
|
||||
|
@ -468,9 +466,7 @@ func TestChangingRepoState(t *testing.T) {
|
|||
forbiddenRepo := "forbidden"
|
||||
accesibleRepo := "accesible"
|
||||
|
||||
credTests := fmt.Sprintf("%s\n\n", getCredString(simpleUser, simpleUserPassword))
|
||||
|
||||
htpasswdPath := MakeHtpasswdFileFromString(credTests)
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(simpleUser, simpleUserPassword))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
conf := config.New()
|
||||
|
@ -562,7 +558,7 @@ func TestChangingRepoState(t *testing.T) {
|
|||
t.FailNow()
|
||||
}
|
||||
|
||||
ctlrManager := NewControllerManager(ctlr)
|
||||
ctlrManager := test.NewControllerManager(ctlr)
|
||||
|
||||
ctlrManager.StartAndWait(port)
|
||||
|
||||
|
@ -622,17 +618,15 @@ func TestChangingRepoState(t *testing.T) {
|
|||
func TestGlobalSearchWithUserPrefFiltering(t *testing.T) {
|
||||
Convey("Bookmarks and Stars filtering", t, func() {
|
||||
dir := t.TempDir()
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
conf.Storage.RootDirectory = dir
|
||||
|
||||
simpleUser := "simpleUser"
|
||||
simpleUserPassword := "simpleUserPass"
|
||||
credTests := fmt.Sprintf("%s\n\n", getCredString(simpleUser, simpleUserPassword))
|
||||
|
||||
htpasswdPath := MakeHtpasswdFileFromString(credTests)
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(simpleUser, simpleUserPassword))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
conf.HTTP.Auth = &config.AuthConfig{
|
||||
|
@ -664,7 +658,7 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
ctlrManager := NewControllerManager(ctlr)
|
||||
ctlrManager := test.NewControllerManager(ctlr)
|
||||
ctlrManager.StartAndWait(port)
|
||||
defer ctlrManager.StopServer()
|
||||
|
||||
|
@ -750,8 +744,8 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) {
|
|||
So(foundRepos, ShouldContain, common.RepoSummary{Name: sbRepo, IsStarred: true, IsBookmarked: true})
|
||||
|
||||
// Filter by IsStarred = true && IsBookmarked = false
|
||||
query = `{
|
||||
GlobalSearch(query:"repo", filter:{ IsStarred:true, IsBookmarked:false }) {
|
||||
query = `{
|
||||
GlobalSearch(query:"repo", filter:{ IsStarred:true, IsBookmarked:false }) {
|
||||
Repos { Name IsStarred IsBookmarked }
|
||||
}
|
||||
}`
|
||||
|
@ -771,8 +765,8 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) {
|
|||
So(foundRepos, ShouldContain, common.RepoSummary{Name: sRepo, IsStarred: true, IsBookmarked: false})
|
||||
|
||||
// Filter by IsBookmarked = true
|
||||
query = `{
|
||||
GlobalSearch(query:"repo", filter:{ IsBookmarked:true }) {
|
||||
query = `{
|
||||
GlobalSearch(query:"repo", filter:{ IsBookmarked:true }) {
|
||||
Repos { Name IsStarred IsBookmarked }
|
||||
}
|
||||
}`
|
||||
|
@ -793,8 +787,8 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) {
|
|||
So(foundRepos, ShouldContain, common.RepoSummary{Name: sbRepo, IsStarred: true, IsBookmarked: true})
|
||||
|
||||
// Filter by IsBookmarked = true && IsStarred = false
|
||||
query = `{
|
||||
GlobalSearch(query:"repo", filter:{ IsBookmarked:true, IsStarred:false }) {
|
||||
query = `{
|
||||
GlobalSearch(query:"repo", filter:{ IsBookmarked:true, IsStarred:false }) {
|
||||
Repos { Name IsStarred IsBookmarked }
|
||||
}
|
||||
}`
|
||||
|
@ -818,17 +812,15 @@ func TestGlobalSearchWithUserPrefFiltering(t *testing.T) {
|
|||
func TestExpandedRepoInfoWithUserPrefs(t *testing.T) {
|
||||
Convey("ExpandedRepoInfo with User Prefs", t, func() {
|
||||
dir := t.TempDir()
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
conf := config.New()
|
||||
conf.HTTP.Port = port
|
||||
conf.Storage.RootDirectory = dir
|
||||
|
||||
simpleUser := "simpleUser"
|
||||
simpleUserPassword := "simpleUserPass"
|
||||
credTests := fmt.Sprintf("%s\n\n", getCredString(simpleUser, simpleUserPassword))
|
||||
|
||||
htpasswdPath := MakeHtpasswdFileFromString(credTests)
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(simpleUser, simpleUserPassword))
|
||||
defer os.Remove(htpasswdPath)
|
||||
|
||||
conf.HTTP.Auth = &config.AuthConfig{
|
||||
|
@ -860,7 +852,7 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) {
|
|||
|
||||
ctlr := api.NewController(conf)
|
||||
|
||||
ctlrManager := NewControllerManager(ctlr)
|
||||
ctlrManager := test.NewControllerManager(ctlr)
|
||||
ctlrManager.StartAndWait(port)
|
||||
defer ctlrManager.StopServer()
|
||||
|
||||
|
@ -888,7 +880,7 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) {
|
|||
{
|
||||
ExpandedRepoInfo(repo:"sbrepo"){
|
||||
Summary {
|
||||
Name IsStarred IsBookmarked
|
||||
Name IsStarred IsBookmarked
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
@ -923,7 +915,7 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) {
|
|||
{
|
||||
ExpandedRepoInfo(repo:"srepo"){
|
||||
Summary {
|
||||
Name IsStarred IsBookmarked
|
||||
Name IsStarred IsBookmarked
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
@ -958,7 +950,7 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) {
|
|||
{
|
||||
ExpandedRepoInfo(repo:"brepo"){
|
||||
Summary {
|
||||
Name IsStarred IsBookmarked
|
||||
Name IsStarred IsBookmarked
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
@ -989,7 +981,7 @@ func TestExpandedRepoInfoWithUserPrefs(t *testing.T) {
|
|||
{
|
||||
ExpandedRepoInfo(repo:"repo"){
|
||||
Summary {
|
||||
Name IsStarred IsBookmarked
|
||||
Name IsStarred IsBookmarked
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
@ -1017,14 +1009,3 @@ func PutRepoStarURL(repo string) string {
|
|||
func PutRepoBookmarkURL(repo string) string {
|
||||
return fmt.Sprintf("?repo=%s&action=toggleBookmark", repo)
|
||||
}
|
||||
|
||||
func getCredString(username, password string) string {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), 10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
usernameAndHash := fmt.Sprintf("%s:%s", username, string(hash))
|
||||
|
||||
return usernameAndHash
|
||||
}
|
||||
|
|
|
@ -69,6 +69,8 @@ const (
|
|||
)
|
||||
|
||||
var (
|
||||
username = "test" //nolint: gochecknoglobals
|
||||
password = "test" //nolint: gochecknoglobals
|
||||
errSync = errors.New("sync error, src oci repo differs from dest one")
|
||||
errBadStatus = errors.New("bad http status")
|
||||
)
|
||||
|
@ -127,7 +129,7 @@ func makeUpstreamServer(
|
|||
|
||||
var htpasswdPath string
|
||||
if basicAuth {
|
||||
htpasswdPath = test.MakeHtpasswdFile()
|
||||
htpasswdPath = test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
srcConfig.HTTP.Auth = &config.AuthConfig{
|
||||
HTPasswd: config.AuthHTPasswd{
|
||||
Path: htpasswdPath,
|
||||
|
@ -2376,7 +2378,8 @@ func TestBasicAuth(t *testing.T) {
|
|||
defer scm.StopServer()
|
||||
|
||||
registryName := sync.StripRegistryTransport(srcBaseURL)
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "test"}}`, registryName))
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "%s", "password": "%s"}}`,
|
||||
registryName, username, password))
|
||||
|
||||
var tlsVerify bool
|
||||
|
||||
|
@ -2408,7 +2411,7 @@ func TestBasicAuth(t *testing.T) {
|
|||
var srcTagsList TagsList
|
||||
var destTagsList TagsList
|
||||
|
||||
resp, _ := srcClient.R().SetBasicAuth("test", "test").Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
||||
resp, _ := srcClient.R().SetBasicAuth(username, password).Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
|
@ -2474,8 +2477,8 @@ func TestBasicAuth(t *testing.T) {
|
|||
|
||||
registryName := sync.StripRegistryTransport(srcBaseURL)
|
||||
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "invalid"}}`,
|
||||
registryName))
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "%s", "password": "invalid"}}`,
|
||||
registryName, username))
|
||||
|
||||
var tlsVerify bool
|
||||
|
||||
|
@ -2541,8 +2544,8 @@ func TestBasicAuth(t *testing.T) {
|
|||
|
||||
registryName := sync.StripRegistryTransport(srcBaseURL)
|
||||
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "test"}}`,
|
||||
registryName))
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "%s", "password": "%s"}}`,
|
||||
registryName, username, password))
|
||||
|
||||
err := os.Chmod(credentialsFile, 0o000)
|
||||
So(err, ShouldBeNil)
|
||||
|
@ -2614,7 +2617,8 @@ func TestBasicAuth(t *testing.T) {
|
|||
defer scm.StopServer()
|
||||
|
||||
registryName := sync.StripRegistryTransport(srcBaseURL)
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "test"}}`, registryName))
|
||||
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "%s", "password": "%s"}}`,
|
||||
registryName, username, password))
|
||||
|
||||
defaultValue := false
|
||||
syncRegistryConfig := syncconf.RegistryConfig{
|
||||
|
@ -2654,7 +2658,7 @@ func TestBasicAuth(t *testing.T) {
|
|||
var srcTagsList TagsList
|
||||
var destTagsList TagsList
|
||||
|
||||
resp, _ := srcClient.R().SetBasicAuth("test", "test").Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
||||
resp, _ := srcClient.R().SetBasicAuth(username, password).Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
||||
|
|
|
@ -24,14 +24,7 @@ import (
|
|||
"zotregistry.io/zot/pkg/api/config"
|
||||
"zotregistry.io/zot/pkg/api/constants"
|
||||
"zotregistry.io/zot/pkg/log"
|
||||
. "zotregistry.io/zot/pkg/test/common"
|
||||
)
|
||||
|
||||
const (
|
||||
username = "test"
|
||||
passphrase = "test"
|
||||
AuthorizedNamespace = "everyone/isallowed"
|
||||
UnauthorizedNamespace = "fortknox/notallowed"
|
||||
test "zotregistry.io/zot/pkg/test/common"
|
||||
)
|
||||
|
||||
type AuditLog struct {
|
||||
|
@ -49,8 +42,8 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
Convey("Make a new controller", t, func() {
|
||||
dir := t.TempDir()
|
||||
|
||||
port := GetFreePort()
|
||||
baseURL := GetBaseURL(port)
|
||||
port := test.GetFreePort()
|
||||
baseURL := test.GetBaseURL(port)
|
||||
conf := config.New()
|
||||
|
||||
outputPath := dir + "/zot.log"
|
||||
|
@ -59,7 +52,9 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
|
||||
conf.HTTP.Port = port
|
||||
|
||||
htpasswdPath := MakeHtpasswdFile()
|
||||
username, seedUser := test.GenerateRandomString()
|
||||
password, seedPass := test.GenerateRandomString()
|
||||
htpasswdPath := test.MakeHtpasswdFileFromString(test.GetCredString(username, password))
|
||||
defer os.Remove(htpasswdPath)
|
||||
conf.HTTP.Auth = &config.AuthConfig{
|
||||
HTPasswd: config.AuthHTPasswd{
|
||||
|
@ -68,9 +63,10 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
}
|
||||
|
||||
ctlr := api.NewController(conf)
|
||||
ctlr.Log.Info().Int64("seedUser", seedUser).Int64("seedPass", seedPass).Msg("random seed for username & password")
|
||||
ctlr.Config.Storage.RootDirectory = dir
|
||||
|
||||
ctlrManager := NewControllerManager(ctlr)
|
||||
ctlrManager := test.NewControllerManager(ctlr)
|
||||
ctlrManager.StartAndWait(port)
|
||||
defer ctlrManager.StopServer()
|
||||
|
||||
|
@ -83,7 +79,7 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
defer auditFile.Close()
|
||||
|
||||
Convey("Test GET request", func() {
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).Get(baseURL + "/v2/")
|
||||
resp, err := resty.R().SetBasicAuth(username, password).Get(baseURL + "/v2/")
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusOK)
|
||||
|
@ -93,8 +89,9 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
})
|
||||
|
||||
Convey("Test POST request", func() {
|
||||
path := "/v2/" + AuthorizedNamespace + "/blobs/uploads/"
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).Post(baseURL + path)
|
||||
repoName := "everyone/isallowed"
|
||||
path := "/v2/" + repoName + "/blobs/uploads/"
|
||||
resp, err := resty.R().SetBasicAuth(username, password).Post(baseURL + path)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp, ShouldNotBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusAccepted)
|
||||
|
@ -124,10 +121,10 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
Convey("Test PUT and DELETE request", func() {
|
||||
// create upload
|
||||
path := "/v2/repo/blobs/uploads/"
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).Post(baseURL + path)
|
||||
resp, err := resty.R().SetBasicAuth(username, password).Post(baseURL + path)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusAccepted)
|
||||
loc := Location(baseURL, resp)
|
||||
loc := test.Location(baseURL, resp)
|
||||
So(loc, ShouldNotBeEmpty)
|
||||
location := resp.Header().Get("Location")
|
||||
So(location, ShouldNotBeEmpty)
|
||||
|
@ -159,11 +156,11 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
|
||||
// blob upload
|
||||
resp, err = resty.R().SetQueryParam("digest", digest.String()).
|
||||
SetBasicAuth(username, passphrase).
|
||||
SetBasicAuth(username, password).
|
||||
SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusCreated)
|
||||
blobLoc := Location(baseURL, resp)
|
||||
blobLoc := test.Location(baseURL, resp)
|
||||
So(blobLoc, ShouldNotBeEmpty)
|
||||
So(resp.Header().Get(constants.DistContentDigestKey), ShouldNotBeEmpty)
|
||||
|
||||
|
@ -190,7 +187,7 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
So(auditLog.Object, ShouldEqual, putPath)
|
||||
|
||||
// delete this blob
|
||||
resp, err = resty.R().SetBasicAuth(username, passphrase).Delete(blobLoc)
|
||||
resp, err = resty.R().SetBasicAuth(username, password).Delete(blobLoc)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusAccepted)
|
||||
So(resp.Header().Get("Content-Length"), ShouldEqual, "0")
|
||||
|
@ -220,10 +217,10 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
|
||||
Convey("Test PATCH request", func() {
|
||||
path := "/v2/repo/blobs/uploads/"
|
||||
resp, err := resty.R().SetBasicAuth(username, passphrase).Post(baseURL + path)
|
||||
resp, err := resty.R().SetBasicAuth(username, password).Post(baseURL + path)
|
||||
So(err, ShouldBeNil)
|
||||
So(resp.StatusCode(), ShouldEqual, http.StatusAccepted)
|
||||
loc := Location(baseURL, resp)
|
||||
loc := test.Location(baseURL, resp)
|
||||
So(loc, ShouldNotBeEmpty)
|
||||
location := resp.Header().Get("Location")
|
||||
So(location, ShouldNotBeEmpty)
|
||||
|
@ -257,7 +254,7 @@ func TestAuditLogMessages(t *testing.T) {
|
|||
|
||||
// write a chunk
|
||||
contentRange := fmt.Sprintf("%d-%d", 0, len(chunk)-1)
|
||||
resp, err = resty.R().SetBasicAuth(username, passphrase).
|
||||
resp, err = resty.R().SetBasicAuth(username, password).
|
||||
SetHeader("Content-Type", "application/octet-stream").
|
||||
SetHeader("Content-Range", contentRange).SetBody(chunk).Patch(loc)
|
||||
So(err, ShouldBeNil)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"zotregistry.io/zot/pkg/log"
|
||||
"zotregistry.io/zot/pkg/storage"
|
||||
"zotregistry.io/zot/pkg/storage/cache"
|
||||
test "zotregistry.io/zot/pkg/test/common"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -20,32 +21,20 @@ const (
|
|||
datasetSize int = 5000
|
||||
)
|
||||
|
||||
func generateRandomString() string {
|
||||
//nolint: gosec
|
||||
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
charset := "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
randomBytes := make([]byte, 10)
|
||||
for i := range randomBytes {
|
||||
randomBytes[i] = charset[seededRand.Intn(len(charset))]
|
||||
}
|
||||
|
||||
return string(randomBytes)
|
||||
}
|
||||
|
||||
func generateData() map[godigest.Digest]string {
|
||||
dataMap := make(map[godigest.Digest]string, datasetSize)
|
||||
//nolint: gosec
|
||||
seededRand := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
for i := 0; i < datasetSize; i++ {
|
||||
randomString := generateRandomString()
|
||||
randomString, _ := test.GenerateRandomString()
|
||||
counter := 0
|
||||
|
||||
for seededRand.Float32() < 0.5 && counter < 5 {
|
||||
counter++
|
||||
randomString += "/"
|
||||
randomString += generateRandomString()
|
||||
rs, _ := test.GenerateRandomString()
|
||||
randomString += rs
|
||||
}
|
||||
digest := godigest.FromString(randomString)
|
||||
dataMap[digest] = randomString
|
||||
|
@ -209,7 +198,8 @@ func BenchmarkMixLocal(b *testing.B) {
|
|||
|
||||
func BenchmarkPutLocalstack(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
|
||||
|
@ -234,7 +224,8 @@ func BenchmarkPutLocalstack(b *testing.B) {
|
|||
|
||||
func BenchmarkDeleteLocalstack(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
|
||||
|
@ -263,7 +254,8 @@ func BenchmarkDeleteLocalstack(b *testing.B) {
|
|||
|
||||
func BenchmarkHasLocalstack(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
|
||||
|
@ -292,7 +284,8 @@ func BenchmarkHasLocalstack(b *testing.B) {
|
|||
|
||||
func BenchmarkGetLocalstack(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
|
||||
|
@ -331,7 +324,8 @@ func BenchmarkGetLocalstack(b *testing.B) {
|
|||
|
||||
func BenchmarkMixLocalstack(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", localEndpoint, "create-table",
|
||||
|
@ -367,7 +361,8 @@ func BenchmarkMixLocalstack(b *testing.B) {
|
|||
|
||||
func BenchmarkPutAWS(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
|
||||
|
@ -392,7 +387,8 @@ func BenchmarkPutAWS(b *testing.B) {
|
|||
|
||||
func BenchmarkDeleteAWS(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
|
||||
|
@ -421,7 +417,8 @@ func BenchmarkDeleteAWS(b *testing.B) {
|
|||
|
||||
func BenchmarkHasAWS(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
|
||||
|
@ -450,7 +447,8 @@ func BenchmarkHasAWS(b *testing.B) {
|
|||
|
||||
func BenchmarkGetAWS(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
|
||||
|
@ -489,7 +487,8 @@ func BenchmarkGetAWS(b *testing.B) {
|
|||
|
||||
func BenchmarkMixAWS(b *testing.B) {
|
||||
log := log.NewLogger("error", "")
|
||||
tableName := generateRandomString()
|
||||
tableName, seed := test.GenerateRandomString()
|
||||
log.Info().Int64("seed", seed).Msg("random seed for tableName")
|
||||
|
||||
// Create Table
|
||||
_, err := exec.Command("aws", "dynamodb", "--region", region, "--endpoint-url", awsEndpoint, "create-table",
|
||||
|
|
|
@ -212,20 +212,13 @@ func ReadLogFileAndCountStringOccurence(logPath string, stringToMatch string,
|
|||
}
|
||||
}
|
||||
|
||||
func MakeHtpasswdFile() string {
|
||||
// bcrypt(username="test", passwd="test")
|
||||
content := "test:$2y$05$hlbSXDp6hzDLu6VwACS39ORvVRpr3OMR4RlJ31jtlaOEGnPjKZI1m\n"
|
||||
|
||||
return MakeHtpasswdFileFromString(content)
|
||||
}
|
||||
|
||||
func GetCredString(username, password string) string {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), 10)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
usernameAndHash := fmt.Sprintf("%s:%s", username, string(hash))
|
||||
usernameAndHash := fmt.Sprintf("%s:%s\n", username, string(hash))
|
||||
|
||||
return usernameAndHash
|
||||
}
|
||||
|
@ -236,7 +229,6 @@ func MakeHtpasswdFileFromString(fileContent string) string {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
// bcrypt(username="test", passwd="test")
|
||||
content := []byte(fileContent)
|
||||
if err := os.WriteFile(htpasswdFile.Name(), content, 0o600); err != nil { //nolint:gomnd
|
||||
panic(err)
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
|
||||
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
|
||||
tcommon "zotregistry.io/zot/pkg/test/common"
|
||||
)
|
||||
|
@ -215,5 +216,61 @@ func TestCopyTestKeysAndCerts(t *testing.T) {
|
|||
|
||||
err = tcommon.CopyTestKeysAndCerts(file)
|
||||
So(err, ShouldNotBeNil)
|
||||
|
||||
// ----- /test/data doesn't exist ------
|
||||
workDir, err := os.Getwd()
|
||||
So(err, ShouldBeNil)
|
||||
defer func() { _ = os.Chdir(workDir) }()
|
||||
|
||||
dir = t.TempDir()
|
||||
file = filepath.Join(dir, "go.mod")
|
||||
_, err = os.Create(file)
|
||||
So(err, ShouldBeNil)
|
||||
_, err = os.Stat(file)
|
||||
So(err, ShouldBeNil)
|
||||
err = os.Chdir(dir)
|
||||
So(err, ShouldBeNil)
|
||||
err = tcommon.CopyTestKeysAndCerts(dir)
|
||||
So(err, ShouldNotBeNil)
|
||||
So(err.Error(), ShouldContainSubstring, "CopyFiles os.Stat failed")
|
||||
|
||||
// --- GetProjectRootDir call fails -----
|
||||
err = os.Chdir(os.TempDir())
|
||||
So(err, ShouldBeNil)
|
||||
err = tcommon.CopyTestKeysAndCerts(os.TempDir())
|
||||
So(err, ShouldNotBeNil)
|
||||
So(err, ShouldEqual, tcommon.ErrNoGoModFileFound)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetProjectRootDir(t *testing.T) {
|
||||
Convey("GetProjectRootDir", t, func() {
|
||||
path, err := tcommon.GetProjectRootDir()
|
||||
So(err, ShouldBeNil)
|
||||
So(len(path), ShouldBeGreaterThan, 0)
|
||||
})
|
||||
Convey("GetProjectRootDir negative testing", t, func() {
|
||||
workDir, err := os.Getwd()
|
||||
So(err, ShouldBeNil)
|
||||
defer func() { _ = os.Chdir(workDir) }()
|
||||
|
||||
err = os.Chdir(os.TempDir())
|
||||
So(err, ShouldBeNil)
|
||||
path, err := tcommon.GetProjectRootDir()
|
||||
So(err, ShouldNotBeNil)
|
||||
So(err, ShouldEqual, tcommon.ErrNoGoModFileFound)
|
||||
So(path, ShouldBeZeroValue)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetCredString(t *testing.T) {
|
||||
Convey("GetCredString panics", t, func() {
|
||||
passwordSize := 100
|
||||
pass := make([]byte, passwordSize)
|
||||
for i := 0; i < passwordSize; i++ {
|
||||
pass[i] = 'Y'
|
||||
}
|
||||
f := func() { tcommon.GetCredString("testUser", string(pass)) }
|
||||
So(f, ShouldPanicWith, bcrypt.ErrPasswordTooLong)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
|
@ -15,9 +16,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
BaseURL = "http://127.0.0.1:%s"
|
||||
BaseSecureURL = "https://127.0.0.1:%s"
|
||||
SleepTime = 100 * time.Millisecond
|
||||
BaseURL = "http://127.0.0.1:%s"
|
||||
BaseSecureURL = "https://127.0.0.1:%s"
|
||||
SleepTime = 100 * time.Millisecond
|
||||
AuthorizationAllRepos = "**"
|
||||
)
|
||||
|
||||
type isser interface {
|
||||
|
@ -177,3 +179,35 @@ func CustomRedirectPolicy(noOfRedirect int) resty.RedirectPolicy {
|
|||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// Generates a random string with length 10 from lower case & upper case characters and
|
||||
// a seed that can be logged in tests (if test fails, you can reconstruct random string).
|
||||
func GenerateRandomString() (string, int64) {
|
||||
seed := time.Now().UnixNano()
|
||||
//nolint: gosec
|
||||
seededRand := rand.New(rand.NewSource(seed))
|
||||
charset := "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
|
||||
randomBytes := make([]byte, 10)
|
||||
for i := range randomBytes {
|
||||
randomBytes[i] = charset[seededRand.Intn(len(charset))]
|
||||
}
|
||||
|
||||
return string(randomBytes), seed
|
||||
}
|
||||
|
||||
// Generates a random string with length 10 from lower case characters and digits and
|
||||
// a seed that can be logged in tests (if test fails, you can reconstruct random string).
|
||||
func GenerateRandomName() (string, int64) {
|
||||
seed := time.Now().UnixNano()
|
||||
//nolint: gosec
|
||||
seededRand := rand.New(rand.NewSource(seed))
|
||||
charset := "abcdefghijklmnopqrstuvwxyz" + "0123456789"
|
||||
|
||||
randomBytes := make([]byte, 10)
|
||||
for i := range randomBytes {
|
||||
randomBytes[i] = charset[seededRand.Intn(len(charset))]
|
||||
}
|
||||
|
||||
return string(randomBytes), seed
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue