forked from barak/tarpoon
Add glide.yaml and vendor deps
This commit is contained in:
parent
db918f12ad
commit
5b3d5e81bd
18880 changed files with 5166045 additions and 1 deletions
123
vendor/github.com/containers/image/manifest/manifest_test.go
generated
vendored
Normal file
123
vendor/github.com/containers/image/manifest/manifest_test.go
generated
vendored
Normal file
|
|
@ -0,0 +1,123 @@
|
|||
package manifest
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/libtrust"
|
||||
imgspecv1 "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestGuessMIMEType(t *testing.T) {
|
||||
cases := []struct {
|
||||
path string
|
||||
mimeType string
|
||||
}{
|
||||
{"ociv1.manifest.json", imgspecv1.MediaTypeImageManifest},
|
||||
{"ociv1list.manifest.json", imgspecv1.MediaTypeImageManifestList},
|
||||
{"v2s2.manifest.json", DockerV2Schema2MediaType},
|
||||
{"v2list.manifest.json", DockerV2ListMediaType},
|
||||
{"v2s1.manifest.json", DockerV2Schema1SignedMediaType},
|
||||
{"v2s1-unsigned.manifest.json", DockerV2Schema1MediaType},
|
||||
{"v2s1-invalid-signatures.manifest.json", DockerV2Schema1SignedMediaType},
|
||||
{"v2s2nomime.manifest.json", DockerV2Schema2MediaType}, // It is unclear whether this one is legal, but we should guess v2s2 if anything at all.
|
||||
{"unknown-version.manifest.json", ""},
|
||||
{"non-json.manifest.json", ""}, // Not a manifest (nor JSON) at all
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
manifest, err := ioutil.ReadFile(filepath.Join("fixtures", c.path))
|
||||
require.NoError(t, err)
|
||||
mimeType := GuessMIMEType(manifest)
|
||||
assert.Equal(t, c.mimeType, mimeType, c.path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDigest(t *testing.T) {
|
||||
cases := []struct {
|
||||
path string
|
||||
digest string
|
||||
}{
|
||||
{"v2s2.manifest.json", TestDockerV2S2ManifestDigest},
|
||||
{"v2s1.manifest.json", TestDockerV2S1ManifestDigest},
|
||||
{"v2s1-unsigned.manifest.json", TestDockerV2S1UnsignedManifestDigest},
|
||||
}
|
||||
for _, c := range cases {
|
||||
manifest, err := ioutil.ReadFile(filepath.Join("fixtures", c.path))
|
||||
require.NoError(t, err)
|
||||
digest, err := Digest(manifest)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, c.digest, digest)
|
||||
}
|
||||
|
||||
manifest, err := ioutil.ReadFile("fixtures/v2s1-invalid-signatures.manifest.json")
|
||||
require.NoError(t, err)
|
||||
digest, err := Digest(manifest)
|
||||
assert.Error(t, err)
|
||||
|
||||
digest, err = Digest([]byte{})
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", digest)
|
||||
}
|
||||
|
||||
func TestMatchesDigest(t *testing.T) {
|
||||
cases := []struct {
|
||||
path string
|
||||
digest string
|
||||
result bool
|
||||
}{
|
||||
// Success
|
||||
{"v2s2.manifest.json", TestDockerV2S2ManifestDigest, true},
|
||||
{"v2s1.manifest.json", TestDockerV2S1ManifestDigest, true},
|
||||
// No match (switched s1/s2)
|
||||
{"v2s2.manifest.json", TestDockerV2S1ManifestDigest, false},
|
||||
{"v2s1.manifest.json", TestDockerV2S2ManifestDigest, false},
|
||||
// Unrecognized algorithm
|
||||
{"v2s2.manifest.json", "md5:2872f31c5c1f62a694fbd20c1e85257c", false},
|
||||
// Mangled format
|
||||
{"v2s2.manifest.json", TestDockerV2S2ManifestDigest + "abc", false},
|
||||
{"v2s2.manifest.json", TestDockerV2S2ManifestDigest[:20], false},
|
||||
{"v2s2.manifest.json", "", false},
|
||||
}
|
||||
for _, c := range cases {
|
||||
manifest, err := ioutil.ReadFile(filepath.Join("fixtures", c.path))
|
||||
require.NoError(t, err)
|
||||
res, err := MatchesDigest(manifest, c.digest)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, c.result, res)
|
||||
}
|
||||
|
||||
manifest, err := ioutil.ReadFile("fixtures/v2s1-invalid-signatures.manifest.json")
|
||||
require.NoError(t, err)
|
||||
// Even a correct SHA256 hash is rejected if we can't strip the JSON signature.
|
||||
hash := sha256.Sum256(manifest)
|
||||
res, err := MatchesDigest(manifest, "sha256:"+hex.EncodeToString(hash[:]))
|
||||
assert.False(t, res)
|
||||
assert.Error(t, err)
|
||||
|
||||
res, err = MatchesDigest([]byte{}, "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
|
||||
assert.True(t, res)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestAddDummyV2S1Signature(t *testing.T) {
|
||||
manifest, err := ioutil.ReadFile("fixtures/v2s1-unsigned.manifest.json")
|
||||
require.NoError(t, err)
|
||||
|
||||
signedManifest, err := AddDummyV2S1Signature(manifest)
|
||||
require.NoError(t, err)
|
||||
|
||||
sig, err := libtrust.ParsePrettySignature(signedManifest, "signatures")
|
||||
require.NoError(t, err)
|
||||
signaturePayload, err := sig.Payload()
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, manifest, signaturePayload)
|
||||
|
||||
_, err = AddDummyV2S1Signature([]byte("}this is invalid JSON"))
|
||||
assert.Error(t, err)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue