2019-06-20 18:36:40 -05:00
|
|
|
package storage_test
|
|
|
|
|
|
|
|
import (
|
2019-09-17 17:45:28 -05:00
|
|
|
"bytes"
|
2021-07-16 22:53:05 -05:00
|
|
|
"context"
|
2019-09-17 17:45:28 -05:00
|
|
|
_ "crypto/sha256"
|
|
|
|
"encoding/json"
|
2022-06-24 08:08:47 -05:00
|
|
|
"errors"
|
2021-07-16 22:53:05 -05:00
|
|
|
"fmt"
|
2019-06-20 18:36:40 -05:00
|
|
|
"os"
|
2020-02-17 16:57:15 -05:00
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
"sync"
|
2019-06-20 18:36:40 -05:00
|
|
|
"testing"
|
2021-12-21 08:19:40 -05:00
|
|
|
"time"
|
2019-06-20 18:36:40 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
// Add s3 support.
|
|
|
|
"github.com/docker/distribution/registry/storage/driver"
|
|
|
|
"github.com/docker/distribution/registry/storage/driver/factory"
|
|
|
|
_ "github.com/docker/distribution/registry/storage/driver/s3-aws"
|
2021-07-16 22:53:05 -05:00
|
|
|
guuid "github.com/gofrs/uuid"
|
2019-09-17 17:45:28 -05:00
|
|
|
godigest "github.com/opencontainers/go-digest"
|
|
|
|
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
2019-06-20 18:36:40 -05:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
. "github.com/smartystreets/goconvey/convey"
|
2021-07-16 22:53:05 -05:00
|
|
|
"gopkg.in/resty.v1"
|
2021-12-03 22:50:58 -05:00
|
|
|
"zotregistry.io/zot/pkg/extensions/monitoring"
|
|
|
|
"zotregistry.io/zot/pkg/log"
|
|
|
|
"zotregistry.io/zot/pkg/storage"
|
|
|
|
"zotregistry.io/zot/pkg/storage/s3"
|
2022-01-19 14:54:17 -05:00
|
|
|
"zotregistry.io/zot/pkg/test"
|
2022-06-24 08:08:47 -05:00
|
|
|
"zotregistry.io/zot/pkg/test/mocks"
|
2019-06-20 18:36:40 -05:00
|
|
|
)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
func cleanupStorage(store driver.StorageDriver, name string) {
|
2021-07-16 22:53:05 -05:00
|
|
|
_ = store.Delete(context.Background(), name)
|
|
|
|
}
|
|
|
|
|
|
|
|
func skipIt(t *testing.T) {
|
2021-12-13 14:23:31 -05:00
|
|
|
t.Helper()
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
if os.Getenv("S3MOCK_ENDPOINT") == "" {
|
|
|
|
t.Skip("Skipping testing without AWS S3 mock server")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-12 05:01:04 -05:00
|
|
|
func createObjectsStore(rootDir string, cacheDir string) (driver.StorageDriver, storage.ImageStore, error) {
|
2021-07-16 22:53:05 -05:00
|
|
|
bucket := "zot-storage-test"
|
|
|
|
endpoint := os.Getenv("S3MOCK_ENDPOINT")
|
|
|
|
storageDriverParams := map[string]interface{}{
|
|
|
|
"rootDir": rootDir,
|
|
|
|
"name": "s3",
|
|
|
|
"region": "us-east-2",
|
|
|
|
"bucket": bucket,
|
|
|
|
"regionendpoint": endpoint,
|
2022-04-12 05:01:04 -05:00
|
|
|
"accesskey": "minioadmin",
|
|
|
|
"secretkey": "minioadmin",
|
2021-07-16 22:53:05 -05:00
|
|
|
"secure": false,
|
|
|
|
"skipverify": false,
|
|
|
|
}
|
|
|
|
|
|
|
|
storeName := fmt.Sprintf("%v", storageDriverParams["name"])
|
|
|
|
|
|
|
|
store, err := factory.Create(storeName, storageDriverParams)
|
2019-06-20 18:36:40 -05:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-12-13 00:53:18 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// create bucket if it doesn't exists
|
|
|
|
_, err = resty.R().Put("http://" + endpoint + "/" + bucket)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2019-06-20 18:36:40 -05:00
|
|
|
|
2021-10-15 10:05:00 -05:00
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2022-06-24 08:08:47 -05:00
|
|
|
il := s3.NewImageStore(rootDir, cacheDir, false, storage.DefaultGCDelay,
|
|
|
|
true, false, log, metrics, nil, store,
|
|
|
|
)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
return store, il, err
|
|
|
|
}
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// nolint: gochecknoglobals
|
|
|
|
var testCases = []struct {
|
|
|
|
testCaseName string
|
|
|
|
storageType string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
testCaseName: "S3APIs",
|
|
|
|
storageType: "s3",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
testCaseName: "FileSystemAPIs",
|
|
|
|
storageType: "fs",
|
|
|
|
},
|
|
|
|
}
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
func TestStorageAPIs(t *testing.T) {
|
|
|
|
for _, testcase := range testCases {
|
|
|
|
testcase := testcase
|
|
|
|
t.Run(testcase.testCaseName, func(t *testing.T) {
|
2021-12-13 14:23:31 -05:00
|
|
|
var imgStore storage.ImageStore
|
2021-07-16 22:53:05 -05:00
|
|
|
if testcase.storageType == "s3" {
|
|
|
|
skipIt(t)
|
|
|
|
|
|
|
|
uuid, err := guuid.NewV4()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testDir := path.Join("/oci-repo-test", uuid.String())
|
2022-04-12 05:01:04 -05:00
|
|
|
tdir := t.TempDir()
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
var store driver.StorageDriver
|
2022-04-12 05:01:04 -05:00
|
|
|
store, imgStore, _ = createObjectsStore(testDir, tdir)
|
2021-07-16 22:53:05 -05:00
|
|
|
defer cleanupStorage(store, testDir)
|
|
|
|
} else {
|
2022-03-07 03:55:12 -05:00
|
|
|
dir := t.TempDir()
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
2022-06-24 08:08:47 -05:00
|
|
|
imgStore = storage.NewImageStore(dir, true, storage.DefaultGCDelay, true,
|
|
|
|
true, log, metrics, nil)
|
2021-07-16 22:53:05 -05:00
|
|
|
}
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Repo layout", t, func(c C) {
|
|
|
|
repoName := "test"
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Validate repo without initialization", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
v, err := imgStore.ValidateRepo(repoName)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(v, ShouldEqual, false)
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
ok := imgStore.DirExists(path.Join(imgStore.RootDir(), repoName))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(ok, ShouldBeFalse)
|
|
|
|
})
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Initialize repo", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
err := imgStore.InitRepo(repoName)
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
ok := imgStore.DirExists(path.Join(imgStore.RootDir(), repoName))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(ok, ShouldBeTrue)
|
|
|
|
storeController := storage.StoreController{}
|
2021-12-13 14:23:31 -05:00
|
|
|
storeController.DefaultStore = imgStore
|
|
|
|
So(storeController.GetImageStore("test"), ShouldResemble, imgStore)
|
2020-02-17 16:57:15 -05:00
|
|
|
})
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Validate repo", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
v, err := imgStore.ValidateRepo(repoName)
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(v, ShouldEqual, true)
|
|
|
|
})
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Get repos", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
v, err := imgStore.GetRepositories()
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(v, ShouldNotBeEmpty)
|
|
|
|
})
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Get image tags", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
v, err := imgStore.GetImageTags("test")
|
2020-04-06 20:17:24 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(v, ShouldBeEmpty)
|
|
|
|
})
|
2020-04-06 20:17:24 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Full blob upload", func() {
|
|
|
|
body := []byte("this is a blob")
|
|
|
|
buf := bytes.NewBuffer(body)
|
2021-12-13 14:23:31 -05:00
|
|
|
digest := godigest.FromBytes(body)
|
|
|
|
upload, n, err := imgStore.FullBlobUpload("test", buf, digest.String())
|
2021-08-20 16:08:41 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(n, ShouldEqual, len(body))
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldNotBeEmpty)
|
2021-07-16 22:53:05 -05:00
|
|
|
})
|
2021-08-20 16:08:41 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("New blob upload", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err := imgStore.NewBlobUpload("test")
|
2021-08-20 16:08:41 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldNotBeEmpty)
|
2021-08-20 16:08:41 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlobUpload("test", upload)
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err = imgStore.NewBlobUpload("test")
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldNotBeEmpty)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
Convey("Get blob upload", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err := imgStore.GetBlobUpload("test", "invalid")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldEqual, -1)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2022-07-27 12:37:55 -05:00
|
|
|
bupload, err = imgStore.GetBlobUpload("hi", " \255")
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(bupload, ShouldEqual, -1)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err = imgStore.GetBlobUpload("test", upload)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldBeGreaterThanOrEqualTo, 0)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err = imgStore.BlobUploadInfo("test", upload)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldBeGreaterThanOrEqualTo, 0)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
content := []byte("test-data1")
|
|
|
|
firstChunkContent := []byte("test")
|
|
|
|
firstChunkBuf := bytes.NewBuffer(firstChunkContent)
|
|
|
|
secondChunkContent := []byte("-data1")
|
|
|
|
secondChunkBuf := bytes.NewBuffer(secondChunkContent)
|
|
|
|
firstChunkLen := firstChunkBuf.Len()
|
|
|
|
secondChunkLen := secondChunkBuf.Len()
|
|
|
|
|
|
|
|
buf := bytes.NewBuffer(content)
|
2021-12-13 14:23:31 -05:00
|
|
|
buflen := buf.Len()
|
|
|
|
digest := godigest.FromBytes(content)
|
|
|
|
blobDigest := digest
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
// invalid chunk range
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutBlobChunk("test", upload, 10, int64(buflen), buf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err = imgStore.PutBlobChunk("test", upload, 0, int64(firstChunkLen), firstChunkBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldEqual, firstChunkLen)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err = imgStore.GetBlobUpload("test", upload)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldEqual, int64(firstChunkLen))
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err = imgStore.BlobUploadInfo("test", upload)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldEqual, int64(firstChunkLen))
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err = imgStore.PutBlobChunk("test", upload, int64(firstChunkLen), int64(buflen), secondChunkBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldEqual, secondChunkLen)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload("test", upload, buf, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.CheckBlob("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.GetBlob("test", digest.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest := ispec.Manifest{}
|
|
|
|
manifest.SchemaVersion = 2
|
2022-03-21 12:37:23 -05:00
|
|
|
manifestBuf, err := json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
Convey("Bad image manifest", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(), "application/json",
|
|
|
|
manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(), ispec.MediaTypeImageManifest,
|
|
|
|
[]byte{})
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(), ispec.MediaTypeImageManifest,
|
|
|
|
[]byte(`{"test":true}`))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(), ispec.MediaTypeImageManifest,
|
|
|
|
manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("inexistent", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Good image manifest", func() {
|
2022-01-19 14:54:17 -05:00
|
|
|
cblob, cdigest := test.GetRandomImageConfig()
|
|
|
|
_, clen, err := imgStore.FullBlobUpload("test", bytes.NewReader(cblob), cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(clen, ShouldEqual, len(cblob))
|
|
|
|
hasBlob, _, err := imgStore.CheckBlob("test", cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(hasBlob, ShouldEqual, true)
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
annotationsMap := make(map[string]string)
|
|
|
|
annotationsMap[ispec.AnnotationRefName] = "1.0"
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest := ispec.Manifest{
|
2021-07-16 22:53:05 -05:00
|
|
|
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-07-16 22:53:05 -05:00
|
|
|
},
|
|
|
|
Layers: []ispec.Descriptor{
|
|
|
|
{
|
|
|
|
MediaType: "application/vnd.oci.image.layer.v1.tar",
|
2021-12-13 14:23:31 -05:00
|
|
|
Digest: digest,
|
|
|
|
Size: int64(buflen),
|
2021-07-16 22:53:05 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
Annotations: annotationsMap,
|
|
|
|
}
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest.SchemaVersion = 2
|
2022-03-21 12:37:23 -05:00
|
|
|
manifestBuf, err = json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
digest := godigest.FromBytes(manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
// bad manifest
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest.Layers[0].Digest = godigest.FromBytes([]byte("inexistent"))
|
2022-03-21 12:37:23 -05:00
|
|
|
badMb, err := json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", "1.0", ispec.MediaTypeImageManifest, badMb)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", "1.0", ispec.MediaTypeImageManifest, manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
// same manifest for coverage
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", "1.0", ispec.MediaTypeImageManifest, manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", "2.0", ispec.MediaTypeImageManifest, manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", "3.0", ispec.MediaTypeImageManifest, manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-08-20 16:08:41 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.GetImageTags("inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// total tags should be 3 but they have same reference.
|
2021-12-13 14:23:31 -05:00
|
|
|
tags, err := imgStore.GetImageTags("test")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(tags), ShouldEqual, 3)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("test", "3.0")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteImageManifest("test", "1.0")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-08-20 16:08:41 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
tags, err = imgStore.GetImageTags("test")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(tags), ShouldEqual, 2)
|
2021-08-20 16:08:41 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// We deleted only one tag, make sure blob should not be removed.
|
2022-01-19 14:54:17 -05:00
|
|
|
hasBlob, _, err = imgStore.CheckBlob("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(hasBlob, ShouldEqual, true)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// If we pass reference all manifest with input reference should be deleted.
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
tags, err = imgStore.GetImageTags("test")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(len(tags), ShouldEqual, 0)
|
2021-08-20 16:08:41 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// All tags/references are deleted, blob should not be present in disk.
|
2021-12-13 14:23:31 -05:00
|
|
|
hasBlob, _, err = imgStore.CheckBlob("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
So(hasBlob, ShouldEqual, false)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlob("test", "inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlob("test", godigest.FromBytes([]byte("inexistent")).String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlob("test", blobDigest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlobUpload("test", upload)
|
2020-02-17 16:57:15 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("New blob upload streamed", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
bupload, err := imgStore.NewBlobUpload("test")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(bupload, ShouldNotBeEmpty)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
Convey("Get blob upload", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload("test", bupload, bytes.NewBuffer([]byte{}), "inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err := imgStore.GetBlobUpload("test", "invalid")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldEqual, -1)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err = imgStore.GetBlobUpload("test", bupload)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldBeGreaterThanOrEqualTo, 0)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.BlobUploadInfo("test", "inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err = imgStore.BlobUploadInfo("test", bupload)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldBeGreaterThanOrEqualTo, 0)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
content := []byte("test-data2")
|
|
|
|
buf := bytes.NewBuffer(content)
|
2021-12-13 14:23:31 -05:00
|
|
|
buflen := buf.Len()
|
|
|
|
digest := godigest.FromBytes(content)
|
|
|
|
upload, err = imgStore.PutBlobChunkStreamed("test", bupload, buf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldEqual, buflen)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.PutBlobChunkStreamed("test", "inexistent", buf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload("test", "inexistent", buf, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload("test", bupload, buf, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.CheckBlob("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.GetBlob("test", "inexistent", "application/vnd.oci.image.layer.v1.tar+gzip")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.GetBlob("test", digest.String(), "application/vnd.oci.image.layer.v1.tar+gzip")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
blobContent, err := imgStore.GetBlobContent("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(content, ShouldResemble, blobContent)
|
2020-02-17 16:57:15 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.GetBlobContent("inexistent", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest := ispec.Manifest{}
|
|
|
|
manifest.SchemaVersion = 2
|
2022-03-21 12:37:23 -05:00
|
|
|
manifestBuf, err := json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Bad digests", func() {
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err := imgStore.FullBlobUpload("test", bytes.NewBuffer([]byte{}), "inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, err = imgStore.CheckBlob("test", "inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Bad image manifest", func() {
|
2022-06-24 08:08:47 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(),
|
|
|
|
ispec.MediaTypeImageManifest, manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2022-06-24 08:08:47 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(),
|
|
|
|
ispec.MediaTypeImageManifest, []byte("bad json"))
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Good image manifest", func() {
|
2022-01-19 14:54:17 -05:00
|
|
|
cblob, cdigest := test.GetRandomImageConfig()
|
|
|
|
_, clen, err := imgStore.FullBlobUpload("test", bytes.NewReader(cblob), cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(clen, ShouldEqual, len(cblob))
|
|
|
|
hasBlob, _, err := imgStore.CheckBlob("test", cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(hasBlob, ShouldEqual, true)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest := ispec.Manifest{
|
2021-07-16 22:53:05 -05:00
|
|
|
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-07-16 22:53:05 -05:00
|
|
|
},
|
|
|
|
Layers: []ispec.Descriptor{
|
|
|
|
{
|
|
|
|
MediaType: "application/vnd.oci.image.layer.v1.tar",
|
2021-12-13 14:23:31 -05:00
|
|
|
Digest: digest,
|
|
|
|
Size: int64(buflen),
|
2021-07-16 22:53:05 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest.SchemaVersion = 2
|
2022-03-21 12:37:23 -05:00
|
|
|
manifestBuf, err = json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
digest := godigest.FromBytes(manifestBuf)
|
2022-06-24 08:08:47 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(),
|
|
|
|
ispec.MediaTypeImageManifest, manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// same manifest for coverage
|
2022-06-24 08:08:47 -05:00
|
|
|
_, err = imgStore.PutImageManifest("test", digest.String(),
|
|
|
|
ispec.MediaTypeImageManifest, manifestBuf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.GetIndexContent("inexistent")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
indexContent, err := imgStore.GetIndexContent("test")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2021-11-10 09:31:03 -05:00
|
|
|
if testcase.storageType == "fs" {
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(path.Join(imgStore.RootDir(), "test", "index.json"), 0o000)
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
_, err = imgStore.GetIndexContent("test")
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
err = os.Chmod(path.Join(imgStore.RootDir(), "test", "index.json"), 0o644)
|
2021-11-10 09:31:03 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
}
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
var index ispec.Index
|
|
|
|
|
|
|
|
err = json.Unmarshal(indexContent, &index)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
So(len(index.Manifests), ShouldEqual, 1)
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteImageManifest("test", "1.0")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteImageManifest("inexistent", "1.0")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("test", digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
})
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.DeleteBlobUpload("test", bupload)
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Modify manifest in-place", func() {
|
|
|
|
// original blob
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err := imgStore.NewBlobUpload("replace")
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldNotBeEmpty)
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
content := []byte("test-data-replace-1")
|
|
|
|
buf := bytes.NewBuffer(content)
|
2021-12-13 14:23:31 -05:00
|
|
|
buflen := buf.Len()
|
|
|
|
digest := godigest.FromBytes(content)
|
|
|
|
blob, err := imgStore.PutBlobChunkStreamed("replace", upload, buf)
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(blob, ShouldEqual, buflen)
|
|
|
|
blobDigest1 := strings.Split(digest.String(), ":")[1]
|
2021-07-16 22:53:05 -05:00
|
|
|
So(blobDigest1, ShouldNotBeEmpty)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload("replace", upload, buf, digest.String())
|
2021-07-16 22:53:05 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(blob, ShouldEqual, buflen)
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
cblob, cdigest := test.GetRandomImageConfig()
|
|
|
|
_, clen, err := imgStore.FullBlobUpload("replace", bytes.NewReader(cblob), cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(clen, ShouldEqual, len(cblob))
|
|
|
|
hasBlob, _, err := imgStore.CheckBlob("replace", cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(hasBlob, ShouldEqual, true)
|
|
|
|
|
|
|
|
manifest := ispec.Manifest{
|
2020-03-18 17:42:06 -05:00
|
|
|
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)),
|
2020-03-18 17:42:06 -05:00
|
|
|
},
|
|
|
|
Layers: []ispec.Descriptor{
|
|
|
|
{
|
|
|
|
MediaType: "application/vnd.oci.image.layer.v1.tar",
|
2021-12-13 14:23:31 -05:00
|
|
|
Digest: digest,
|
|
|
|
Size: int64(buflen),
|
2020-03-18 17:42:06 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest.SchemaVersion = 2
|
2022-03-21 12:37:23 -05:00
|
|
|
manifestBuf, err := json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
digest = godigest.FromBytes(manifestBuf)
|
|
|
|
_, err = imgStore.PutImageManifest("replace", "1.0", ispec.MediaTypeImageManifest, manifestBuf)
|
2019-09-17 17:45:28 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
_, _, _, err = imgStore.GetImageManifest("replace", digest.String())
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
// new blob to replace
|
2021-12-13 14:23:31 -05:00
|
|
|
upload, err = imgStore.NewBlobUpload("replace")
|
2019-09-17 17:45:28 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(upload, ShouldNotBeEmpty)
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
content = []byte("test-data-replace-2")
|
|
|
|
buf = bytes.NewBuffer(content)
|
2021-12-13 14:23:31 -05:00
|
|
|
buflen = buf.Len()
|
|
|
|
digest = godigest.FromBytes(content)
|
|
|
|
blob, err = imgStore.PutBlobChunkStreamed("replace", upload, buf)
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(blob, ShouldEqual, buflen)
|
|
|
|
blobDigest2 := strings.Split(digest.String(), ":")[1]
|
2021-07-16 22:53:05 -05:00
|
|
|
So(blobDigest2, ShouldNotBeEmpty)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
err = imgStore.FinishBlobUpload("replace", upload, buf, digest.String())
|
2021-09-30 08:27:13 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
So(blob, ShouldEqual, buflen)
|
2021-09-30 08:27:13 -05:00
|
|
|
|
2022-01-19 14:54:17 -05:00
|
|
|
cblob, cdigest = test.GetRandomImageConfig()
|
|
|
|
_, clen, err = imgStore.FullBlobUpload("replace", bytes.NewReader(cblob), cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(clen, ShouldEqual, len(cblob))
|
|
|
|
hasBlob, _, err = imgStore.CheckBlob("replace", cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(hasBlob, ShouldEqual, true)
|
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest = ispec.Manifest{
|
2021-07-16 22:53:05 -05:00
|
|
|
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-07-16 22:53:05 -05:00
|
|
|
},
|
|
|
|
Layers: []ispec.Descriptor{
|
|
|
|
{
|
|
|
|
MediaType: "application/vnd.oci.image.layer.v1.tar",
|
2021-12-13 14:23:31 -05:00
|
|
|
Digest: digest,
|
|
|
|
Size: int64(buflen),
|
2021-07-16 22:53:05 -05:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2021-12-13 14:23:31 -05:00
|
|
|
manifest.SchemaVersion = 2
|
2022-03-21 12:37:23 -05:00
|
|
|
manifestBuf, err = json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
2021-12-13 14:23:31 -05:00
|
|
|
_ = godigest.FromBytes(manifestBuf)
|
|
|
|
_, err = imgStore.PutImageManifest("replace", "1.0", ispec.MediaTypeImageManifest, manifestBuf)
|
2019-09-17 17:45:28 -05:00
|
|
|
So(err, ShouldBeNil)
|
2021-07-16 22:53:05 -05:00
|
|
|
})
|
2019-09-17 17:45:28 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Locks", func() {
|
|
|
|
// in parallel, a mix of read and write locks - mainly for coverage
|
|
|
|
var wg sync.WaitGroup
|
|
|
|
for i := 0; i < 1000; i++ {
|
|
|
|
wg.Add(2)
|
|
|
|
go func() {
|
2021-12-21 08:19:40 -05:00
|
|
|
var lockLatency time.Time
|
2021-07-16 22:53:05 -05:00
|
|
|
defer wg.Done()
|
2021-12-21 08:19:40 -05:00
|
|
|
imgStore.Lock(&lockLatency)
|
2021-07-16 22:53:05 -05:00
|
|
|
func() {}()
|
2021-12-21 08:19:40 -05:00
|
|
|
imgStore.Unlock(&lockLatency)
|
2021-07-16 22:53:05 -05:00
|
|
|
}()
|
|
|
|
go func() {
|
2021-12-21 08:19:40 -05:00
|
|
|
var lockLatency time.Time
|
2021-07-16 22:53:05 -05:00
|
|
|
defer wg.Done()
|
2021-12-21 08:19:40 -05:00
|
|
|
imgStore.RLock(&lockLatency)
|
2021-07-16 22:53:05 -05:00
|
|
|
func() {}()
|
2021-12-21 08:19:40 -05:00
|
|
|
imgStore.RUnlock(&lockLatency)
|
2021-07-16 22:53:05 -05:00
|
|
|
}()
|
|
|
|
}
|
|
|
|
wg.Wait()
|
2019-09-17 17:45:28 -05:00
|
|
|
})
|
|
|
|
})
|
2020-02-17 16:57:15 -05:00
|
|
|
})
|
2021-07-16 22:53:05 -05:00
|
|
|
}
|
2021-04-05 19:40:33 -05:00
|
|
|
}
|
|
|
|
|
2022-06-24 08:08:47 -05:00
|
|
|
func TestMandatoryAnnotations(t *testing.T) {
|
|
|
|
for _, testcase := range testCases {
|
|
|
|
testcase := testcase
|
|
|
|
t.Run(testcase.testCaseName, func(t *testing.T) {
|
|
|
|
var imgStore storage.ImageStore
|
|
|
|
var testDir, tdir string
|
|
|
|
var store driver.StorageDriver
|
|
|
|
|
|
|
|
log := log.Logger{Logger: zerolog.New(os.Stdout)}
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
|
|
|
|
|
|
|
if testcase.storageType == "s3" {
|
|
|
|
skipIt(t)
|
|
|
|
|
|
|
|
uuid, err := guuid.NewV4()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
testDir = path.Join("/oci-repo-test", uuid.String())
|
|
|
|
tdir = t.TempDir()
|
|
|
|
|
|
|
|
store, _, _ = createObjectsStore(testDir, tdir)
|
|
|
|
imgStore = s3.NewImageStore(testDir, tdir, false, 1, false, false, log, metrics,
|
|
|
|
&mocks.MockedLint{
|
|
|
|
LintFn: func(repo string, manifestDigest godigest.Digest, imageStore storage.ImageStore) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
},
|
|
|
|
}, store)
|
|
|
|
|
|
|
|
defer cleanupStorage(store, testDir)
|
|
|
|
} else {
|
|
|
|
tdir = t.TempDir()
|
|
|
|
|
|
|
|
imgStore = storage.NewImageStore(tdir, true, storage.DefaultGCDelay, true,
|
|
|
|
true, log, metrics, &mocks.MockedLint{
|
|
|
|
LintFn: func(repo string, manifestDigest godigest.Digest, imageStore storage.ImageStore) (bool, error) {
|
|
|
|
return false, nil
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
Convey("Setup manifest", t, func() {
|
|
|
|
content := []byte("test-data1")
|
|
|
|
buf := bytes.NewBuffer(content)
|
|
|
|
buflen := buf.Len()
|
|
|
|
digest := godigest.FromBytes(content)
|
|
|
|
|
|
|
|
_, _, err := imgStore.FullBlobUpload("test", bytes.NewReader(buf.Bytes()), digest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
cblob, cdigest := test.GetRandomImageConfig()
|
|
|
|
_, clen, err := imgStore.FullBlobUpload("test", bytes.NewReader(cblob), cdigest.String())
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
So(clen, ShouldEqual, len(cblob))
|
|
|
|
|
|
|
|
annotationsMap := make(map[string]string)
|
|
|
|
annotationsMap[ispec.AnnotationRefName] = "1.0"
|
|
|
|
|
|
|
|
manifest := ispec.Manifest{
|
|
|
|
Config: ispec.Descriptor{
|
|
|
|
MediaType: "application/vnd.oci.image.config.v1+json",
|
|
|
|
Digest: cdigest,
|
|
|
|
Size: int64(len(cblob)),
|
|
|
|
},
|
|
|
|
Layers: []ispec.Descriptor{
|
|
|
|
{
|
|
|
|
MediaType: "application/vnd.oci.image.layer.v1.tar",
|
|
|
|
Digest: digest,
|
|
|
|
Size: int64(buflen),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Annotations: annotationsMap,
|
|
|
|
}
|
|
|
|
|
|
|
|
manifest.SchemaVersion = 2
|
|
|
|
manifestBuf, err := json.Marshal(manifest)
|
|
|
|
So(err, ShouldBeNil)
|
|
|
|
|
|
|
|
Convey("Missing mandatory annotations", func() {
|
|
|
|
_, err = imgStore.PutImageManifest("test", "1.0.0", ispec.MediaTypeImageManifest, manifestBuf)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
|
|
|
|
Convey("Error on mandatory annotations", func() {
|
|
|
|
if testcase.storageType == "s3" {
|
|
|
|
imgStore = s3.NewImageStore(testDir, tdir, false, 1, false, false, log, metrics,
|
|
|
|
&mocks.MockedLint{
|
|
|
|
LintFn: func(repo string, manifestDigest godigest.Digest, imageStore storage.ImageStore) (bool, error) {
|
|
|
|
// nolint: goerr113
|
|
|
|
return false, errors.New("linter error")
|
|
|
|
},
|
|
|
|
}, store)
|
|
|
|
} else {
|
|
|
|
imgStore = storage.NewImageStore(tdir, true, storage.DefaultGCDelay, true,
|
|
|
|
true, log, metrics, &mocks.MockedLint{
|
|
|
|
LintFn: func(repo string, manifestDigest godigest.Digest, imageStore storage.ImageStore) (bool, error) {
|
|
|
|
// nolint: goerr113
|
|
|
|
return false, errors.New("linter error")
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = imgStore.PutImageManifest("test", "1.0.0", ispec.MediaTypeImageManifest, manifestBuf)
|
|
|
|
So(err, ShouldNotBeNil)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-05 19:40:33 -05:00
|
|
|
func TestStorageHandler(t *testing.T) {
|
2021-07-16 22:53:05 -05:00
|
|
|
for _, testcase := range testCases {
|
|
|
|
testcase := testcase
|
|
|
|
t.Run(testcase.testCaseName, func(t *testing.T) {
|
|
|
|
var firstStore storage.ImageStore
|
|
|
|
var secondStore storage.ImageStore
|
|
|
|
var thirdStore storage.ImageStore
|
|
|
|
var firstRootDir string
|
|
|
|
var secondRootDir string
|
|
|
|
var thirdRootDir string
|
|
|
|
|
|
|
|
if testcase.storageType == "s3" {
|
|
|
|
skipIt(t)
|
|
|
|
var firstStorageDriver driver.StorageDriver
|
|
|
|
var secondStorageDriver driver.StorageDriver
|
|
|
|
var thirdStorageDriver driver.StorageDriver
|
|
|
|
|
|
|
|
firstRootDir = "/util_test1"
|
2022-04-12 05:01:04 -05:00
|
|
|
firstStorageDriver, firstStore, _ = createObjectsStore(firstRootDir, t.TempDir())
|
2021-07-16 22:53:05 -05:00
|
|
|
defer cleanupStorage(firstStorageDriver, firstRootDir)
|
|
|
|
|
|
|
|
secondRootDir = "/util_test2"
|
2022-04-12 05:01:04 -05:00
|
|
|
secondStorageDriver, secondStore, _ = createObjectsStore(secondRootDir, t.TempDir())
|
2021-07-16 22:53:05 -05:00
|
|
|
defer cleanupStorage(secondStorageDriver, secondRootDir)
|
|
|
|
|
|
|
|
thirdRootDir = "/util_test3"
|
2022-04-12 05:01:04 -05:00
|
|
|
thirdStorageDriver, thirdStore, _ = createObjectsStore(thirdRootDir, t.TempDir())
|
2021-07-16 22:53:05 -05:00
|
|
|
defer cleanupStorage(thirdStorageDriver, thirdRootDir)
|
|
|
|
} else {
|
|
|
|
// Create temporary directory
|
2022-03-07 03:55:12 -05:00
|
|
|
firstRootDir = t.TempDir()
|
|
|
|
secondRootDir = t.TempDir()
|
|
|
|
thirdRootDir = t.TempDir()
|
2021-07-16 22:53:05 -05:00
|
|
|
|
|
|
|
log := log.NewLogger("debug", "")
|
|
|
|
|
|
|
|
metrics := monitoring.NewMetricsServer(false, log)
|
|
|
|
|
|
|
|
// Create ImageStore
|
2022-06-24 08:08:47 -05:00
|
|
|
firstStore = storage.NewImageStore(firstRootDir, false, storage.DefaultGCDelay,
|
|
|
|
false, false, log, metrics, nil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2022-06-24 08:08:47 -05:00
|
|
|
secondStore = storage.NewImageStore(secondRootDir, false,
|
|
|
|
storage.DefaultGCDelay, false, false, log, metrics, nil)
|
2021-07-16 22:53:05 -05:00
|
|
|
|
2022-06-24 08:08:47 -05:00
|
|
|
thirdStore = storage.NewImageStore(thirdRootDir, false, storage.DefaultGCDelay,
|
|
|
|
false, false, log, metrics, nil)
|
2021-07-16 22:53:05 -05:00
|
|
|
}
|
2021-04-05 19:40:33 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
Convey("Test storage handler", t, func() {
|
|
|
|
storeController := storage.StoreController{}
|
2021-04-05 19:40:33 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
storeController.DefaultStore = firstStore
|
2021-04-05 19:40:33 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
subStore := make(map[string]storage.ImageStore)
|
2021-04-05 19:40:33 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
subStore["/a"] = secondStore
|
|
|
|
subStore["/b"] = thirdStore
|
2021-04-05 19:40:33 -05:00
|
|
|
|
2021-07-16 22:53:05 -05:00
|
|
|
storeController.SubStore = subStore
|
2021-04-05 19:40:33 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore := storeController.GetImageStore("zot-x-test")
|
|
|
|
So(imgStore.RootDir(), ShouldEqual, firstRootDir)
|
2021-04-05 19:40:33 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = storeController.GetImageStore("a/zot-a-test")
|
|
|
|
So(imgStore.RootDir(), ShouldEqual, secondRootDir)
|
2021-10-27 12:03:26 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = storeController.GetImageStore("b/zot-b-test")
|
|
|
|
So(imgStore.RootDir(), ShouldEqual, thirdRootDir)
|
2021-10-27 12:03:26 -05:00
|
|
|
|
2021-12-13 14:23:31 -05:00
|
|
|
imgStore = storeController.GetImageStore("c/zot-c-test")
|
|
|
|
So(imgStore.RootDir(), ShouldEqual, firstRootDir)
|
2021-07-16 22:53:05 -05:00
|
|
|
})
|
|
|
|
})
|
2021-10-27 12:03:26 -05:00
|
|
|
}
|
|
|
|
}
|