vendor: remove dep and use vndr
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
16f44674a4
commit
148e72d81e
16131 changed files with 73815 additions and 4235138 deletions
124
vendor/github.com/containers/image/copy/copy_test.go
generated
vendored
124
vendor/github.com/containers/image/copy/copy_test.go
generated
vendored
|
@ -1,124 +0,0 @@
|
|||
package copy
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/containers/image/pkg/compression"
|
||||
"github.com/opencontainers/go-digest"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestNewDigestingReader(t *testing.T) {
|
||||
// Only the failure cases, success is tested in TestDigestingReaderRead below.
|
||||
source := bytes.NewReader([]byte("abc"))
|
||||
for _, input := range []digest.Digest{
|
||||
"abc", // Not algo:hexvalue
|
||||
"crc32:", // Unknown algorithm, empty value
|
||||
"crc32:012345678", // Unknown algorithm
|
||||
"sha256:", // Empty value
|
||||
"sha256:0", // Invalid hex value
|
||||
"sha256:01", // Invalid length of hex value
|
||||
} {
|
||||
_, err := newDigestingReader(source, input)
|
||||
assert.Error(t, err, input.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestDigestingReaderRead(t *testing.T) {
|
||||
cases := []struct {
|
||||
input []byte
|
||||
digest digest.Digest
|
||||
}{
|
||||
{[]byte(""), "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"},
|
||||
{[]byte("abc"), "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"},
|
||||
{make([]byte, 65537, 65537), "sha256:3266304f31be278d06c3bd3eb9aa3e00c59bedec0a890de466568b0b90b0e01f"},
|
||||
}
|
||||
// Valid input
|
||||
for _, c := range cases {
|
||||
source := bytes.NewReader(c.input)
|
||||
reader, err := newDigestingReader(source, c.digest)
|
||||
require.NoError(t, err, c.digest.String())
|
||||
dest := bytes.Buffer{}
|
||||
n, err := io.Copy(&dest, reader)
|
||||
assert.NoError(t, err, c.digest.String())
|
||||
assert.Equal(t, int64(len(c.input)), n, c.digest.String())
|
||||
assert.Equal(t, c.input, dest.Bytes(), c.digest.String())
|
||||
assert.False(t, reader.validationFailed, c.digest.String())
|
||||
}
|
||||
// Modified input
|
||||
for _, c := range cases {
|
||||
source := bytes.NewReader(bytes.Join([][]byte{c.input, []byte("x")}, nil))
|
||||
reader, err := newDigestingReader(source, c.digest)
|
||||
require.NoError(t, err, c.digest.String())
|
||||
dest := bytes.Buffer{}
|
||||
_, err = io.Copy(&dest, reader)
|
||||
assert.Error(t, err, c.digest.String())
|
||||
assert.True(t, reader.validationFailed)
|
||||
}
|
||||
}
|
||||
|
||||
func goDiffIDComputationGoroutineWithTimeout(layerStream io.ReadCloser, decompressor compression.DecompressorFunc) *diffIDResult {
|
||||
ch := make(chan diffIDResult)
|
||||
go diffIDComputationGoroutine(ch, layerStream, nil)
|
||||
timeout := time.After(time.Second)
|
||||
select {
|
||||
case res := <-ch:
|
||||
return &res
|
||||
case <-timeout:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiffIDComputationGoroutine(t *testing.T) {
|
||||
stream, err := os.Open("fixtures/Hello.uncompressed")
|
||||
require.NoError(t, err)
|
||||
res := goDiffIDComputationGoroutineWithTimeout(stream, nil)
|
||||
require.NotNil(t, res)
|
||||
assert.NoError(t, res.err)
|
||||
assert.Equal(t, "sha256:185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969", res.digest.String())
|
||||
|
||||
// Error reading input
|
||||
reader, writer := io.Pipe()
|
||||
writer.CloseWithError(errors.New("Expected error reading input in diffIDComputationGoroutine"))
|
||||
res = goDiffIDComputationGoroutineWithTimeout(reader, nil)
|
||||
require.NotNil(t, res)
|
||||
assert.Error(t, res.err)
|
||||
}
|
||||
|
||||
func TestComputeDiffID(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
filename string
|
||||
decompressor compression.DecompressorFunc
|
||||
result digest.Digest
|
||||
}{
|
||||
{"fixtures/Hello.uncompressed", nil, "sha256:185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969"},
|
||||
{"fixtures/Hello.gz", nil, "sha256:0bd4409dcd76476a263b8f3221b4ce04eb4686dec40bfdcc2e86a7403de13609"},
|
||||
{"fixtures/Hello.gz", compression.GzipDecompressor, "sha256:185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969"},
|
||||
} {
|
||||
stream, err := os.Open(c.filename)
|
||||
require.NoError(t, err, c.filename)
|
||||
defer stream.Close()
|
||||
|
||||
diffID, err := computeDiffID(stream, c.decompressor)
|
||||
require.NoError(t, err, c.filename)
|
||||
assert.Equal(t, c.result, diffID)
|
||||
}
|
||||
|
||||
// Error initializing decompression
|
||||
_, err := computeDiffID(bytes.NewReader([]byte{}), compression.GzipDecompressor)
|
||||
assert.Error(t, err)
|
||||
|
||||
// Error reading input
|
||||
reader, writer := io.Pipe()
|
||||
defer reader.Close()
|
||||
writer.CloseWithError(errors.New("Expected error reading input in computeDiffID"))
|
||||
_, err = computeDiffID(reader, nil)
|
||||
assert.Error(t, err)
|
||||
}
|
164
vendor/github.com/containers/image/copy/manifest_test.go
generated
vendored
164
vendor/github.com/containers/image/copy/manifest_test.go
generated
vendored
|
@ -1,164 +0,0 @@
|
|||
package copy
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/image/docker/reference"
|
||||
"github.com/containers/image/manifest"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestOrderedSet(t *testing.T) {
|
||||
for _, c := range []struct{ input, expected []string }{
|
||||
{[]string{}, []string{}},
|
||||
{[]string{"a", "b", "c"}, []string{"a", "b", "c"}},
|
||||
{[]string{"a", "b", "a", "c"}, []string{"a", "b", "c"}},
|
||||
} {
|
||||
os := newOrderedSet()
|
||||
for _, s := range c.input {
|
||||
os.append(s)
|
||||
}
|
||||
assert.Equal(t, c.expected, os.list, fmt.Sprintf("%#v", c.input))
|
||||
}
|
||||
}
|
||||
|
||||
// fakeImageSource is an implementation of types.Image which only returns itself as a MIME type in Manifest
|
||||
// except that "" means “reading the manifest should fail”
|
||||
type fakeImageSource string
|
||||
|
||||
func (f fakeImageSource) Reference() types.ImageReference {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) Close() error {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) Manifest() ([]byte, string, error) {
|
||||
if string(f) == "" {
|
||||
return nil, "", errors.New("Manifest() directed to fail")
|
||||
}
|
||||
return nil, string(f), nil
|
||||
}
|
||||
func (f fakeImageSource) Signatures() ([][]byte, error) {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) ConfigInfo() types.BlobInfo {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) ConfigBlob() ([]byte, error) {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) OCIConfig() (*v1.Image, error) {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) LayerInfos() []types.BlobInfo {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) EmbeddedDockerReferenceConflicts(ref reference.Named) bool {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) Inspect() (*types.ImageInspectInfo, error) {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) UpdatedImageNeedsLayerDiffIDs(options types.ManifestUpdateOptions) bool {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) UpdatedImage(options types.ManifestUpdateOptions) (types.Image, error) {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) IsMultiImage() bool {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
func (f fakeImageSource) Size() (int64, error) {
|
||||
panic("Unexpected call to a mock function")
|
||||
}
|
||||
|
||||
func TestDetermineManifestConversion(t *testing.T) {
|
||||
supportS1S2OCI := []string{
|
||||
v1.MediaTypeImageManifest,
|
||||
manifest.DockerV2Schema2MediaType,
|
||||
manifest.DockerV2Schema1SignedMediaType,
|
||||
manifest.DockerV2Schema1MediaType,
|
||||
}
|
||||
supportS1OCI := []string{
|
||||
v1.MediaTypeImageManifest,
|
||||
manifest.DockerV2Schema1SignedMediaType,
|
||||
manifest.DockerV2Schema1MediaType,
|
||||
}
|
||||
supportS1S2 := []string{
|
||||
manifest.DockerV2Schema2MediaType,
|
||||
manifest.DockerV2Schema1SignedMediaType,
|
||||
manifest.DockerV2Schema1MediaType,
|
||||
}
|
||||
supportOnlyS1 := []string{
|
||||
manifest.DockerV2Schema1SignedMediaType,
|
||||
manifest.DockerV2Schema1MediaType,
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
description string
|
||||
sourceType string
|
||||
destTypes []string
|
||||
expectedUpdate string
|
||||
expectedOtherCandidates []string
|
||||
}{
|
||||
// Destination accepts anything — no conversion necessary
|
||||
{"s1→anything", manifest.DockerV2Schema1SignedMediaType, nil, "", []string{}},
|
||||
{"s2→anything", manifest.DockerV2Schema2MediaType, nil, "", []string{}},
|
||||
// Destination accepts the unmodified original
|
||||
{"s1→s1s2", manifest.DockerV2Schema1SignedMediaType, supportS1S2, "", []string{manifest.DockerV2Schema2MediaType, manifest.DockerV2Schema1MediaType}},
|
||||
{"s2→s1s2", manifest.DockerV2Schema2MediaType, supportS1S2, "", supportOnlyS1},
|
||||
{"s1→s1", manifest.DockerV2Schema1SignedMediaType, supportOnlyS1, "", []string{manifest.DockerV2Schema1MediaType}},
|
||||
// Conversion necessary, a preferred format is acceptable
|
||||
{"s2→s1", manifest.DockerV2Schema2MediaType, supportOnlyS1, manifest.DockerV2Schema1SignedMediaType, []string{manifest.DockerV2Schema1MediaType}},
|
||||
// Conversion necessary, a preferred format is not acceptable
|
||||
{"s2→OCI", manifest.DockerV2Schema2MediaType, []string{v1.MediaTypeImageManifest}, v1.MediaTypeImageManifest, []string{}},
|
||||
// Conversion necessary, try the preferred formats in order.
|
||||
{
|
||||
"special→s2", "this needs conversion", supportS1S2OCI, manifest.DockerV2Schema2MediaType,
|
||||
[]string{manifest.DockerV2Schema1SignedMediaType, v1.MediaTypeImageManifest, manifest.DockerV2Schema1MediaType},
|
||||
},
|
||||
{
|
||||
"special→s1", "this needs conversion", supportS1OCI, manifest.DockerV2Schema1SignedMediaType,
|
||||
[]string{v1.MediaTypeImageManifest, manifest.DockerV2Schema1MediaType},
|
||||
},
|
||||
{
|
||||
"special→OCI", "this needs conversion", []string{v1.MediaTypeImageManifest, "other options", "with lower priority"}, v1.MediaTypeImageManifest,
|
||||
[]string{"other options", "with lower priority"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
src := fakeImageSource(c.sourceType)
|
||||
mu := types.ManifestUpdateOptions{}
|
||||
preferredMIMEType, otherCandidates, err := determineManifestConversion(&mu, src, c.destTypes, true)
|
||||
require.NoError(t, err, c.description)
|
||||
assert.Equal(t, c.expectedUpdate, mu.ManifestMIMEType, c.description)
|
||||
if c.expectedUpdate == "" {
|
||||
assert.Equal(t, c.sourceType, preferredMIMEType, c.description)
|
||||
} else {
|
||||
assert.Equal(t, c.expectedUpdate, preferredMIMEType, c.description)
|
||||
}
|
||||
assert.Equal(t, c.expectedOtherCandidates, otherCandidates, c.description)
|
||||
}
|
||||
|
||||
// Whatever the input is, with !canModifyManifest we return "keep the original as is"
|
||||
for _, c := range cases {
|
||||
src := fakeImageSource(c.sourceType)
|
||||
mu := types.ManifestUpdateOptions{}
|
||||
preferredMIMEType, otherCandidates, err := determineManifestConversion(&mu, src, c.destTypes, false)
|
||||
require.NoError(t, err, c.description)
|
||||
assert.Equal(t, "", mu.ManifestMIMEType, c.description)
|
||||
assert.Equal(t, c.sourceType, preferredMIMEType, c.description)
|
||||
assert.Equal(t, []string{}, otherCandidates, c.description)
|
||||
}
|
||||
|
||||
// Error reading the manifest — smoke test only.
|
||||
mu := types.ManifestUpdateOptions{}
|
||||
_, _, err := determineManifestConversion(&mu, fakeImageSource(""), supportS1S2, true)
|
||||
assert.Error(t, err)
|
||||
}
|
72
vendor/github.com/containers/image/copy/sign_test.go
generated
vendored
72
vendor/github.com/containers/image/copy/sign_test.go
generated
vendored
|
@ -1,72 +0,0 @@
|
|||
package copy
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/image/directory"
|
||||
"github.com/containers/image/docker"
|
||||
"github.com/containers/image/manifest"
|
||||
"github.com/containers/image/signature"
|
||||
"github.com/containers/image/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
const (
|
||||
testGPGHomeDirectory = "../signature/fixtures"
|
||||
// TestKeyFingerprint is the fingerprint of the private key in testGPGHomeDirectory.
|
||||
// Keep this in sync with signature/fixtures_info_test.go
|
||||
testKeyFingerprint = "1D8230F6CDB6A06716E414C1DB72F2188BB46CC8"
|
||||
)
|
||||
|
||||
func TestCreateSignature(t *testing.T) {
|
||||
manifestBlob := []byte("Something")
|
||||
manifestDigest, err := manifest.Digest(manifestBlob)
|
||||
require.NoError(t, err)
|
||||
|
||||
mech, _, err := signature.NewEphemeralGPGSigningMechanism([]byte{})
|
||||
require.NoError(t, err)
|
||||
defer mech.Close()
|
||||
if err := mech.SupportsSigning(); err != nil {
|
||||
t.Skipf("Signing not supported: %v", err)
|
||||
}
|
||||
|
||||
os.Setenv("GNUPGHOME", testGPGHomeDirectory)
|
||||
defer os.Unsetenv("GNUPGHOME")
|
||||
|
||||
// Signing a directory: reference, which does not have a DockerRefrence(), fails.
|
||||
tempDir, err := ioutil.TempDir("", "signature-dir-dest")
|
||||
require.NoError(t, err)
|
||||
defer os.RemoveAll(tempDir)
|
||||
dirRef, err := directory.NewReference(tempDir)
|
||||
require.NoError(t, err)
|
||||
dirDest, err := dirRef.NewImageDestination(nil)
|
||||
require.NoError(t, err)
|
||||
defer dirDest.Close()
|
||||
_, err = createSignature(dirDest, manifestBlob, testKeyFingerprint, ioutil.Discard)
|
||||
assert.Error(t, err)
|
||||
|
||||
// Set up a docker: reference
|
||||
dockerRef, err := docker.ParseReference("//busybox")
|
||||
require.NoError(t, err)
|
||||
dockerDest, err := dockerRef.NewImageDestination(&types.SystemContext{RegistriesDirPath: "/this/doesnt/exist"})
|
||||
assert.NoError(t, err)
|
||||
defer dockerDest.Close()
|
||||
|
||||
// Signing with an unknown key fails
|
||||
_, err = createSignature(dockerDest, manifestBlob, "this key does not exist", ioutil.Discard)
|
||||
assert.Error(t, err)
|
||||
|
||||
// Success
|
||||
mech, err = signature.NewGPGSigningMechanism()
|
||||
require.NoError(t, err)
|
||||
defer mech.Close()
|
||||
sig, err := createSignature(dockerDest, manifestBlob, testKeyFingerprint, ioutil.Discard)
|
||||
require.NoError(t, err)
|
||||
verified, err := signature.VerifyDockerManifestSignature(sig, manifestBlob, "docker.io/library/busybox:latest", mech, testKeyFingerprint)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, "docker.io/library/busybox:latest", verified.DockerReference)
|
||||
assert.Equal(t, manifestDigest, verified.DockerManifestDigest)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue