Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test against referrers API #856

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions integration/pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,12 @@ func TestMirror(t *testing.T) {
t.Fatalf("failed to generate htpasswd: %v", err)
}

authDir := t.TempDir()
hostVolumeMount := t.TempDir()
authDir := filepath.Join(hostVolumeMount, "auth")
if err := os.Mkdir(authDir, 0777); err != nil {
t.Fatalf("failed to create auth folder in tempdir: %v", err)
}

if err := os.WriteFile(filepath.Join(authDir, "domain.key"), key, 0666); err != nil {
t.Fatalf("failed to prepare key file")
}
Expand All @@ -653,7 +658,7 @@ func TestMirror(t *testing.T) {
RegistryAltImageRef: oci10RegistryImage,
RegistryHost: regConfig.host,
RegistryAltHost: regAltConfig.host,
AuthDir: authDir,
HostVolumeMount: hostVolumeMount,
})
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 5 additions & 0 deletions integration/push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ func TestLegacyOCI(t *testing.T) {
registryImage: oci10RegistryImage,
expectError: false,
},
{
name: "OCI 1.0 Artifacts succeed with OCI 1.1 registry",
registryImage: oci11RegistryImage,
expectError: false,
},
}
for _, tc := range tests {
tc := tc
Expand Down
60 changes: 55 additions & 5 deletions integration/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
"math/big"
"os"
"path/filepath"
"runtime"
"sort"
"strings"
"testing"
Expand Down Expand Up @@ -74,6 +75,7 @@ const (
// Registry images to use in the test infrastructure. These are not intended to be used
// as images in the test itself, but just when we're setting up docker compose.
oci10RegistryImage = "registry2:soci_test"
oci11RegistryImage = "ghcr.io/project-zot/zot-linux-" + runtime.GOARCH + ":v2.0.0-rc6"
)

// These are images that we use in our integration tests
Expand Down Expand Up @@ -175,7 +177,8 @@ services:
- REGISTRY_HTTP_ADDR={{.RegistryHost}}:443
- REGISTRY_STORAGE_DELETE_ENABLED=true
volumes:
- {{.AuthDir}}:/auth:ro
- {{.HostVolumeMount}}/auth:/auth:ro
- {{.HostVolumeMount}}/etc/zot/config.json:/etc/zot/config.json:ro
{{.NetworkConfig}}
`
const composeRegistryAltTemplate = `
Expand Down Expand Up @@ -206,7 +209,7 @@ services:
- REGISTRY_HTTP_ADDR={{.RegistryHost}}:443
- REGISTRY_STORAGE_DELETE_ENABLED=true
volumes:
- {{.AuthDir}}:/auth:ro
- {{.HostVolumeMount}}/auth:/auth:ro
registry-alt:
image: {{.RegistryAltImageRef}}
container_name: {{.RegistryAltHost}}
Expand All @@ -229,6 +232,28 @@ services:
target: {{.Registry2Stage}}
`

const zotConfigTemplate = `
{
"storage": {
"rootDirectory": "/tmp/zot"
},
"http": {
"address": "{{.Address}}",
"port": "443",
"realm": "Registry Realm",
"auth": {
"htpasswd": {
"path": "/auth/htpasswd"
}
},
"tls": {
"cert": "/auth/domain.crt",
"key": "/auth/domain.key"
}
}
}
`

type dockerComposeYaml struct {
ServiceName string
ImageContextDir string
Expand All @@ -238,10 +263,14 @@ type dockerComposeYaml struct {
RegistryAltImageRef string
RegistryHost string
RegistryAltHost string
AuthDir string
HostVolumeMount string
NetworkConfig string
}

type zotConfigStruct struct {
Address string
}

// getContainerdConfigToml creates a containerd config yaml, by appending all
// `additionalConfigs` to the default `containerdConfigTemplate`.
func getContainerdConfigToml(t *testing.T, disableVerification bool, additionalConfigs ...string) string {
Expand Down Expand Up @@ -447,7 +476,13 @@ func newShellWithRegistry(t *testing.T, r registryConfig, opts ...registryOpt) (
if err != nil {
t.Fatalf("failed to generate htpasswd: %v", err)
}
authDir := t.TempDir()

hostVolumeMount := t.TempDir()
authDir := filepath.Join(hostVolumeMount, "auth")
if err := os.Mkdir(authDir, 0777); err != nil {
t.Fatalf("failed to create auth folder in tempdir: %v", err)
}

if err := os.WriteFile(filepath.Join(authDir, "domain.key"), key, 0666); err != nil {
t.Fatalf("failed to prepare key file")
}
Expand Down Expand Up @@ -483,11 +518,26 @@ networks:
`, nw)
}

zotDir := filepath.Join(hostVolumeMount, "etc/zot")
if err := os.MkdirAll(zotDir, 0777); err != nil {
t.Fatalf("failed to create zot folder in tempdir: %v", err)
}
zotConfigFile, err := testutil.ApplyTextTemplate(zotConfigTemplate, zotConfigStruct{
sondavidb marked this conversation as resolved.
Show resolved Hide resolved
Address: r.host,
})
if err != nil {
t.Fatal(err)
}

if err := os.WriteFile(filepath.Join(hostVolumeMount, "etc/zot/config.json"), []byte(zotConfigFile), 0666); err != nil {
t.Fatalf("failed to prepare config.json: %v", err)
}

s, err := testutil.ApplyTextTemplate(composeRegistryTemplate, dockerComposeYaml{
ServiceName: serviceName,
RegistryHost: r.host,
RegistryImageRef: rOpts.registryImageRef,
AuthDir: authDir,
HostVolumeMount: hostVolumeMount,
NetworkConfig: networkConfig,
})
if err != nil {
Expand Down