2021-12-03 22:50:58 -05:00
|
|
|
//go:build extended
|
2021-10-15 10:05:00 -05:00
|
|
|
// +build extended
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
package sync_test
|
|
|
|
|
|
|
|
import (
|
2021-12-07 13:26:26 -05:00
|
|
|
"context"
|
2021-06-08 15:11:18 -05:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
|
|
|
"io/ioutil"
|
2022-01-19 14:54:17 -05:00
|
|
|
"net/http"
|
2021-06-08 15:11:18 -05:00
|
|
|
"os"
|
2021-12-07 13:26:26 -05:00
|
|
|
"os/exec"
|
2021-06-08 15:11:18 -05:00
|
|
|
"path"
|
|
|
|
"reflect"
|
|
|
|
"strings"
|
2022-01-10 11:06:12 -05:00
|
|
|
goSync "sync"
|
2021-06-08 15:11:18 -05:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
"github.com/notaryproject/notation-go-lib"
|
|
|
|
godigest "github.com/opencontainers/go-digest"
|
2021-06-08 15:11:18 -05:00
|
|
|
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
2021-12-07 13:26:26 -05:00
|
|
|
artifactspec "github.com/oras-project/artifacts-spec/specs-go/v1"
|
2022-01-19 14:54:17 -05:00
|
|
|
perr "github.com/pkg/errors"
|
2021-12-07 13:26:26 -05:00
|
|
|
"github.com/sigstore/cosign/cmd/cosign/cli/generate"
|
|
|
|
"github.com/sigstore/cosign/cmd/cosign/cli/options"
|
|
|
|
"github.com/sigstore/cosign/cmd/cosign/cli/sign"
|
|
|
|
"github.com/sigstore/cosign/cmd/cosign/cli/verify"
|
2021-06-08 15:11:18 -05:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
|
|
|
"gopkg.in/resty.v1"
|
2021-12-03 22:50:58 -05:00
|
|
|
"zotregistry.io/zot/pkg/api"
|
|
|
|
"zotregistry.io/zot/pkg/api/config"
|
|
|
|
extconf "zotregistry.io/zot/pkg/extensions/config"
|
|
|
|
"zotregistry.io/zot/pkg/extensions/sync"
|
2022-01-19 14:54:17 -05:00
|
|
|
"zotregistry.io/zot/pkg/test"
|
2021-06-08 15:11:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2021-11-10 09:31:03 -05:00
|
|
|
ServerCert = "../../../test/data/server.cert"
|
|
|
|
ServerKey = "../../../test/data/server.key"
|
|
|
|
CACert = "../../../test/data/ca.crt"
|
|
|
|
ClientCert = "../../../test/data/client.cert"
|
|
|
|
ClientKey = "../../../test/data/client.key"
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
testImage = "zot-test"
|
|
|
|
testImageTag = "0.0.1"
|
2021-11-25 07:04:39 -05:00
|
|
|
testCveImage = "zot-cve-test"
|
2022-01-10 11:06:12 -05:00
|
|
|
|
|
|
|
testSignedImage = "signed-repo"
|
2021-06-08 15:11:18 -05:00
|
|
|
)
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
var (
|
|
|
|
errSync = errors.New("sync error, src oci repo differs from dest one")
|
|
|
|
errBadStatus = errors.New("bad http status")
|
|
|
|
)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
type TagsList struct {
|
|
|
|
Name string
|
|
|
|
Tags []string
|
|
|
|
}
|
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
type ReferenceList struct {
|
|
|
|
References []notation.Descriptor `json:"references"`
|
|
|
|
}
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
type catalog struct {
|
|
|
|
Repositories []string `json:"repositories"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func copyFile(sourceFilePath, destFilePath string) error {
|
|
|
|
destFile, err := os.Create(destFilePath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer destFile.Close()
|
|
|
|
|
|
|
|
sourceFile, err := os.Open(sourceFilePath)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer sourceFile.Close()
|
|
|
|
|
|
|
|
if _, err = io.Copy(destFile, sourceFile); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
func startUpstreamServer(secure, basicAuth bool) (*api.Controller, string, string, string, *resty.Client) {
|
2022-01-19 14:54:17 -05:00
|
|
|
srcPort := test.GetFreePort()
|
2021-11-25 07:04:39 -05:00
|
|
|
|
|
|
|
srcConfig := config.New()
|
|
|
|
|
|
|
|
client := resty.New()
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
var srcBaseURL string
|
|
|
|
if secure {
|
2022-01-19 14:54:17 -05:00
|
|
|
srcBaseURL = test.GetSecureBaseURL(srcPort)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
srcConfig.HTTP.TLS = &config.TLSConfig{
|
|
|
|
Cert: ServerCert,
|
|
|
|
Key: ServerKey,
|
|
|
|
CACert: CACert,
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
caCert, err := ioutil.ReadFile(CACert)
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
caCertPool := x509.NewCertPool()
|
|
|
|
caCertPool.AppendCertsFromPEM(caCert)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
client.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool, MinVersion: tls.VersionTLS12})
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
cert, err := tls.LoadX509KeyPair("../../../test/data/client.cert", "../../../test/data/client.key")
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
client.SetCertificates(cert)
|
|
|
|
} else {
|
2022-01-19 14:54:17 -05:00
|
|
|
srcBaseURL = test.GetBaseURL(srcPort)
|
2021-11-25 07:04:39 -05:00
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
var htpasswdPath string
|
|
|
|
if basicAuth {
|
2022-01-19 14:54:17 -05:00
|
|
|
htpasswdPath = test.MakeHtpasswdFile()
|
2021-11-25 07:04:39 -05:00
|
|
|
srcConfig.HTTP.Auth = &config.AuthConfig{
|
|
|
|
HTPasswd: config.AuthHTPasswd{
|
|
|
|
Path: htpasswdPath,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
srcConfig.HTTP.Port = srcPort
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-10-22 04:56:55 -05:00
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
err = test.CopyFiles("../../../test/data", srcDir)
|
2021-11-25 07:04:39 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
srcConfig.Storage.RootDirectory = srcDir
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
sctlr := api.NewController(srcConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
// this blocks
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := sctlr.Run(); err != nil {
|
2021-11-25 07:04:39 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// wait till ready
|
|
|
|
for {
|
|
|
|
_, err := client.R().Get(srcBaseURL)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
return sctlr, srcBaseURL, srcDir, htpasswdPath, client
|
2021-11-25 07:04:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func startDownstreamServer(secure bool, syncConfig *sync.Config) (*api.Controller, string, string, *resty.Client) {
|
2022-01-19 14:54:17 -05:00
|
|
|
destPort := test.GetFreePort()
|
2021-11-25 07:04:39 -05:00
|
|
|
|
|
|
|
destConfig := config.New()
|
|
|
|
|
|
|
|
client := resty.New()
|
|
|
|
|
|
|
|
var destBaseURL string
|
|
|
|
if secure {
|
2022-01-19 14:54:17 -05:00
|
|
|
destBaseURL = test.GetSecureBaseURL(destPort)
|
2021-11-25 07:04:39 -05:00
|
|
|
|
|
|
|
destConfig.HTTP.TLS = &config.TLSConfig{
|
|
|
|
Cert: ServerCert,
|
|
|
|
Key: ServerKey,
|
|
|
|
CACert: CACert,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
caCert, err := ioutil.ReadFile(CACert)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
caCertPool := x509.NewCertPool()
|
|
|
|
caCertPool.AppendCertsFromPEM(caCert)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
client.SetTLSClientConfig(&tls.Config{RootCAs: caCertPool, MinVersion: tls.VersionTLS12})
|
2021-11-25 07:04:39 -05:00
|
|
|
|
|
|
|
cert, err := tls.LoadX509KeyPair("../../../test/data/client.cert", "../../../test/data/client.key")
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
client.SetCertificates(cert)
|
|
|
|
} else {
|
2022-01-19 14:54:17 -05:00
|
|
|
destBaseURL = test.GetBaseURL(destPort)
|
2021-11-25 07:04:39 -05:00
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
destConfig.HTTP.Port = destPort
|
|
|
|
|
|
|
|
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
destConfig.Storage.RootDirectory = destDir
|
2021-12-07 13:26:26 -05:00
|
|
|
destConfig.Storage.Dedupe = false
|
|
|
|
destConfig.Storage.GC = false
|
2021-11-25 07:04:39 -05:00
|
|
|
|
|
|
|
destConfig.Extensions = &extconf.ExtensionConfig{}
|
|
|
|
destConfig.Extensions.Search = nil
|
|
|
|
destConfig.Extensions.Sync = syncConfig
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr := api.NewController(destConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
// this blocks
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := dctlr.Run(); err != nil {
|
2021-11-25 07:04:39 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// wait till ready
|
|
|
|
for {
|
|
|
|
_, err := client.R().Get(destBaseURL)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
return dctlr, destBaseURL, destDir, client
|
2021-11-25 07:04:39 -05:00
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestOnDemand(t *testing.T) {
|
2021-11-25 07:04:39 -05:00
|
|
|
Convey("Verify sync on demand feature", t, func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, srcClient := startUpstreamServer(false, false)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-11-25 07:04:39 -05:00
|
|
|
}()
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
|
2021-10-25 07:05:03 -05:00
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
2021-10-25 07:05:03 -05:00
|
|
|
Prefix: testImage,
|
2021-06-08 15:11:18 -05:00
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-25 07:05:03 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{
|
2021-12-13 14:23:31 -05:00
|
|
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
var srcTagsList TagsList
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, _ := srcClient.R().Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-06-08 15:11:18 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
err := json.Unmarshal(resp.Body(), &srcTagsList)
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + "inexistent" + "/manifests/" + testImageTag)
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "inexistent")
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(path.Join(destDir, testImage), 0o000)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 500)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(path.Join(destDir, testImage), 0o755)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "1.1.1")
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(path.Join(destDir, testImage, sync.SyncBlobUploadDir), 0o000)
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "1.1.1")
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(path.Join(destDir, testImage, sync.SyncBlobUploadDir), 0o755)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.MkdirAll(path.Join(destDir, testImage, "blobs"), 0o000)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(path.Join(destDir, testImage, "blobs"), 0o755)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
So(destTagsList, ShouldResemble, srcTagsList)
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestPeriodically(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync feature", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, srcClient := startUpstreamServer(false, false)
|
2021-06-08 15:11:18 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
maxRetries := 1
|
|
|
|
delay := 1 * time.Second
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
2022-01-10 11:06:12 -05:00
|
|
|
MaxRetries: &maxRetries,
|
|
|
|
RetryDelay: &delay,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
var srcTagsList TagsList
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, _ := srcClient.R().Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-06-08 15:11:18 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
err := json.Unmarshal(resp.Body(), &srcTagsList)
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(destTagsList.Tags) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
time.Sleep(500 * time.Millisecond)
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
So(destTagsList, ShouldResemble, srcTagsList)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
Convey("Test sync with more contents", func() {
|
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
|
|
|
|
invalidRegex := "invalid"
|
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Prefix: testCveImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: &invalidRegex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-22 04:56:55 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-10-22 04:56:55 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-10-22 04:56:55 -05:00
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
var srcTagsList TagsList
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err := srcClient.R().Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
|
|
|
So(err, ShouldBeNil)
|
2021-10-22 04:56:55 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &srcTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-10-22 04:56:55 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(destTagsList.Tags) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
So(destTagsList, ShouldResemble, srcTagsList)
|
|
|
|
|
|
|
|
// testCveImage should not be synced because of regex being "invalid", shouldn't match anything
|
|
|
|
resp, _ = srcClient.R().Get(srcBaseURL + "/v2/" + testCveImage + "/tags/list")
|
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &srcTagsList)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testCveImage + "/tags/list")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
So(destTagsList, ShouldNotResemble, srcTagsList)
|
2021-10-22 04:56:55 -05:00
|
|
|
})
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestPermsDenied(t *testing.T) {
|
2021-10-28 04:10:01 -05:00
|
|
|
Convey("Verify sync feature without perm on sync cache", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-10-28 04:10:01 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-28 04:10:01 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-28 04:10:01 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
2022-01-07 07:28:45 -05:00
|
|
|
OnDemand: true,
|
2021-10-28 04:10:01 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-28 04:10:01 -05:00
|
|
|
}()
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err := os.Chmod(path.Join(destDir, testImage, sync.SyncBlobUploadDir), 0o000)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
|
|
|
err = os.Chmod(path.Join(destDir, testImage, sync.SyncBlobUploadDir), 0o755)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-11-25 07:04:39 -05:00
|
|
|
})
|
|
|
|
}
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestBadTLS(t *testing.T) {
|
2021-11-25 07:04:39 -05:00
|
|
|
Convey("Verify sync TLS feature", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(true, false)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-11-25 07:04:39 -05:00
|
|
|
}()
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
tlsVerify := true
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-28 04:10:01 -05:00
|
|
|
OnDemand: true,
|
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(true, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-28 04:10:01 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// give it time to set up sync
|
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
resp, _ := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "invalid")
|
2021-10-28 04:10:01 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, _ = destClient.R().Get(destBaseURL + "/v2/" + "invalid" + "/manifests/" + testImageTag)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
2022-01-07 07:28:45 -05:00
|
|
|
|
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
2021-10-28 04:10:01 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestTLS(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync TLS feature", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("1h")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(true, false)
|
2021-06-08 15:11:18 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
var srcIndex ispec.Index
|
|
|
|
var destIndex ispec.Index
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
srcBuf, err := ioutil.ReadFile(path.Join(srcDir, testImage, "index.json"))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := json.Unmarshal(srcBuf, &srcIndex); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
// copy upstream client certs, use them in sync config
|
|
|
|
destClientCertDir, err := ioutil.TempDir("", "destCerts")
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
destFilePath := path.Join(destClientCertDir, "ca.crt")
|
2021-06-08 15:11:18 -05:00
|
|
|
err = copyFile(CACert, destFilePath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
destFilePath = path.Join(destClientCertDir, "client.cert")
|
2021-06-08 15:11:18 -05:00
|
|
|
err = copyFile(ClientCert, destFilePath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
destFilePath = path.Join(destClientCertDir, "client.key")
|
2021-06-08 15:11:18 -05:00
|
|
|
err = copyFile(ClientKey, destFilePath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
defer os.RemoveAll(destClientCertDir)
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
tlsVerify := true
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
2021-10-28 04:10:01 -05:00
|
|
|
CertDir: destClientCertDir,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, _, destDir, _ := startDownstreamServer(true, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
// wait till ready
|
|
|
|
for {
|
|
|
|
destBuf, _ := ioutil.ReadFile(path.Join(destDir, testImage, "index.json"))
|
|
|
|
_ = json.Unmarshal(destBuf, &destIndex)
|
2021-10-22 04:56:55 -05:00
|
|
|
time.Sleep(500 * time.Millisecond)
|
2021-06-08 15:11:18 -05:00
|
|
|
if len(destIndex.Manifests) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var found bool
|
|
|
|
for _, manifest := range srcIndex.Manifests {
|
|
|
|
if reflect.DeepEqual(manifest.Annotations, destIndex.Manifests[0].Annotations) {
|
|
|
|
found = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
|
|
|
panic(errSync)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestBasicAuth(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync basic auth", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("1h")
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
Convey("Verify sync basic auth with file credentials", func() {
|
|
|
|
sctlr, srcBaseURL, srcDir, htpasswdPath, srcClient := startUpstreamServer(false, true)
|
|
|
|
defer os.Remove(htpasswdPath)
|
|
|
|
defer os.RemoveAll(srcDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
2021-10-22 04:56:55 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
registryName := sync.StripRegistryTransport(srcBaseURL)
|
2021-10-28 04:10:01 -05:00
|
|
|
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "test"}}`, registryName))
|
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-28 04:10:01 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
syncConfig := &sync.Config{
|
|
|
|
CredentialsFile: credentialsFile,
|
|
|
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
|
|
|
}
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-28 04:10:01 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
var srcTagsList TagsList
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, _ := srcClient.R().SetBasicAuth("test", "test").Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-10-28 04:10:01 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
err := json.Unmarshal(resp.Body(), &srcTagsList)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(destTagsList.Tags) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
So(destTagsList, ShouldResemble, srcTagsList)
|
2021-10-28 04:10:01 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Verify sync basic auth with wrong file credentials", func() {
|
2022-01-10 11:06:12 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, htpasswdPath, _ := startUpstreamServer(false, true)
|
|
|
|
defer os.Remove(htpasswdPath)
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
destPort := test.GetFreePort()
|
|
|
|
destBaseURL := test.GetBaseURL(destPort)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
destConfig := config.New()
|
|
|
|
destConfig.HTTP.Port = destPort
|
|
|
|
|
|
|
|
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
destConfig.Storage.SubPaths = map[string]config.StorageConfig{
|
|
|
|
"a": {
|
|
|
|
RootDirectory: destDir,
|
|
|
|
GC: true,
|
|
|
|
Dedupe: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
destConfig.Storage.RootDirectory = destDir
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
registryName := sync.StripRegistryTransport(srcBaseURL)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "invalid"}}`,
|
|
|
|
registryName))
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
2021-10-28 04:10:01 -05:00
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
2021-06-08 15:11:18 -05:00
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
2021-10-28 04:10:01 -05:00
|
|
|
OnDemand: true,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
destConfig.Extensions = &extconf.ExtensionConfig{}
|
|
|
|
destConfig.Extensions.Search = nil
|
2021-12-13 14:23:31 -05:00
|
|
|
destConfig.Extensions.Sync = &sync.Config{
|
|
|
|
CredentialsFile: credentialsFile,
|
|
|
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr := api.NewController(destConfig)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
// this blocks
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := dctlr.Run(); err != nil {
|
2021-06-08 15:11:18 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
// wait till ready
|
|
|
|
for {
|
|
|
|
_, err := resty.R().Get(destBaseURL)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Verify sync basic auth with bad file credentials", func() {
|
2022-01-10 11:06:12 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, htpasswdPath, _ := startUpstreamServer(false, true)
|
|
|
|
defer os.Remove(htpasswdPath)
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
registryName := sync.StripRegistryTransport(srcBaseURL)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "test"}}`,
|
2021-06-08 15:11:18 -05:00
|
|
|
registryName))
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err := os.Chmod(credentialsFile, 0o000)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
defer func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
So(os.Chmod(credentialsFile, 0o755), ShouldBeNil)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(os.RemoveAll(credentialsFile), ShouldBeNil)
|
|
|
|
}()
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
2021-06-08 15:11:18 -05:00
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
syncConfig := &sync.Config{
|
|
|
|
CredentialsFile: credentialsFile,
|
|
|
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
time.Sleep(2 * time.Second)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Verify on demand sync with basic auth", func() {
|
2022-01-10 11:06:12 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, htpasswdPath, srcClient := startUpstreamServer(false, true)
|
|
|
|
defer os.Remove(htpasswdPath)
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
registryName := sync.StripRegistryTransport(srcBaseURL)
|
2021-06-08 15:11:18 -05:00
|
|
|
credentialsFile := makeCredentialsFile(fmt.Sprintf(`{"%s":{"username": "test", "password": "test"}}`, registryName))
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
unreacheableSyncRegistryConfig1 := sync.RegistryConfig{
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{"localhost:9999"},
|
2021-06-08 15:11:18 -05:00
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
unreacheableSyncRegistryConfig2 := sync.RegistryConfig{
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{"localhost:9999"},
|
2021-06-08 15:11:18 -05:00
|
|
|
OnDemand: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
// add file path to the credentials
|
2021-12-13 14:23:31 -05:00
|
|
|
syncConfig := &sync.Config{
|
|
|
|
CredentialsFile: credentialsFile,
|
|
|
|
Registries: []sync.RegistryConfig{
|
|
|
|
unreacheableSyncRegistryConfig1,
|
2021-06-08 15:11:18 -05:00
|
|
|
unreacheableSyncRegistryConfig2,
|
2021-12-13 14:23:31 -05:00
|
|
|
syncRegistryConfig,
|
|
|
|
},
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
var srcTagsList TagsList
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, _ := srcClient.R().SetBasicAuth("test", "test").Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-06-08 15:11:18 -05:00
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
err := json.Unmarshal(resp.Body(), &srcTagsList)
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + "inexistent" + "/manifests/" + testImageTag)
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "inexistent")
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = dctlr.StoreController.DefaultStore.DeleteImageManifest(testImage, testImageTag)
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "1.1.1")
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "inexistent")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
So(destTagsList, ShouldResemble, srcTagsList)
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestBadURL(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync with bad url", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("1h")
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2022-01-10 11:06:12 -05:00
|
|
|
URLs: []string{"bad-registry-url]"},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
2022-01-07 07:28:45 -05:00
|
|
|
OnDemand: true,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-11-25 07:04:39 -05:00
|
|
|
}()
|
2022-01-10 11:06:12 -05:00
|
|
|
|
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestNoImagesByRegex(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync with no images on source based on regex", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("1h")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-06-08 15:11:18 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
regex := "9.9.9"
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
PollInterval: updateDuration,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/_catalog")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp, ShouldNotBeEmpty)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
var c catalog
|
|
|
|
err = json.Unmarshal(resp.Body(), &c)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
So(c.Repositories, ShouldResemble, []string{})
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestInvalidRegex(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync with invalid regex", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("1h")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-06-08 15:11:18 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
regex := "["
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
PollInterval: updateDuration,
|
|
|
|
CertDir: "",
|
2022-01-07 07:28:45 -05:00
|
|
|
OnDemand: true,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, _, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestNotSemver(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync feature semver compliant", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-06-08 15:11:18 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
// get manifest so we can update it with a semver non compliant tag
|
|
|
|
resp, err := resty.R().Get(srcBaseURL + "/v2/zot-test/manifests/0.0.1")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
manifestBlob := resp.Body()
|
|
|
|
|
|
|
|
resp, err = resty.R().SetHeader("Content-type", "application/vnd.oci.image.manifest.v1+json").
|
|
|
|
SetBody(manifestBlob).
|
|
|
|
Put(srcBaseURL + "/v2/" + testImage + "/manifests/notSemverTag")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 201)
|
|
|
|
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
var destTagsList TagsList
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
for {
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp, ShouldNotBeNil)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-01-07 07:28:45 -05:00
|
|
|
if len(destTagsList.Tags) > 0 {
|
|
|
|
break
|
|
|
|
}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
So(len(destTagsList.Tags), ShouldEqual, 1)
|
|
|
|
So(destTagsList.Tags[0], ShouldEqual, testImageTag)
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestInvalidCerts(t *testing.T) {
|
2021-06-08 15:11:18 -05:00
|
|
|
Convey("Verify sync with bad certs", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("1h")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(true, false)
|
2021-06-08 15:11:18 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
// copy client certs, use them in sync config
|
|
|
|
clientCertDir, err := ioutil.TempDir("", "certs")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
destFilePath := path.Join(clientCertDir, "ca.crt")
|
|
|
|
err = copyFile(CACert, destFilePath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
dstfile, err := os.OpenFile(destFilePath, os.O_TRUNC|os.O_WRONLY|os.O_CREATE, 0o600)
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
defer dstfile.Close()
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
if _, err = dstfile.WriteString("Add Invalid Text In Cert"); err != nil {
|
2021-06-08 15:11:18 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
destFilePath = path.Join(clientCertDir, "client.cert")
|
|
|
|
err = copyFile(ClientCert, destFilePath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
destFilePath = path.Join(clientCertDir, "client.key")
|
|
|
|
err = copyFile(ClientKey, destFilePath)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
defer os.RemoveAll(clientCertDir)
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: "",
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: clientCertDir,
|
2022-01-07 07:28:45 -05:00
|
|
|
OnDemand: true,
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
2021-10-22 04:56:55 -05:00
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-22 04:56:55 -05:00
|
|
|
}()
|
2021-06-08 15:11:18 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func makeCredentialsFile(fileContent string) string {
|
2021-12-13 14:23:31 -05:00
|
|
|
tmpfile, err := ioutil.TempFile("", "sync-credentials-")
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
content := []byte(fileContent)
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := ioutil.WriteFile(tmpfile.Name(), content, 0o600); err != nil {
|
2021-06-08 15:11:18 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
return tmpfile.Name()
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestInvalidUrl(t *testing.T) {
|
2021-10-28 04:10:01 -05:00
|
|
|
Convey("Verify sync invalid url", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
// won't match any image on source registry, we will sync on demand
|
|
|
|
Prefix: "dummy",
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{"http://invalid.invalid/invalid/"},
|
2021-10-28 04:10:01 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-28 04:10:01 -05:00
|
|
|
}()
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestInvalidTags(t *testing.T) {
|
2021-11-25 07:04:39 -05:00
|
|
|
Convey("Verify sync invalid tags", t, func() {
|
2021-10-28 04:10:01 -05:00
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-10-28 04:10:01 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-28 04:10:01 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
// won't match any image on source registry, we will sync on demand
|
|
|
|
Prefix: "dummy",
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-28 04:10:01 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
syncConfig := &sync.Config{
|
2021-12-13 14:23:31 -05:00
|
|
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
|
|
|
}
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-11-25 07:04:39 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-28 04:10:01 -05:00
|
|
|
}()
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + "invalid:tag")
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
}
|
2021-12-06 09:41:04 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestSubPaths(t *testing.T) {
|
2021-12-06 09:41:04 -05:00
|
|
|
Convey("Verify sync with storage subPaths", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
srcPort := test.GetFreePort()
|
2021-12-06 09:41:04 -05:00
|
|
|
srcConfig := config.New()
|
|
|
|
client := resty.New()
|
2022-01-19 14:54:17 -05:00
|
|
|
srcBaseURL := test.GetBaseURL(srcPort)
|
2021-12-06 09:41:04 -05:00
|
|
|
|
|
|
|
srcConfig.HTTP.Port = srcPort
|
|
|
|
|
|
|
|
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
subpath := "/subpath"
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
err = test.CopyFiles("../../../test/data", path.Join(srcDir, subpath))
|
2021-12-06 09:41:04 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
srcConfig.Storage.RootDirectory = srcDir
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
sctlr := api.NewController(srcConfig)
|
2021-12-06 09:41:04 -05:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
// this blocks
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := sctlr.Run(); err != nil {
|
2021-12-06 09:41:04 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// wait till ready
|
|
|
|
for {
|
|
|
|
_, err := client.R().Get(srcBaseURL)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
sctlr.Shutdown()
|
2021-12-06 09:41:04 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: path.Join(subpath, testImage),
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-12-06 09:41:04 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{
|
2021-12-13 14:23:31 -05:00
|
|
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
|
|
|
}
|
2021-12-06 09:41:04 -05:00
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
destPort := test.GetFreePort()
|
2021-12-06 09:41:04 -05:00
|
|
|
destConfig := config.New()
|
|
|
|
|
|
|
|
destDir, err := ioutil.TempDir("", "oci-dest-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
subPathDestDir, err := ioutil.TempDir("", "oci-dest-subpath-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(subPathDestDir)
|
|
|
|
|
|
|
|
destConfig.Storage.RootDirectory = destDir
|
|
|
|
|
|
|
|
destConfig.Storage.SubPaths = map[string]config.StorageConfig{
|
|
|
|
subpath: {
|
|
|
|
RootDirectory: subPathDestDir,
|
|
|
|
GC: true,
|
|
|
|
Dedupe: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
destBaseURL := test.GetBaseURL(destPort)
|
2021-12-06 09:41:04 -05:00
|
|
|
destConfig.HTTP.Port = destPort
|
|
|
|
|
|
|
|
destConfig.Extensions = &extconf.ExtensionConfig{}
|
|
|
|
destConfig.Extensions.Search = nil
|
|
|
|
destConfig.Extensions.Sync = syncConfig
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr := api.NewController(destConfig)
|
2021-12-06 09:41:04 -05:00
|
|
|
|
|
|
|
go func() {
|
|
|
|
// this blocks
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := dctlr.Run(); err != nil {
|
2021-12-06 09:41:04 -05:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// wait till ready
|
|
|
|
for {
|
|
|
|
_, err := resty.R().Get(destBaseURL)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
dctlr.Shutdown()
|
2021-12-06 09:41:04 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
|
|
|
for {
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2" + path.Join(subpath, testImage) + "/tags/list")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(destTagsList.Tags) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
// synced image should get into subpath instead of rootDir
|
2021-12-13 14:23:31 -05:00
|
|
|
binfo, err := os.Stat(path.Join(subPathDestDir, subpath, testImage, "blobs/sha256"))
|
|
|
|
So(binfo, ShouldNotBeNil)
|
2021-12-06 09:41:04 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// check rootDir is not populated with any image.
|
2021-12-13 14:23:31 -05:00
|
|
|
binfo, err = os.Stat(path.Join(destDir, subpath))
|
|
|
|
So(binfo, ShouldBeNil)
|
2021-12-06 09:41:04 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
}
|
2021-10-25 07:05:03 -05:00
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
func TestOnDemandRepoErr(t *testing.T) {
|
2021-12-07 13:26:26 -05:00
|
|
|
Convey("Verify sync on demand parseRepositoryReference error", t, func() {
|
|
|
|
tlsVerify := false
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
// will sync on demand, should not be filtered out
|
|
|
|
Prefix: testImage,
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{"docker://invalid"},
|
2021-12-07 13:26:26 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-12-07 13:26:26 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-12-07 13:26:26 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestOnDemandContentFiltering(t *testing.T) {
|
2021-10-25 07:05:03 -05:00
|
|
|
Convey("Verify sync on demand feature", t, func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-10-25 07:05:03 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-25 07:05:03 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
Convey("Test image is filtered out by content", func() {
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
2021-12-13 14:23:31 -05:00
|
|
|
// should be filtered out
|
2021-10-25 07:05:03 -05:00
|
|
|
Prefix: "dummy",
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-25 07:05:03 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-10-25 07:05:03 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-25 07:05:03 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test image is not filtered out by content", func() {
|
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
// will sync on demand, should not be filtered out
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-25 07:05:03 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-10-25 07:05:03 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-25 07:05:03 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestConfigRules(t *testing.T) {
|
2021-10-25 07:05:03 -05:00
|
|
|
Convey("Verify sync config rules", t, func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-10-25 07:05:03 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-10-25 07:05:03 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
Convey("Test periodically sync is disabled when pollInterval is not set", func() {
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-25 07:05:03 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-10-25 07:05:03 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-25 07:05:03 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// image should not be synced
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test periodically sync is disabled when content is not set", func() {
|
|
|
|
var tlsVerify bool
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
PollInterval: updateDuration,
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-25 07:05:03 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-10-25 07:05:03 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-25 07:05:03 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test ondemand sync is disabled when ondemand is false", func() {
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-10-25 07:05:03 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-10-25 07:05:03 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-10-25 07:05:03 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2021-12-07 13:26:26 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
func TestMultipleURLs(t *testing.T) {
|
|
|
|
Convey("Verify sync feature", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
|
|
|
sctlr, srcBaseURL, srcDir, _, srcClient := startUpstreamServer(false, false)
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
URLs: []string{"badURL", "http://invalid.invalid/invalid/", srcBaseURL},
|
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
|
|
|
dc, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
dc.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
var srcTagsList TagsList
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
|
|
|
resp, _ := srcClient.R().Get(srcBaseURL + "/v2/" + testImage + "/tags/list")
|
|
|
|
So(resp, ShouldNotBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
err := json.Unmarshal(resp.Body(), &srcTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/tags/list")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(destTagsList.Tags) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
So(destTagsList, ShouldResemble, srcTagsList)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
func TestPeriodicallySignatures(t *testing.T) {
|
2021-12-07 13:26:26 -05:00
|
|
|
Convey("Verify sync signatures", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-12-07 13:26:26 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-12-07 13:26:26 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// create repo, push and sign it
|
2022-01-10 11:06:12 -05:00
|
|
|
repoName := testSignedImage
|
2021-12-07 13:26:26 -05:00
|
|
|
var digest godigest.Digest
|
|
|
|
So(func() { digest = pushRepo(srcBaseURL, repoName) }, ShouldNotPanic)
|
|
|
|
|
|
|
|
splittedURL := strings.SplitAfter(srcBaseURL, ":")
|
|
|
|
srcPort := splittedURL[len(splittedURL)-1]
|
|
|
|
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
defer func() { _ = os.Chdir(cwd) }()
|
|
|
|
tdir, err := ioutil.TempDir("", "sigs")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
defer os.RemoveAll(tdir)
|
|
|
|
_ = os.Chdir(tdir)
|
2022-01-10 11:06:12 -05:00
|
|
|
generateKeyPairs(tdir)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
So(func() { signImage(tdir, srcPort, repoName, digest) }, ShouldNotPanic)
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
var semver bool
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: repoName,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-12-07 13:26:26 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{
|
|
|
|
Registries: []sync.RegistryConfig{syncRegistryConfig},
|
|
|
|
}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
2021-12-07 13:26:26 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-12-07 13:26:26 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// wait for sync
|
|
|
|
var destTagsList TagsList
|
|
|
|
|
|
|
|
for {
|
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + repoName + "/tags/list")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &destTagsList)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(destTagsList.Tags) > 0 {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
splittedURL = strings.SplitAfter(destBaseURL, ":")
|
|
|
|
destPort := splittedURL[len(splittedURL)-1]
|
|
|
|
|
|
|
|
a := &options.AnnotationOptions{Annotations: []string{"tag=1.0"}}
|
|
|
|
amap, err := a.AnnotationsMap()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
time.Sleep(1 * time.Second)
|
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
// notation verify the image
|
|
|
|
image := fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")
|
|
|
|
cmd := exec.Command("notation", "verify", "--cert", "good", "--plain-http", image)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
msg := string(out)
|
|
|
|
So(msg, ShouldNotBeEmpty)
|
|
|
|
So(strings.Contains(msg, "verification failure"), ShouldBeFalse)
|
|
|
|
|
|
|
|
// cosign verify the image
|
|
|
|
vrfy := verify.VerifyCommand{
|
|
|
|
RegistryOptions: options.RegistryOptions{AllowInsecure: true},
|
|
|
|
CheckClaims: true,
|
|
|
|
KeyRef: path.Join(tdir, "cosign.pub"),
|
|
|
|
Annotations: amap,
|
|
|
|
}
|
|
|
|
err = vrfy.Exec(context.TODO(), []string{fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// test negative cases (trigger errors)
|
|
|
|
// test notary signatures errors
|
|
|
|
|
|
|
|
// based on manifest digest get referrers
|
|
|
|
getReferrersURL := srcBaseURL + path.Join("/oras/artifacts/v1/", repoName, "manifests", digest.String(), "referrers")
|
|
|
|
|
|
|
|
resp, err := resty.R().
|
|
|
|
SetHeader("Content-Type", "application/json").
|
|
|
|
SetQueryParam("artifactType", "application/vnd.cncf.notary.v2.signature").
|
|
|
|
Get(getReferrersURL)
|
|
|
|
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp, ShouldNotBeEmpty)
|
|
|
|
|
|
|
|
var referrers ReferenceList
|
|
|
|
|
|
|
|
err = json.Unmarshal(resp.Body(), &referrers)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// read manifest
|
|
|
|
var nm artifactspec.Manifest
|
|
|
|
for _, ref := range referrers.References {
|
|
|
|
refPath := path.Join(srcDir, repoName, "blobs", string(ref.Digest.Algorithm()), ref.Digest.Hex())
|
|
|
|
body, err := ioutil.ReadFile(refPath)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
err = json.Unmarshal(body, &nm)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// triggers perm denied on sig blobs
|
|
|
|
for _, blob := range nm.Blobs {
|
|
|
|
blobPath := path.Join(srcDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
|
|
|
err := os.Chmod(blobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
// remove already synced image
|
|
|
|
err = os.RemoveAll(path.Join(destDir, repoName))
|
|
|
|
So(err, ShouldBeNil)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
2022-01-07 07:28:45 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
for _, blob := range nm.Blobs {
|
|
|
|
srcBlobPath := path.Join(srcDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
|
|
|
err := os.Chmod(srcBlobPath, 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
destBlobPath := path.Join(destDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
2022-01-10 11:06:12 -05:00
|
|
|
_ = os.Remove(destBlobPath)
|
2021-12-07 13:26:26 -05:00
|
|
|
err = os.MkdirAll(destBlobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
2022-01-07 07:28:45 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
// clean
|
|
|
|
for _, blob := range nm.Blobs {
|
|
|
|
destBlobPath := path.Join(destDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
|
|
|
err = os.Chmod(destBlobPath, 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
err = os.Remove(destBlobPath)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// test cosign signatures errors
|
|
|
|
// based on manifest digest get cosign manifest
|
|
|
|
cosignEncodedDigest := strings.Replace(digest.String(), ":", "-", 1) + ".sig"
|
|
|
|
getCosignManifestURL := srcBaseURL + path.Join("/v2", repoName, "manifests", cosignEncodedDigest)
|
|
|
|
|
|
|
|
mResp, err := resty.R().Get(getCosignManifestURL)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
var cm ispec.Manifest
|
|
|
|
|
|
|
|
err = json.Unmarshal(mResp.Body(), &cm)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
for _, blob := range cm.Layers {
|
|
|
|
blobPath := path.Join(srcDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
|
|
|
err := os.Chmod(blobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
// remove already synced image
|
|
|
|
err = os.RemoveAll(path.Join(destDir, repoName))
|
2022-01-07 07:28:45 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
for _, blob := range cm.Layers {
|
|
|
|
srcBlobPath := path.Join(srcDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
|
|
|
err := os.Chmod(srcBlobPath, 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
destBlobPath := path.Join(destDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
2021-12-29 10:14:56 -05:00
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
err = os.MkdirAll(destBlobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
// remove already synced image
|
|
|
|
err = os.RemoveAll(path.Join(destDir, repoName))
|
2022-01-07 07:28:45 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
for _, blob := range cm.Layers {
|
|
|
|
destBlobPath := path.Join(destDir, repoName, "blobs", string(blob.Digest.Algorithm()), blob.Digest.Hex())
|
|
|
|
err = os.Chmod(destBlobPath, 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
err = os.Remove(destBlobPath)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// trigger error on config blob
|
|
|
|
srcConfigBlobPath := path.Join(srcDir, repoName, "blobs", string(cm.Config.Digest.Algorithm()),
|
|
|
|
cm.Config.Digest.Hex())
|
|
|
|
err = os.Chmod(srcConfigBlobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
// remove already synced image
|
|
|
|
err = os.RemoveAll(path.Join(destDir, repoName))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
2022-01-07 07:28:45 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
err = os.Chmod(srcConfigBlobPath, 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
destConfigBlobPath := path.Join(destDir, repoName, "blobs", string(cm.Config.Digest.Algorithm()),
|
|
|
|
cm.Config.Digest.Hex())
|
2021-12-29 10:14:56 -05:00
|
|
|
// err = os.Remove(destConfigBlobPath)
|
|
|
|
// So(err, ShouldBeNil)
|
2021-12-07 13:26:26 -05:00
|
|
|
err = os.MkdirAll(destConfigBlobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
// remove already synced image
|
|
|
|
err = os.RemoveAll(path.Join(destDir, repoName))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
2022-01-07 07:28:45 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
2021-12-07 13:26:26 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
func TestOnDemandRetryGoroutine(t *testing.T) {
|
|
|
|
Convey("Verify ondemand sync retries in background on error", t, func() {
|
|
|
|
srcPort := test.GetFreePort()
|
|
|
|
srcConfig := config.New()
|
|
|
|
srcBaseURL := test.GetBaseURL(srcPort)
|
|
|
|
|
|
|
|
srcConfig.HTTP.Port = srcPort
|
|
|
|
|
|
|
|
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = test.CopyFiles("../../../test/data", srcDir)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
srcConfig.Storage.RootDirectory = srcDir
|
|
|
|
|
|
|
|
sctlr := api.NewController(srcConfig)
|
|
|
|
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
URLs: []string{srcBaseURL},
|
|
|
|
OnDemand: true,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
maxRetries := 3
|
|
|
|
delay := 2 * time.Second
|
|
|
|
syncRegistryConfig.MaxRetries = &maxRetries
|
|
|
|
syncRegistryConfig.RetryDelay = &delay
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
|
|
|
dc, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
dc.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
resp, err := destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
|
|
|
|
|
|
|
// start upstream server
|
|
|
|
go func() {
|
|
|
|
// this blocks
|
|
|
|
if err := sctlr.Run(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// in the meantime ondemand should retry syncing
|
|
|
|
time.Sleep(15 * time.Second)
|
|
|
|
|
|
|
|
// now we should have the image synced
|
|
|
|
binfo, err := os.Stat(path.Join(destDir, testImage, "index.json"))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(binfo, ShouldNotBeNil)
|
|
|
|
So(binfo.Size(), ShouldNotBeZeroValue)
|
|
|
|
|
|
|
|
resp, err = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOnDemandMultipleRetries(t *testing.T) {
|
|
|
|
Convey("Verify ondemand sync retries in background on error, multiple calls should spawn one routine", t, func() {
|
|
|
|
srcPort := test.GetFreePort()
|
|
|
|
srcConfig := config.New()
|
|
|
|
srcBaseURL := test.GetBaseURL(srcPort)
|
|
|
|
|
|
|
|
srcConfig.HTTP.Port = srcPort
|
|
|
|
|
|
|
|
srcDir, err := ioutil.TempDir("", "oci-src-repo-test")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = test.CopyFiles("../../../test/data", srcDir)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
srcConfig.Storage.RootDirectory = srcDir
|
|
|
|
|
|
|
|
sctlr := api.NewController(srcConfig)
|
|
|
|
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
URLs: []string{srcBaseURL},
|
|
|
|
OnDemand: true,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
maxRetries := 5
|
|
|
|
delay := 5 * time.Second
|
|
|
|
syncRegistryConfig.MaxRetries = &maxRetries
|
|
|
|
syncRegistryConfig.RetryDelay = &delay
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
|
|
|
dc, destBaseURL, destDir, destClient := startDownstreamServer(false, syncConfig)
|
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
dc.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
callsNo := 5
|
|
|
|
for i := 0; i < callsNo; i++ {
|
|
|
|
_, _ = destClient.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
}
|
|
|
|
|
|
|
|
populatedDirs := make(map[string]bool)
|
|
|
|
|
|
|
|
done := make(chan bool)
|
|
|
|
go func() {
|
|
|
|
/* watch .sync local cache, make sure just one .sync/subdir is populated with image
|
|
|
|
the lock from ondemand should prevent spawning multiple go routines for the same image*/
|
|
|
|
for {
|
|
|
|
time.Sleep(250 * time.Millisecond)
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
dirs, err := os.ReadDir(path.Join(destDir, testImage, ".sync"))
|
|
|
|
if err == nil {
|
|
|
|
for _, dir := range dirs {
|
|
|
|
contents, err := os.ReadDir(path.Join(destDir, testImage, ".sync", dir.Name()))
|
|
|
|
if err == nil {
|
|
|
|
if len(contents) > 0 {
|
|
|
|
populatedDirs[dir.Name()] = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// start upstream server
|
|
|
|
go func() {
|
|
|
|
// this blocks
|
|
|
|
if err := sctlr.Run(); err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// wait till ready
|
|
|
|
for {
|
|
|
|
_, err := resty.R().Get(destBaseURL)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// wait sync
|
|
|
|
for {
|
|
|
|
_, err := os.Stat(path.Join(destDir, testImage, "index.json"))
|
|
|
|
if err == nil {
|
|
|
|
// stop watching /.sync/ subdirs
|
|
|
|
done <- true
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
|
|
|
|
waitSyncOndemand(destDir, testImage)
|
|
|
|
|
|
|
|
So(len(populatedDirs), ShouldEqual, 1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOnDemandPullsOnce(t *testing.T) {
|
|
|
|
Convey("Verify sync on demand pulls only one time", t, func(conv C) {
|
|
|
|
sc, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sc.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
URLs: []string{srcBaseURL},
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
|
|
|
dc, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
dc.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
var wg goSync.WaitGroup
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func(conv C) {
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
conv.So(err, ShouldBeNil)
|
|
|
|
conv.So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
wg.Done()
|
|
|
|
}(conv)
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func(conv C) {
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
conv.So(err, ShouldBeNil)
|
|
|
|
conv.So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
wg.Done()
|
|
|
|
}(conv)
|
|
|
|
|
|
|
|
wg.Add(1)
|
|
|
|
go func(conv C) {
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
conv.So(err, ShouldBeNil)
|
|
|
|
conv.So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
wg.Done()
|
|
|
|
}(conv)
|
|
|
|
|
|
|
|
done := make(chan bool)
|
|
|
|
|
|
|
|
var maxLen int
|
|
|
|
syncBlobUploadDir := path.Join(destDir, testImage, sync.SyncBlobUploadDir)
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-done:
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
dirs, err := ioutil.ReadDir(syncBlobUploadDir)
|
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
// check how many .sync/uuid/ dirs are created, if just one then on demand pulled only once
|
|
|
|
if len(dirs) > maxLen {
|
|
|
|
maxLen = len(dirs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
wg.Wait()
|
|
|
|
done <- true
|
|
|
|
|
|
|
|
So(maxLen, ShouldEqual, 1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestError(t *testing.T) {
|
2021-12-07 13:26:26 -05:00
|
|
|
Convey("Verify periodically sync pushSyncedLocalImage() error", t, func() {
|
|
|
|
updateDuration, _ := time.ParseDuration("30m")
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-12-07 13:26:26 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-12-07 13:26:26 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
regex := ".*"
|
|
|
|
semver := true
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
Content: []sync.Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
Tags: &sync.Tags{
|
|
|
|
Regex: ®ex,
|
|
|
|
Semver: &semver,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-12-07 13:26:26 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, client := startDownstreamServer(false, syncConfig)
|
2021-12-07 13:26:26 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-12-07 13:26:26 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// give permission denied on pushSyncedLocalImage()
|
|
|
|
localRepoPath := path.Join(destDir, testImage, "blobs")
|
|
|
|
err := os.MkdirAll(localRepoPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
resp, err := client.R().Get(destBaseURL + "/v2/" + testImage + "/manifests/" + testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 404)
|
2021-12-07 13:26:26 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
func TestSignaturesOnDemand(t *testing.T) {
|
2021-12-07 13:26:26 -05:00
|
|
|
Convey("Verify sync signatures on demand feature", t, func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
2021-12-07 13:26:26 -05:00
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
sctlr.Shutdown()
|
2021-12-07 13:26:26 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// create repo, push and sign it
|
2022-01-10 11:06:12 -05:00
|
|
|
repoName := testSignedImage
|
2021-12-07 13:26:26 -05:00
|
|
|
var digest godigest.Digest
|
|
|
|
So(func() { digest = pushRepo(srcBaseURL, repoName) }, ShouldNotPanic)
|
|
|
|
|
|
|
|
splittedURL := strings.SplitAfter(srcBaseURL, ":")
|
|
|
|
srcPort := splittedURL[len(splittedURL)-1]
|
|
|
|
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
defer func() { _ = os.Chdir(cwd) }()
|
|
|
|
tdir, err := ioutil.TempDir("", "sigs")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
defer os.RemoveAll(tdir)
|
|
|
|
_ = os.Chdir(tdir)
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
generateKeyPairs(tdir)
|
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
So(func() { signImage(tdir, srcPort, repoName, digest) }, ShouldNotPanic)
|
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{srcBaseURL},
|
2021-12-07 13:26:26 -05:00
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncRegistryConfig}}
|
|
|
|
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
2021-12-07 13:26:26 -05:00
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
2022-01-07 07:28:45 -05:00
|
|
|
dctlr.Shutdown()
|
2021-12-07 13:26:26 -05:00
|
|
|
}()
|
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
splittedURL = strings.SplitAfter(destBaseURL, ":")
|
|
|
|
destPort := splittedURL[len(splittedURL)-1]
|
|
|
|
|
|
|
|
a := &options.AnnotationOptions{Annotations: []string{"tag=1.0"}}
|
|
|
|
amap, err := a.AnnotationsMap()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// notation verify the synced image
|
|
|
|
image := fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")
|
|
|
|
cmd := exec.Command("notation", "verify", "--cert", "good", "--plain-http", image)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
msg := string(out)
|
|
|
|
So(msg, ShouldNotBeEmpty)
|
|
|
|
So(strings.Contains(msg, "verification failure"), ShouldBeFalse)
|
|
|
|
|
|
|
|
// cosign verify the synced image
|
|
|
|
vrfy := verify.VerifyCommand{
|
|
|
|
RegistryOptions: options.RegistryOptions{AllowInsecure: true},
|
|
|
|
CheckClaims: true,
|
|
|
|
KeyRef: path.Join(tdir, "cosign.pub"),
|
|
|
|
Annotations: amap,
|
|
|
|
}
|
|
|
|
err = vrfy.Exec(context.TODO(), []string{fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// test negative case
|
|
|
|
cosignEncodedDigest := strings.Replace(digest.String(), ":", "-", 1) + ".sig"
|
|
|
|
getCosignManifestURL := srcBaseURL + path.Join("/v2", repoName, "manifests", cosignEncodedDigest)
|
|
|
|
|
|
|
|
mResp, err := resty.R().Get(getCosignManifestURL)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
var cm ispec.Manifest
|
|
|
|
|
|
|
|
err = json.Unmarshal(mResp.Body(), &cm)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
// trigger errors on cosign blobs
|
|
|
|
// trigger error on cosign config blob
|
2021-12-07 13:26:26 -05:00
|
|
|
srcConfigBlobPath := path.Join(srcDir, repoName, "blobs", string(cm.Config.Digest.Algorithm()),
|
|
|
|
cm.Config.Digest.Hex())
|
|
|
|
err = os.Chmod(srcConfigBlobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// remove already synced image
|
|
|
|
err = os.RemoveAll(path.Join(destDir, repoName))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
// trigger error on cosign layer blob
|
|
|
|
srcSignatureBlobPath := path.Join(srcDir, repoName, "blobs", string(cm.Layers[0].Digest.Algorithm()),
|
|
|
|
cm.Layers[0].Digest.Hex())
|
|
|
|
|
|
|
|
err = os.Chmod(srcConfigBlobPath, 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
err = os.Chmod(srcSignatureBlobPath, 0o000)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// remove already synced image
|
|
|
|
err = os.RemoveAll(path.Join(destDir, repoName))
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err = resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
err = os.Chmod(srcSignatureBlobPath, 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
2021-12-07 13:26:26 -05:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
func TestOnlySignaturesOnDemand(t *testing.T) {
|
|
|
|
Convey("Verify sync signatures on demand feature when we already have the image", t, func() {
|
|
|
|
sctlr, srcBaseURL, srcDir, _, _ := startUpstreamServer(false, false)
|
|
|
|
defer os.RemoveAll(srcDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
sctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// create repo, push and sign it
|
|
|
|
repoName := testSignedImage
|
|
|
|
var digest godigest.Digest
|
|
|
|
So(func() { digest = pushRepo(srcBaseURL, repoName) }, ShouldNotPanic)
|
|
|
|
|
|
|
|
splittedURL := strings.SplitAfter(srcBaseURL, ":")
|
|
|
|
srcPort := splittedURL[len(splittedURL)-1]
|
|
|
|
|
|
|
|
cwd, err := os.Getwd()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
defer func() { _ = os.Chdir(cwd) }()
|
|
|
|
tdir, err := ioutil.TempDir("", "sigs")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
defer os.RemoveAll(tdir)
|
|
|
|
_ = os.Chdir(tdir)
|
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
|
|
|
|
syncRegistryConfig := sync.RegistryConfig{
|
|
|
|
URLs: []string{srcBaseURL},
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncBadRegistryConfig := sync.RegistryConfig{
|
|
|
|
URLs: []string{"http://invalid.invalid:9999"},
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
OnDemand: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
syncConfig := &sync.Config{Registries: []sync.RegistryConfig{syncBadRegistryConfig, syncRegistryConfig}}
|
|
|
|
|
|
|
|
dctlr, destBaseURL, destDir, _ := startDownstreamServer(false, syncConfig)
|
|
|
|
defer os.RemoveAll(destDir)
|
|
|
|
|
|
|
|
defer func() {
|
|
|
|
dctlr.Shutdown()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// sync on demand
|
|
|
|
resp, err := resty.R().Get(destBaseURL + "/v2/" + repoName + "/manifests/1.0")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(resp.StatusCode(), ShouldEqual, 200)
|
|
|
|
|
|
|
|
splittedURL = strings.SplitAfter(destBaseURL, ":")
|
|
|
|
destPort := splittedURL[len(splittedURL)-1]
|
|
|
|
|
|
|
|
a := &options.AnnotationOptions{Annotations: []string{"tag=1.0"}}
|
|
|
|
amap, err := a.AnnotationsMap()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
generateKeyPairs(tdir)
|
|
|
|
|
|
|
|
// sync signature on demand when upstream doesn't have the signature
|
|
|
|
image := fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")
|
|
|
|
cmd := exec.Command("notation", "verify", "--cert", "good", "--plain-http", image)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
msg := string(out)
|
|
|
|
So(msg, ShouldNotBeEmpty)
|
|
|
|
So(strings.Contains(msg, "signature failure"), ShouldBeTrue)
|
|
|
|
|
|
|
|
// cosign verify the synced image
|
|
|
|
vrfy := verify.VerifyCommand{
|
|
|
|
RegistryOptions: options.RegistryOptions{AllowInsecure: true},
|
|
|
|
CheckClaims: true,
|
|
|
|
KeyRef: path.Join(tdir, "cosign.pub"),
|
|
|
|
Annotations: amap,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = vrfy.Exec(context.TODO(), []string{fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")})
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
// sign upstream image
|
|
|
|
So(func() { signImage(tdir, srcPort, repoName, digest) }, ShouldNotPanic)
|
|
|
|
|
|
|
|
// now it should sync signatures on demand, even if we already have the image
|
|
|
|
image = fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")
|
|
|
|
cmd = exec.Command("notation", "verify", "--cert", "good", "--plain-http", image)
|
|
|
|
out, err = cmd.CombinedOutput()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
msg = string(out)
|
|
|
|
So(msg, ShouldNotBeEmpty)
|
|
|
|
So(strings.Contains(msg, "verification failure"), ShouldBeFalse)
|
|
|
|
|
|
|
|
// cosign verify the synced image
|
|
|
|
vrfy = verify.VerifyCommand{
|
|
|
|
RegistryOptions: options.RegistryOptions{AllowInsecure: true},
|
|
|
|
CheckClaims: true,
|
|
|
|
KeyRef: path.Join(tdir, "cosign.pub"),
|
|
|
|
Annotations: amap,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = vrfy.Exec(context.TODO(), []string{fmt.Sprintf("localhost:%s/%s:%s", destPort, repoName, "1.0")})
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func generateKeyPairs(tdir string) {
|
2021-12-07 13:26:26 -05:00
|
|
|
// generate a keypair
|
|
|
|
os.Setenv("COSIGN_PASSWORD", "")
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
if _, err := os.Stat(path.Join(tdir, "cosign.key")); err != nil {
|
|
|
|
err := generate.GenerateKeyPairCmd(context.TODO(), "", nil)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// "notation" (notaryv2) doesn't yet support exported apis, so use the binary instead
|
|
|
|
_, err := exec.LookPath("notation")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
os.Setenv("XDG_CONFIG_HOME", tdir)
|
|
|
|
|
|
|
|
// generate a keypair
|
|
|
|
cmd := exec.Command("notation", "cert", "generate-test", "--trust", "good")
|
|
|
|
|
|
|
|
err = cmd.Run()
|
2021-12-07 13:26:26 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2022-01-10 11:06:12 -05:00
|
|
|
}
|
2021-12-07 13:26:26 -05:00
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
func signImage(tdir, port, repoName string, digest godigest.Digest) {
|
|
|
|
// push signatures to upstream server so that we can sync them later
|
2021-12-07 13:26:26 -05:00
|
|
|
// sign the image
|
2022-01-10 11:06:12 -05:00
|
|
|
err := sign.SignCmd(context.TODO(),
|
2021-12-07 13:26:26 -05:00
|
|
|
sign.KeyOpts{KeyRef: path.Join(tdir, "cosign.key"), PassFunc: generate.GetPass},
|
|
|
|
options.RegistryOptions{AllowInsecure: true},
|
|
|
|
map[string]interface{}{"tag": "1.0"},
|
|
|
|
[]string{fmt.Sprintf("localhost:%s/%s@%s", port, repoName, digest.String())},
|
|
|
|
"", true, "", false, false, "")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify the image
|
|
|
|
a := &options.AnnotationOptions{Annotations: []string{"tag=1.0"}}
|
|
|
|
|
|
|
|
amap, err := a.AnnotationsMap()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
vrfy := verify.VerifyCommand{
|
|
|
|
RegistryOptions: options.RegistryOptions{AllowInsecure: true},
|
|
|
|
CheckClaims: true,
|
|
|
|
KeyRef: path.Join(tdir, "cosign.pub"),
|
|
|
|
Annotations: amap,
|
|
|
|
}
|
|
|
|
|
|
|
|
err = vrfy.Exec(context.TODO(), []string{fmt.Sprintf("localhost:%s/%s:%s", port, repoName, "1.0")})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// sign the image
|
|
|
|
image := fmt.Sprintf("localhost:%s/%s:%s", port, repoName, "1.0")
|
2022-01-10 11:06:12 -05:00
|
|
|
cmd := exec.Command("notation", "sign", "--key", "good", "--plain-http", image)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
err = cmd.Run()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify the image
|
|
|
|
cmd = exec.Command("notation", "verify", "--cert", "good", "--plain-http", image)
|
|
|
|
out, err := cmd.CombinedOutput()
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
msg := string(out)
|
|
|
|
So(msg, ShouldNotBeEmpty)
|
|
|
|
So(strings.Contains(msg, "verification failure"), ShouldBeFalse)
|
|
|
|
}
|
|
|
|
|
|
|
|
func pushRepo(url, repoName string) godigest.Digest {
|
|
|
|
// create a blob/layer
|
|
|
|
resp, err := resty.R().Post(url + fmt.Sprintf("/v2/%s/blobs/uploads/", repoName))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
loc := test.Location(url, resp)
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
_, err = resty.R().Get(loc)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
content := []byte("this is a blob")
|
|
|
|
digest := godigest.FromBytes(content)
|
|
|
|
|
|
|
|
_, err = resty.R().SetQueryParam("digest", digest.String()).
|
|
|
|
SetHeader("Content-Type", "application/octet-stream").SetBody(content).Put(loc)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
// upload image config blob
|
|
|
|
resp, err = resty.R().
|
|
|
|
Post(fmt.Sprintf("%s/v2/%s/blobs/uploads/", url, repoName))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode() != http.StatusAccepted {
|
|
|
|
panic(perr.Wrapf(errBadStatus, "invalid status code: %d", resp.StatusCode()))
|
|
|
|
}
|
|
|
|
|
|
|
|
loc = test.Location(url, resp)
|
|
|
|
cblob, cdigest := test.GetRandomImageConfig()
|
|
|
|
|
|
|
|
resp, err = resty.R().
|
|
|
|
SetContentLength(true).
|
|
|
|
SetHeader("Content-Length", fmt.Sprintf("%d", len(cblob))).
|
|
|
|
SetHeader("Content-Type", "application/octet-stream").
|
|
|
|
SetQueryParam("digest", cdigest.String()).
|
|
|
|
SetBody(cblob).
|
|
|
|
Put(loc)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode() != http.StatusCreated {
|
|
|
|
panic(perr.Wrapf(errBadStatus, "invalid status code: %d", resp.StatusCode()))
|
|
|
|
}
|
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
// create a manifest
|
|
|
|
manifest := ispec.Manifest{
|
|
|
|
Config: ispec.Descriptor{
|
2022-01-19 14:54:17 -05:00
|
|
|
MediaType: "application/vnd.oci.image.config.v1+json",
|
|
|
|
Digest: cdigest,
|
|
|
|
Size: int64(len(cblob)),
|
2021-12-07 13:26:26 -05:00
|
|
|
},
|
|
|
|
Layers: []ispec.Descriptor{
|
|
|
|
{
|
|
|
|
MediaType: "application/vnd.oci.image.layer.v1.tar",
|
|
|
|
Digest: digest,
|
|
|
|
Size: int64(len(content)),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest.SchemaVersion = 2
|
|
|
|
|
|
|
|
content, err = json.Marshal(manifest)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
digest = godigest.FromBytes(content)
|
|
|
|
|
|
|
|
_, err = resty.R().SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
|
|
|
|
SetBody(content).Put(url + fmt.Sprintf("/v2/%s/manifests/1.0", repoName))
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return digest
|
|
|
|
}
|
2022-01-10 11:06:12 -05:00
|
|
|
|
|
|
|
func waitSyncOndemand(rootDir, repoName string) {
|
|
|
|
// wait for .sync subdirs to be removed
|
|
|
|
for {
|
|
|
|
dirs, err := os.ReadDir(path.Join(rootDir, repoName, sync.SyncBlobUploadDir))
|
|
|
|
if err == nil && len(dirs) == 0 {
|
|
|
|
// stop watching /.sync/ subdirs
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|