diff --git a/nexus3/pkg/repository/docker/docker_group_test.go b/nexus3/pkg/repository/docker/docker_group_test.go index e69029a..41a776e 100644 --- a/nexus3/pkg/repository/docker/docker_group_test.go +++ b/nexus3/pkg/repository/docker/docker_group_test.go @@ -31,6 +31,28 @@ func getTestDockerGroupRepository(name string) repository.DockerGroupRepository } } +func getTestProDockerGroupRepository(name string) repository.DockerGroupRepository { + return repository.DockerGroupRepository{ + Name: name, + Online: true, + + Group: repository.GroupDeploy{ + MemberNames: []string{}, + }, + Storage: repository.Storage{ + BlobStoreName: "default", + StrictContentTypeValidation: true, + }, + Docker: repository.Docker{ + ForceBasicAuth: true, + V1Enabled: false, + HTTPPort: tools.GetIntPointer(8080), + HTTPSPort: tools.GetIntPointer(8443), + Subdomain: tools.GetStringPointer(name), + }, + } +} + func TestDockerGroupRepository(t *testing.T) { service := getTestService() repo := getTestDockerGroupRepository("test-docker-repo-group-" + strconv.Itoa(rand.Intn(1024))) @@ -64,3 +86,40 @@ func TestDockerGroupRepository(t *testing.T) { service.Group.Delete(repo.Name) assert.Nil(t, err) } + +func TestProDockerGroupRepository(t *testing.T) { + if tools.GetEnv("SKIP_PRO_TESTS", "false") == "true" { + t.Skip("Skipping Nexus Pro tests") + } + service := getTestService() + repo := getTestProDockerGroupRepository("test-docker-repo-group-" + strconv.Itoa(rand.Intn(1024))) + + testProxyRepo := getTestDockerProxyRepository("test-docker-group-proxy-" + strconv.Itoa(rand.Intn(1024))) + defer service.Proxy.Delete(testProxyRepo.Name) + err := service.Proxy.Create(testProxyRepo) + assert.Nil(t, err) + repo.Group.MemberNames = append(repo.Group.MemberNames, testProxyRepo.Name) + + err = service.Group.Create(repo) + assert.Nil(t, err) + generatedRepo, err := service.Group.Get(repo.Name) + assert.Nil(t, err) + assert.Equal(t, repo.Online, generatedRepo.Online) + assert.Equal(t, repo.Group, generatedRepo.Group) + assert.Equal(t, repo.Storage, generatedRepo.Storage) + assert.Equal(t, repo.Docker, generatedRepo.Docker) + + updatedRepo := repo + updatedRepo.Online = false + updatedRepo.ForceBasicAuth = false + + err = service.Group.Update(repo.Name, updatedRepo) + assert.Nil(t, err) + generatedRepo, err = service.Group.Get(updatedRepo.Name) + assert.Nil(t, err) + assert.Equal(t, updatedRepo.Online, generatedRepo.Online) + assert.Equal(t, updatedRepo.ForceBasicAuth, generatedRepo.ForceBasicAuth) + + service.Group.Delete(repo.Name) + assert.Nil(t, err) +} diff --git a/nexus3/pkg/repository/docker/docker_hosted_test.go b/nexus3/pkg/repository/docker/docker_hosted_test.go index 1cd2364..c27fdaa 100644 --- a/nexus3/pkg/repository/docker/docker_hosted_test.go +++ b/nexus3/pkg/repository/docker/docker_hosted_test.go @@ -36,6 +36,33 @@ func getTestDockerHostedRepository(name string) repository.DockerHostedRepositor } } +func getTestProDockerHostedRepository(name string) repository.DockerHostedRepository { + writePolicy := repository.StorageWritePolicyAllow + return repository.DockerHostedRepository{ + Name: name, + Online: true, + + Cleanup: &repository.Cleanup{ + PolicyNames: []string{"weekly-cleanup"}, + }, + Storage: repository.HostedStorage{ + BlobStoreName: "default", + StrictContentTypeValidation: true, + WritePolicy: &writePolicy, + }, + Component: &repository.Component{ + ProprietaryComponents: true, + }, + Docker: repository.Docker{ + ForceBasicAuth: true, + V1Enabled: false, + HTTPPort: tools.GetIntPointer(8180), + HTTPSPort: tools.GetIntPointer(8543), + Subdomain: tools.GetStringPointer(name), + }, + } +} + func TestDockerHostedRepository(t *testing.T) { service := getTestService() repo := getTestDockerHostedRepository("test-docker-repo-hosted-" + strconv.Itoa(rand.Intn(1024))) @@ -64,3 +91,35 @@ func TestDockerHostedRepository(t *testing.T) { service.Hosted.Delete(repo.Name) assert.Nil(t, err) } + +func TestProDockerHostedRepository(t *testing.T) { + if tools.GetEnv("SKIP_PRO_TESTS", "false") == "true" { + t.Skip("Skipping Nexus Pro tests") + } + service := getTestService() + repo := getTestProDockerHostedRepository("test-docker-repo-hosted-" + strconv.Itoa(rand.Intn(1024))) + + err := service.Hosted.Create(repo) + assert.Nil(t, err) + generatedRepo, err := service.Hosted.Get(repo.Name) + assert.Nil(t, err) + assert.Equal(t, repo.Online, generatedRepo.Online) + assert.Equal(t, repo.Cleanup, generatedRepo.Cleanup) + assert.Equal(t, repo.Storage, generatedRepo.Storage) + assert.Equal(t, repo.Component, generatedRepo.Component) + assert.Equal(t, repo.Docker, generatedRepo.Docker) + + updatedRepo := repo + updatedRepo.Online = false + updatedRepo.V1Enabled = true + + err = service.Hosted.Update(repo.Name, updatedRepo) + assert.Nil(t, err) + generatedRepo, err = service.Hosted.Get(updatedRepo.Name) + assert.Nil(t, err) + assert.Equal(t, updatedRepo.Online, generatedRepo.Online) + assert.Equal(t, updatedRepo.V1Enabled, generatedRepo.V1Enabled) + + service.Hosted.Delete(repo.Name) + assert.Nil(t, err) +} diff --git a/nexus3/pkg/repository/docker/docker_proxy_test.go b/nexus3/pkg/repository/docker/docker_proxy_test.go index ef142e6..eeb7399 100644 --- a/nexus3/pkg/repository/docker/docker_proxy_test.go +++ b/nexus3/pkg/repository/docker/docker_proxy_test.go @@ -47,6 +47,44 @@ func getTestDockerProxyRepository(name string) repository.DockerProxyRepository } } +func getTestProDockerProxyRepository(name string) repository.DockerProxyRepository { + return repository.DockerProxyRepository{ + Name: name, + Online: true, + HTTPClient: repository.HTTPClient{ + Blocked: true, + AutoBlock: true, + Connection: &repository.HTTPClientConnection{ + Timeout: tools.GetIntPointer(20), + UseTrustStore: tools.GetBoolPointer(true), + }, + }, + NegativeCache: repository.NegativeCache{ + Enabled: true, + TTL: 1440, + }, + Proxy: repository.Proxy{ + ContentMaxAge: 1440, + MetadataMaxAge: 1440, + RemoteURL: "https://archive.ubuntu.com/ubuntu/", + }, + Storage: repository.Storage{ + BlobStoreName: "default", + StrictContentTypeValidation: true, + }, + Docker: repository.Docker{ + ForceBasicAuth: true, + V1Enabled: false, + HTTPPort: tools.GetIntPointer(8280), + HTTPSPort: tools.GetIntPointer(8643), + Subdomain: tools.GetStringPointer(name), + }, + DockerProxy: repository.DockerProxy{ + IndexType: repository.DockerProxyIndexTypeHub, + }, + } +} + func TestDockerProxyRepository(t *testing.T) { service := getTestService() repo := getTestDockerProxyRepository("test-docker-repo-hosted-" + strconv.Itoa(rand.Intn(1024))) @@ -79,3 +117,39 @@ func TestDockerProxyRepository(t *testing.T) { service.Proxy.Delete(repo.Name) assert.Nil(t, err) } + +func TestProDockerProxyRepository(t *testing.T) { + if tools.GetEnv("SKIP_PRO_TESTS", "false") == "true" { + t.Skip("Skipping Nexus Pro tests") + } + service := getTestService() + repo := getTestProDockerProxyRepository("test-docker-repo-hosted-" + strconv.Itoa(rand.Intn(1024))) + + err := service.Proxy.Create(repo) + assert.Nil(t, err) + generatedRepo, err := service.Proxy.Get(repo.Name) + assert.Nil(t, err) + assert.Equal(t, repo.Online, generatedRepo.Online) + assert.Equal(t, repo.HTTPClient.Blocked, generatedRepo.HTTPClient.Blocked) + assert.Equal(t, repo.HTTPClient.AutoBlock, generatedRepo.HTTPClient.AutoBlock) + assert.Equal(t, repo.HTTPClient.Connection.Timeout, generatedRepo.HTTPClient.Connection.Timeout) + assert.Equal(t, repo.HTTPClient.Connection.UseTrustStore, generatedRepo.HTTPClient.Connection.UseTrustStore) + assert.Equal(t, repo.NegativeCache, generatedRepo.NegativeCache) + assert.Equal(t, repo.Proxy, generatedRepo.Proxy) + assert.Equal(t, repo.Storage, generatedRepo.Storage) + assert.Equal(t, repo.Docker, generatedRepo.Docker) + assert.Equal(t, repo.DockerProxy, generatedRepo.DockerProxy) + + updatedRepo := repo + updatedRepo.Online = false + + err = service.Proxy.Update(repo.Name, updatedRepo) + assert.Nil(t, err) + generatedRepo, err = service.Proxy.Get(updatedRepo.Name) + assert.Nil(t, err) + assert.Equal(t, updatedRepo.Online, generatedRepo.Online) + assert.Equal(t, updatedRepo.Docker, generatedRepo.Docker) + + service.Proxy.Delete(repo.Name) + assert.Nil(t, err) +} diff --git a/nexus3/schema/repository/docker.go b/nexus3/schema/repository/docker.go index f217986..8534f3d 100644 --- a/nexus3/schema/repository/docker.go +++ b/nexus3/schema/repository/docker.go @@ -56,6 +56,8 @@ type Docker struct { HTTPSPort *int `json:"httpsPort,omitempty"` // Whether to allow clients to use the V1 API to interact with this repository V1Enabled bool `json:"v1Enabled"` + // Whether to allow subdomain connector at the specified subdomain + Subdomain *string `json:"subdomain,omitempty"` } // DockerProxy contains data of a Docker Proxy Repository