mirror of
https://github.com/project-zot/zot.git
synced 2024-12-16 21:56:37 -05:00
sync: fix functions which compare signatures
Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
This commit is contained in:
parent
4e20ab8a5d
commit
89c5f4f604
2 changed files with 268 additions and 22 deletions
|
@ -649,3 +649,246 @@ func TestFindRepoMatchingContentID(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCompareManifest(t *testing.T) {
|
||||
testCases := []struct {
|
||||
manifest1 ispec.Manifest
|
||||
manifest2 ispec.Manifest
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
manifest1: ispec.Manifest{
|
||||
Config: ispec.Descriptor{
|
||||
Digest: "digest1",
|
||||
},
|
||||
},
|
||||
manifest2: ispec.Manifest{
|
||||
Config: ispec.Descriptor{
|
||||
Digest: "digest2",
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
manifest1: ispec.Manifest{
|
||||
Config: ispec.Descriptor{
|
||||
Digest: "digest",
|
||||
},
|
||||
},
|
||||
manifest2: ispec.Manifest{
|
||||
Config: ispec.Descriptor{
|
||||
Digest: "digest",
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
manifest1: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{{
|
||||
Digest: "digest",
|
||||
Size: 1,
|
||||
}},
|
||||
},
|
||||
manifest2: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{{
|
||||
Digest: "digest",
|
||||
Size: 1,
|
||||
}},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
manifest1: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{{
|
||||
Digest: "digest1",
|
||||
Size: 1,
|
||||
}},
|
||||
},
|
||||
manifest2: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{{
|
||||
Digest: "digest2",
|
||||
Size: 2,
|
||||
}},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
manifest1: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
Size: 1,
|
||||
},
|
||||
{
|
||||
Digest: "digest1",
|
||||
Size: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
manifest2: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{{
|
||||
Digest: "digest",
|
||||
Size: 1,
|
||||
}},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
manifest1: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{
|
||||
{
|
||||
Digest: "digest1",
|
||||
Size: 1,
|
||||
},
|
||||
{
|
||||
Digest: "digest2",
|
||||
Size: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
manifest2: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{
|
||||
{
|
||||
Digest: "digest1",
|
||||
Size: 1,
|
||||
},
|
||||
{
|
||||
Digest: "digest2",
|
||||
Size: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
manifest1: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
Size: 1,
|
||||
},
|
||||
{
|
||||
Digest: "digest1",
|
||||
Size: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
manifest2: ispec.Manifest{
|
||||
Layers: []ispec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
Size: 1,
|
||||
},
|
||||
{
|
||||
Digest: "digest2",
|
||||
Size: 2,
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
Convey("Test manifestsEqual()", t, func() {
|
||||
for _, test := range testCases {
|
||||
actualResult := manifestsEqual(test.manifest1, test.manifest2)
|
||||
So(actualResult, ShouldEqual, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestCompareArtifactRefs(t *testing.T) {
|
||||
testCases := []struct {
|
||||
refs1 []artifactspec.Descriptor
|
||||
refs2 []artifactspec.Descriptor
|
||||
expected bool
|
||||
}{
|
||||
{
|
||||
refs1: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest1",
|
||||
},
|
||||
},
|
||||
refs2: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest2",
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
refs1: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
},
|
||||
},
|
||||
refs2: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
refs1: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
},
|
||||
{
|
||||
Digest: "digest2",
|
||||
},
|
||||
},
|
||||
refs2: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
{
|
||||
refs1: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest1",
|
||||
},
|
||||
{
|
||||
Digest: "digest2",
|
||||
},
|
||||
},
|
||||
refs2: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest1",
|
||||
},
|
||||
{
|
||||
Digest: "digest2",
|
||||
},
|
||||
},
|
||||
expected: true,
|
||||
},
|
||||
{
|
||||
refs1: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest",
|
||||
},
|
||||
{
|
||||
Digest: "digest1",
|
||||
},
|
||||
},
|
||||
refs2: []artifactspec.Descriptor{
|
||||
{
|
||||
Digest: "digest1",
|
||||
},
|
||||
{
|
||||
Digest: "digest2",
|
||||
},
|
||||
},
|
||||
expected: false,
|
||||
},
|
||||
}
|
||||
|
||||
Convey("Test manifestsEqual()", t, func() {
|
||||
for _, test := range testCases {
|
||||
actualResult := artifactDescriptorsEqual(test.refs1, test.refs2)
|
||||
So(actualResult, ShouldEqual, test.expected)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -412,9 +412,8 @@ func canSkipImage(repo, tag, digest string, imageStore storage.ImageStore, log l
|
|||
func manifestsEqual(manifest1, manifest2 ispec.Manifest) bool {
|
||||
if manifest1.Config.Digest == manifest2.Config.Digest &&
|
||||
manifest1.Config.MediaType == manifest2.Config.MediaType &&
|
||||
manifest1.Config.Size == manifest2.Config.Size &&
|
||||
len(manifest1.Layers) == len(manifest2.Layers) {
|
||||
if descriptorEqual(manifest1.Layers, manifest2.Layers) {
|
||||
manifest1.Config.Size == manifest2.Config.Size {
|
||||
if descriptorsEqual(manifest1.Layers, manifest2.Layers) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
@ -423,31 +422,35 @@ func manifestsEqual(manifest1, manifest2 ispec.Manifest) bool {
|
|||
}
|
||||
|
||||
func artifactDescriptorsEqual(desc1, desc2 []artifactspec.Descriptor) bool {
|
||||
if len(desc1) == len(desc2) {
|
||||
for id, desc := range desc1 {
|
||||
if desc.Digest == desc2[id].Digest &&
|
||||
desc.Size == desc2[id].Size &&
|
||||
desc.MediaType == desc2[id].MediaType &&
|
||||
desc.ArtifactType == desc2[id].ArtifactType {
|
||||
return true
|
||||
}
|
||||
if len(desc1) != len(desc2) {
|
||||
return false
|
||||
}
|
||||
|
||||
for id, desc := range desc1 {
|
||||
if desc.Digest != desc2[id].Digest ||
|
||||
desc.Size != desc2[id].Size ||
|
||||
desc.MediaType != desc2[id].MediaType ||
|
||||
desc.ArtifactType != desc2[id].ArtifactType {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
||||
func descriptorEqual(desc1, desc2 []ispec.Descriptor) bool {
|
||||
if len(desc1) == len(desc2) {
|
||||
for id, desc := range desc1 {
|
||||
if desc.Digest == desc2[id].Digest &&
|
||||
desc.Size == desc2[id].Size &&
|
||||
desc.MediaType == desc2[id].MediaType &&
|
||||
desc.Annotations[static.SignatureAnnotationKey] == desc2[id].Annotations[static.SignatureAnnotationKey] {
|
||||
return true
|
||||
}
|
||||
func descriptorsEqual(desc1, desc2 []ispec.Descriptor) bool {
|
||||
if len(desc1) != len(desc2) {
|
||||
return false
|
||||
}
|
||||
|
||||
for id, desc := range desc1 {
|
||||
if desc.Digest != desc2[id].Digest ||
|
||||
desc.Size != desc2[id].Size ||
|
||||
desc.MediaType != desc2[id].MediaType ||
|
||||
desc.Annotations[static.SignatureAnnotationKey] != desc2[id].Annotations[static.SignatureAnnotationKey] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue