From a0c215dee2e1c03879f6b441b7510707384ab78c Mon Sep 17 00:00:00 2001 From: David Son Date: Wed, 4 Oct 2023 22:25:49 +0000 Subject: [PATCH] Add test against referrers API Signed-off-by: David Son --- integration/pull_test.go | 9 ++++-- integration/push_test.go | 5 ++++ integration/util_test.go | 60 ++++++++++++++++++++++++++++++++++++---- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/integration/pull_test.go b/integration/pull_test.go index 84bdbfb16..e04b04f3d 100644 --- a/integration/pull_test.go +++ b/integration/pull_test.go @@ -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") } @@ -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) diff --git a/integration/push_test.go b/integration/push_test.go index 07eedf5e7..22b877f7c 100644 --- a/integration/push_test.go +++ b/integration/push_test.go @@ -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 diff --git a/integration/util_test.go b/integration/util_test.go index d38cda853..46d9cd2ff 100644 --- a/integration/util_test.go +++ b/integration/util_test.go @@ -45,6 +45,7 @@ import ( "math/big" "os" "path/filepath" + "runtime" "sort" "strings" "testing" @@ -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 @@ -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 = ` @@ -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}} @@ -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 @@ -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 { @@ -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") } @@ -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{ + 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 {