2021-06-08 15:11:18 -05:00
|
|
|
package sync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-10-28 04:10:01 -05:00
|
|
|
"encoding/json"
|
2021-06-08 15:11:18 -05:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2021-12-07 13:26:26 -05:00
|
|
|
"net/url"
|
2021-10-28 04:10:01 -05:00
|
|
|
"os"
|
|
|
|
"path"
|
2021-12-02 12:45:26 -05:00
|
|
|
goSync "sync"
|
2021-06-08 15:11:18 -05:00
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/containers/image/v5/docker"
|
|
|
|
"github.com/containers/image/v5/docker/reference"
|
|
|
|
"github.com/containers/image/v5/types"
|
2021-10-28 04:10:01 -05:00
|
|
|
godigest "github.com/opencontainers/go-digest"
|
|
|
|
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
|
|
|
"github.com/rs/zerolog"
|
2021-06-08 15:11:18 -05:00
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2021-12-07 13:26:26 -05:00
|
|
|
"gopkg.in/resty.v1"
|
2021-12-03 22:50:58 -05:00
|
|
|
"zotregistry.io/zot/errors"
|
|
|
|
"zotregistry.io/zot/pkg/extensions/monitoring"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
|
|
"zotregistry.io/zot/pkg/storage"
|
2021-12-17 11:34:22 -05:00
|
|
|
"zotregistry.io/zot/pkg/test"
|
2021-06-08 15:11:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
testImage = "zot-test"
|
|
|
|
testImageTag = "0.0.1"
|
|
|
|
|
|
|
|
host = "127.0.0.1:45117"
|
|
|
|
)
|
|
|
|
|
2022-02-18 06:36:50 -05:00
|
|
|
func TestInjectSyncUtils(t *testing.T) {
|
|
|
|
Convey("Inject errors in utils functions", t, func() {
|
|
|
|
repositoryReference := fmt.Sprintf("%s/%s", host, testImage)
|
|
|
|
ref, err := parseRepositoryReference(repositoryReference)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(ref.Name(), ShouldEqual, repositoryReference)
|
|
|
|
|
|
|
|
taggedRef, err := reference.WithTag(ref, "tag")
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
injected := test.InjectFailure(0)
|
|
|
|
if injected {
|
|
|
|
_, err = getImageTags(context.Background(), &types.SystemContext{}, taggedRef)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
injected = test.InjectFailure(0)
|
|
|
|
_, _, err = getLocalContexts(log.NewLogger("debug", ""))
|
|
|
|
if injected {
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
} else {
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
|
|
|
|
2022-03-07 03:55:12 -05:00
|
|
|
imageStore := storage.NewImageStore(t.TempDir(), false, storage.DefaultGCDelay, false, false, log, metrics)
|
2022-02-18 06:36:50 -05:00
|
|
|
|
|
|
|
injected = test.InjectFailure(0)
|
|
|
|
_, _, err = getLocalImageRef(imageStore, testImage, testImageTag)
|
|
|
|
if injected {
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
} else {
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-06-08 15:11:18 -05:00
|
|
|
func TestSyncInternal(t *testing.T) {
|
2021-10-28 04:10:01 -05:00
|
|
|
Convey("Verify parseRepositoryReference func", t, func() {
|
2021-06-08 15:11:18 -05:00
|
|
|
repositoryReference := fmt.Sprintf("%s/%s", host, testImage)
|
|
|
|
ref, err := parseRepositoryReference(repositoryReference)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(ref.Name(), ShouldEqual, repositoryReference)
|
|
|
|
|
|
|
|
repositoryReference = fmt.Sprintf("%s/%s:tagged", host, testImage)
|
|
|
|
_, err = parseRepositoryReference(repositoryReference)
|
|
|
|
So(err, ShouldEqual, errors.ErrInvalidRepositoryName)
|
|
|
|
|
|
|
|
repositoryReference = fmt.Sprintf("http://%s/%s", host, testImage)
|
|
|
|
_, err = parseRepositoryReference(repositoryReference)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
repositoryReference = fmt.Sprintf("docker://%s/%s", host, testImage)
|
|
|
|
_, err = parseRepositoryReference(repositoryReference)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
_, err = getFileCredentials("/path/to/inexistent/file")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
tempFile, err := ioutil.TempFile("", "sync-credentials-")
|
2021-06-08 15:11:18 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
content := []byte(`{`)
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := ioutil.WriteFile(tempFile.Name(), content, 0o600); err != nil {
|
2021-06-08 15:11:18 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = getFileCredentials(tempFile.Name())
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
srcCtx := &types.SystemContext{}
|
|
|
|
_, err = getImageTags(context.Background(), srcCtx, ref)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
taggedRef, err := reference.WithTag(ref, "tag")
|
|
|
|
So(err, ShouldBeNil)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
_, err = getImageTags(context.Background(), &types.SystemContext{}, taggedRef)
|
2021-06-08 15:11:18 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
dockerRef, err := docker.NewReference(taggedRef)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
So(getTagFromRef(dockerRef, log.NewLogger("debug", "")), ShouldNotBeNil)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
updateDuration := time.Microsecond
|
2021-12-17 11:34:22 -05:00
|
|
|
port := test.GetFreePort()
|
|
|
|
baseURL := test.GetBaseURL(port)
|
2021-06-08 15:11:18 -05:00
|
|
|
syncRegistryConfig := RegistryConfig{
|
|
|
|
Content: []Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{baseURL},
|
2021-06-08 15:11:18 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "",
|
|
|
|
}
|
|
|
|
|
|
|
|
cfg := Config{Registries: []RegistryConfig{syncRegistryConfig}, CredentialsFile: "/invalid/path/to/file"}
|
|
|
|
|
2021-12-02 12:45:26 -05:00
|
|
|
So(Run(cfg, storage.StoreController{}, new(goSync.WaitGroup), log.NewLogger("debug", "")), ShouldNotBeNil)
|
2021-06-08 15:11:18 -05:00
|
|
|
|
|
|
|
_, err = getFileCredentials("/invalid/path/to/file")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-02-18 06:36:50 -05:00
|
|
|
Convey("Verify getLocalImageRef()", t, func() {
|
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
|
|
|
|
2022-03-07 03:55:12 -05:00
|
|
|
imageStore := storage.NewImageStore(t.TempDir(), false, storage.DefaultGCDelay, false, false, log, metrics)
|
2022-02-18 06:36:50 -05:00
|
|
|
|
2022-03-07 03:55:12 -05:00
|
|
|
err := os.Chmod(imageStore.RootDir(), 0o000)
|
2022-02-18 06:36:50 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
_, _, err = getLocalImageRef(imageStore, testImage, testImageTag)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
err = os.Chmod(imageStore.RootDir(), 0o755)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
_, _, err = getLocalImageRef(imageStore, "zot][]321", "tag_tag][]")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
Convey("Test getUpstreamCatalog() with missing certs", t, func() {
|
|
|
|
var tlsVerify bool
|
|
|
|
updateDuration := time.Microsecond
|
|
|
|
syncRegistryConfig := RegistryConfig{
|
|
|
|
Content: []Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
},
|
|
|
|
},
|
2021-12-17 11:34:22 -05:00
|
|
|
URLs: []string{test.BaseURL},
|
2021-10-28 04:10:01 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: "/tmp/missing_certs/a/b/c/d/z",
|
|
|
|
}
|
|
|
|
|
2021-12-17 11:34:22 -05:00
|
|
|
port := test.GetFreePort()
|
|
|
|
baseURL := test.GetBaseURL(port)
|
2021-12-29 10:14:56 -05:00
|
|
|
|
|
|
|
httpClient, err := getHTTPClient(&syncRegistryConfig, baseURL, Credentials{}, log.NewLogger("debug", ""))
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(httpClient, ShouldBeNil)
|
|
|
|
// _, err = getUpstreamCatalog(httpClient, baseURL, log.NewLogger("debug", ""))
|
|
|
|
// So(err, ShouldNotBeNil)
|
2021-10-28 04:10:01 -05:00
|
|
|
})
|
|
|
|
|
2021-12-07 13:26:26 -05:00
|
|
|
Convey("Test getHttpClient() with bad certs", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
badCertsDir := t.TempDir()
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := os.WriteFile(path.Join(badCertsDir, "ca.crt"), []byte("certificate"), 0o600); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var tlsVerify bool
|
|
|
|
updateDuration := time.Microsecond
|
2021-12-17 11:34:22 -05:00
|
|
|
port := test.GetFreePort()
|
|
|
|
baseURL := test.GetBaseURL(port)
|
|
|
|
baseSecureURL := test.GetSecureBaseURL(port)
|
2022-01-27 07:45:46 -05:00
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
syncRegistryConfig := RegistryConfig{
|
|
|
|
Content: []Content{
|
|
|
|
{
|
|
|
|
Prefix: testImage,
|
|
|
|
},
|
|
|
|
},
|
2021-12-29 10:14:56 -05:00
|
|
|
URLs: []string{baseURL, "invalidUrl]"},
|
2021-10-28 04:10:01 -05:00
|
|
|
PollInterval: updateDuration,
|
|
|
|
TLSVerify: &tlsVerify,
|
|
|
|
CertDir: badCertsDir,
|
|
|
|
}
|
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
httpClient, err := getHTTPClient(&syncRegistryConfig, baseURL, Credentials{}, log.NewLogger("debug", ""))
|
2021-12-07 13:26:26 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(httpClient, ShouldBeNil)
|
2022-01-27 07:45:46 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
syncRegistryConfig.CertDir = "/path/to/invalid/cert"
|
|
|
|
httpClient, err = getHTTPClient(&syncRegistryConfig, baseURL, Credentials{}, log.NewLogger("debug", ""))
|
2022-01-27 07:45:46 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(httpClient, ShouldBeNil)
|
2022-01-27 07:45:46 -05:00
|
|
|
|
|
|
|
syncRegistryConfig.CertDir = ""
|
2021-12-29 10:14:56 -05:00
|
|
|
syncRegistryConfig.URLs = []string{baseSecureURL}
|
2022-01-27 07:45:46 -05:00
|
|
|
|
2021-12-29 10:14:56 -05:00
|
|
|
httpClient, err = getHTTPClient(&syncRegistryConfig, baseSecureURL, Credentials{}, log.NewLogger("debug", ""))
|
2022-01-27 07:45:46 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-29 10:14:56 -05:00
|
|
|
So(httpClient, ShouldNotBeNil)
|
|
|
|
|
|
|
|
_, err = getUpstreamCatalog(httpClient, baseURL, log.NewLogger("debug", ""))
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
_, err = getUpstreamCatalog(httpClient, "http://invalid:5000", log.NewLogger("debug", ""))
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-17 11:34:22 -05:00
|
|
|
syncRegistryConfig.URLs = []string{test.BaseURL}
|
2021-12-29 10:14:56 -05:00
|
|
|
httpClient, err = getHTTPClient(&syncRegistryConfig, baseSecureURL, Credentials{}, log.NewLogger("debug", ""))
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(httpClient, ShouldBeNil)
|
2021-10-28 04:10:01 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Test imagesToCopyFromUpstream()", t, func() {
|
|
|
|
repos := []string{"repo1"}
|
|
|
|
upstreamCtx := &types.SystemContext{}
|
|
|
|
|
|
|
|
_, err := imagesToCopyFromUpstream("localhost:4566", repos, upstreamCtx, Content{}, log.NewLogger("debug", ""))
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
_, err = imagesToCopyFromUpstream("docker://localhost:4566", repos, upstreamCtx,
|
|
|
|
Content{}, log.NewLogger("debug", ""))
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
// Convey("Test OneImage() skips cosign signatures", t, func() {
|
|
|
|
// err := OneImage(Config{}, storage.StoreController{}, "repo", "sha256-.sig", log.NewLogger("", ""))
|
|
|
|
// So(err, ShouldBeNil)
|
|
|
|
// })
|
2021-12-07 13:26:26 -05:00
|
|
|
|
|
|
|
Convey("Test syncSignatures()", t, func() {
|
2022-01-10 11:06:12 -05:00
|
|
|
log := log.NewLogger("debug", "")
|
2021-12-07 13:26:26 -05:00
|
|
|
err := syncSignatures(resty.New(), storage.StoreController{}, "%", "repo", "tag", log)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
err = syncSignatures(resty.New(), storage.StoreController{}, "http://zot", "repo", "tag", log)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
err = syncSignatures(resty.New(), storage.StoreController{}, "https://google.com", "repo", "tag", log)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
url, _ := url.Parse("invalid")
|
|
|
|
err = syncCosignSignature(resty.New(), storage.StoreController{}, *url, "repo", "tag", log)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
err = syncNotarySignature(resty.New(), storage.StoreController{}, *url, "repo", "tag", log)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2021-12-17 11:34:22 -05:00
|
|
|
Convey("Test canSkipImage()", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
storageDir := t.TempDir()
|
2021-12-17 11:34:22 -05:00
|
|
|
|
2022-03-07 03:55:12 -05:00
|
|
|
err := test.CopyFiles("../../../test/data", storageDir)
|
2021-12-17 11:34:22 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
|
|
|
|
2022-02-09 19:51:35 -05:00
|
|
|
imageStore := storage.NewImageStore(storageDir, false, storage.DefaultGCDelay, false, false, log, metrics)
|
2021-12-17 11:34:22 -05:00
|
|
|
|
|
|
|
repoRefStr := fmt.Sprintf("%s/%s", host, testImage)
|
|
|
|
repoRef, err := parseRepositoryReference(repoRefStr)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(repoRef, ShouldNotBeNil)
|
|
|
|
|
|
|
|
taggedRef, err := reference.WithTag(repoRef, testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(taggedRef, ShouldNotBeNil)
|
|
|
|
|
|
|
|
upstreamRef, err := docker.NewReference(taggedRef)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(taggedRef, ShouldNotBeNil)
|
|
|
|
|
|
|
|
canBeSkipped, err := canSkipImage(testImage, testImageTag, upstreamRef, imageStore, &types.SystemContext{}, log)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(canBeSkipped, ShouldBeFalse)
|
|
|
|
|
|
|
|
err = os.Chmod(path.Join(imageStore.RootDir(), testImage, "index.json"), 0o000)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
canBeSkipped, err = canSkipImage(testImage, testImageTag, upstreamRef, imageStore, &types.SystemContext{}, log)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(canBeSkipped, ShouldBeFalse)
|
|
|
|
})
|
|
|
|
|
2021-11-25 07:04:39 -05:00
|
|
|
Convey("Test filterRepos()", t, func() {
|
|
|
|
repos := []string{"repo", "repo1", "repo2", "repo/repo2", "repo/repo2/repo3/repo4"}
|
|
|
|
contents := []Content{
|
|
|
|
{
|
|
|
|
Prefix: "repo",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Prefix: "/repo/**",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
Prefix: "repo*",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
filteredRepos := filterRepos(repos, contents, log.NewLogger("", ""))
|
|
|
|
So(filteredRepos[0], ShouldResemble, []string{"repo"})
|
|
|
|
So(filteredRepos[1], ShouldResemble, []string{"repo/repo2", "repo/repo2/repo3/repo4"})
|
|
|
|
So(filteredRepos[2], ShouldResemble, []string{"repo1", "repo2"})
|
|
|
|
|
|
|
|
contents = []Content{
|
|
|
|
{
|
|
|
|
Prefix: "[repo%#@",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
filteredRepos = filterRepos(repos, contents, log.NewLogger("", ""))
|
|
|
|
So(len(filteredRepos), ShouldEqual, 0)
|
|
|
|
})
|
|
|
|
|
2021-10-28 04:10:01 -05:00
|
|
|
Convey("Verify pushSyncedLocalImage func", t, func() {
|
2022-03-07 03:55:12 -05:00
|
|
|
storageDir := t.TempDir()
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
|
|
|
|
2022-02-09 19:51:35 -05:00
|
|
|
imageStore := storage.NewImageStore(storageDir, false, storage.DefaultGCDelay, false, false, log, metrics)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
|
|
|
storeController := storage.StoreController{}
|
|
|
|
storeController.DefaultStore = imageStore
|
|
|
|
|
|
|
|
testRootDir := path.Join(imageStore.RootDir(), testImage, SyncBlobUploadDir)
|
2021-12-13 14:23:31 -05:00
|
|
|
// testImagePath := path.Join(testRootDir, testImage)
|
2021-10-28 04:10:01 -05:00
|
|
|
|
2022-03-07 03:55:12 -05:00
|
|
|
err := pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
2022-01-10 11:06:12 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.MkdirAll(testRootDir, 0o755)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-17 11:34:22 -05:00
|
|
|
err = test.CopyFiles("../../../test/data", testRootDir)
|
2021-10-28 04:10:01 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-02-09 19:51:35 -05:00
|
|
|
testImageStore := storage.NewImageStore(testRootDir, false, storage.DefaultGCDelay, false, false, log, metrics)
|
2021-10-28 04:10:01 -05:00
|
|
|
manifestContent, _, _, err := testImageStore.GetImageManifest(testImage, testImageTag)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
var manifest ispec.Manifest
|
|
|
|
|
|
|
|
if err := json.Unmarshal(manifestContent, &manifest); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := os.Chmod(storageDir, 0o000); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if os.Geteuid() != 0 {
|
|
|
|
So(func() {
|
2022-01-10 11:06:12 -05:00
|
|
|
_ = pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
|
|
|
}, ShouldPanic)
|
2021-10-28 04:10:01 -05:00
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := os.Chmod(storageDir, 0o755); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.Chmod(path.Join(testRootDir, testImage, "blobs", "sha256",
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest.Layers[0].Digest.Hex()), 0o000); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
err = pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
if err := os.Chmod(path.Join(testRootDir, testImage, "blobs", "sha256",
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest.Layers[0].Digest.Hex()), 0o755); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
cachedManifestConfigPath := path.Join(imageStore.RootDir(), testImage, SyncBlobUploadDir,
|
|
|
|
testImage, "blobs", "sha256", manifest.Config.Digest.Hex())
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := os.Chmod(cachedManifestConfigPath, 0o000); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
err = pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := os.Chmod(cachedManifestConfigPath, 0o755); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
manifestConfigPath := path.Join(imageStore.RootDir(), testImage, "blobs", "sha256", manifest.Config.Digest.Hex())
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := os.MkdirAll(manifestConfigPath, 0o000); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
err = pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
|
|
|
if err := os.Remove(manifestConfigPath); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
mDigest := godigest.FromBytes(manifestContent)
|
|
|
|
|
|
|
|
manifestPath := path.Join(imageStore.RootDir(), testImage, "blobs", mDigest.Algorithm().String(), mDigest.Encoded())
|
2021-12-13 14:23:31 -05:00
|
|
|
if err := os.MkdirAll(manifestPath, 0o000); err != nil {
|
2021-10-28 04:10:01 -05:00
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
2022-01-10 11:06:12 -05:00
|
|
|
err = pushSyncedLocalImage(testImage, testImageTag, testRootDir, storeController, log)
|
2021-10-28 04:10:01 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2021-06-08 15:11:18 -05:00
|
|
|
}
|