mirror of
https://github.com/containers/skopeo.git
synced 2025-10-22 11:44:05 +00:00
The Docker Registry manifest upload should supply a Content-Type, and guessing from the contents is the easiest we can do right now. Also eliminate dockerutils.manifestMIMEType, it is making it too difficult to use the returned value to be worth the extra safety.
59 lines
1.7 KiB
Go
59 lines
1.7 KiB
Go
package dockerutils
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/projectatomic/skopeo/dockerutils/fixtures"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestGuessManifestMIMEType(t *testing.T) {
|
|
cases := []struct {
|
|
path string
|
|
mimeType string
|
|
}{
|
|
{"v2s2.manifest.json", DockerV2Schema2MIMEType},
|
|
{"v2s1.manifest.json", DockerV2Schema1MIMEType},
|
|
{"v2s1-invalid-signatures.manifest.json", DockerV2Schema1MIMEType},
|
|
{"v2s2nomime.manifest.json", DockerV2Schema2MIMEType}, // 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 := GuessManifestMIMEType(manifest)
|
|
assert.Equal(t, c.mimeType, mimeType)
|
|
}
|
|
}
|
|
|
|
func TestManifestDigest(t *testing.T) {
|
|
cases := []struct {
|
|
path string
|
|
digest string
|
|
}{
|
|
{"v2s2.manifest.json", fixtures.TestV2S2ManifestDigest},
|
|
{"v2s1.manifest.json", fixtures.TestV2S1ManifestDigest},
|
|
}
|
|
for _, c := range cases {
|
|
manifest, err := ioutil.ReadFile(filepath.Join("fixtures", c.path))
|
|
require.NoError(t, err)
|
|
digest, err := ManifestDigest(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 := ManifestDigest(manifest)
|
|
assert.Error(t, err)
|
|
|
|
digest, err = ManifestDigest([]byte{})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", digest)
|
|
}
|