mirror of
https://github.com/project-zot/zot.git
synced 2026-06-16 04:17:55 +08:00
fixed failed tests for all skopeo versions
Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> skopeo verifications Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> skopeo verifications modified makefile Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> modified how to get digest and fixed makefile Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> fixed failed tests for all skopeo versions Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> echo skopeo version Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> skopeo verifications Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> skopeo verifications modified makefile Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> modified how to get digest and fixed makefile Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> skopeo failed tests fixed Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> changed function name Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> fixed lost modifications Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com> fixed code coverage and dead code Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com>
This commit is contained in:
committed by
Ramkumar Chinchani
parent
e5a14670db
commit
62775cc095
@@ -1,6 +1,7 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/rand"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -15,6 +16,7 @@ import (
|
||||
|
||||
godigest "github.com/opencontainers/go-digest"
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/opencontainers/umoci"
|
||||
"github.com/phayes/freeport"
|
||||
"gopkg.in/resty.v1"
|
||||
)
|
||||
@@ -204,3 +206,54 @@ func GetImageConfig() ([]byte, godigest.Digest) {
|
||||
|
||||
return configBlobContent, configBlobDigestRaw
|
||||
}
|
||||
|
||||
func GetOciLayoutDigests(imagePath string) (godigest.Digest, godigest.Digest, godigest.Digest) {
|
||||
var (
|
||||
manifestDigest godigest.Digest
|
||||
configDigest godigest.Digest
|
||||
layerDigest godigest.Digest
|
||||
)
|
||||
|
||||
oci, err := umoci.OpenLayout(imagePath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
defer oci.Close()
|
||||
|
||||
ctxUmoci := context.Background()
|
||||
|
||||
index, err := oci.GetIndex(ctxUmoci)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, manifest := range index.Manifests {
|
||||
manifestDigest = manifest.Digest
|
||||
|
||||
manifestBlob, err := oci.GetBlob(ctxUmoci, manifest.Digest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
manifestBuf, err := ioutil.ReadAll(manifestBlob)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var manifest imagespec.Manifest
|
||||
|
||||
err = json.Unmarshal(manifestBuf, &manifest)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
configDigest = manifest.Config.Digest
|
||||
|
||||
for _, layer := range manifest.Layers {
|
||||
layerDigest = layer.Digest
|
||||
}
|
||||
}
|
||||
|
||||
return manifestDigest, configDigest, layerDigest
|
||||
}
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
package test_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"testing"
|
||||
|
||||
ispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"zotregistry.io/zot/pkg/test"
|
||||
)
|
||||
@@ -64,3 +66,59 @@ func TestCopyFiles(t *testing.T) {
|
||||
So(err, ShouldNotBeNil)
|
||||
})
|
||||
}
|
||||
|
||||
func TestGetOciLayoutDigests(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
|
||||
Convey("image path is wrong", t, func() {
|
||||
So(func() { _, _, _ = test.GetOciLayoutDigests("inexistent-image") }, ShouldPanic)
|
||||
})
|
||||
|
||||
Convey("no permissions when getting index", t, func() {
|
||||
err := test.CopyFiles("../../test/data/zot-test", path.Join(dir, "test-index"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = os.Chmod(path.Join(dir, "test-index", "index.json"), 0o000)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
So(func() { _, _, _ = test.GetOciLayoutDigests(path.Join(dir, "test-index")) }, ShouldPanic)
|
||||
|
||||
err = os.Chmod(path.Join(dir, "test-index", "index.json"), 0o755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
|
||||
Convey("can't access manifest digest", t, func() {
|
||||
err := test.CopyFiles("../../test/data/zot-test", path.Join(dir, "test-manifest"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
buf, err := ioutil.ReadFile(path.Join(dir, "test-manifest", "index.json"))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var index ispec.Index
|
||||
if err := json.Unmarshal(buf, &index); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = os.Chmod(path.Join(dir, "test-manifest", "blobs/sha256", index.Manifests[0].Digest.Encoded()), 0o000)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
So(func() { _, _, _ = test.GetOciLayoutDigests(path.Join(dir, "test-manifest")) }, ShouldPanic)
|
||||
|
||||
err = os.Chmod(path.Join(dir, "test-manifest", "blobs/sha256", index.Manifests[0].Digest.Encoded()), 0o755)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user