If the media type for a manifest is unrecognized, default to schema1
This is needed for compatibility with some third-party registries that send an inappropriate Content-Type header such as text/html. Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
parent
08650825fe
commit
c01fe47231
@ -96,7 +96,10 @@ func UnmarshalManifest(ctHeader string, p []byte) (Manifest, Descriptor, error)
|
|||||||
|
|
||||||
unmarshalFunc, ok := mappings[mediatype]
|
unmarshalFunc, ok := mappings[mediatype]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, Descriptor{}, fmt.Errorf("unsupported manifest mediatype: %s", mediatype)
|
unmarshalFunc, ok = mappings[""]
|
||||||
|
if !ok {
|
||||||
|
return nil, Descriptor{}, fmt.Errorf("unsupported manifest mediatype and no default available: %s", mediatype)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return unmarshalFunc(p)
|
return unmarshalFunc(p)
|
||||||
|
@ -610,7 +610,7 @@ func addTestManifestWithEtag(repo, reference string, content []byte, m *testutil
|
|||||||
*m = append(*m, testutil.RequestResponseMapping{Request: getReqWithEtag, Response: getRespWithEtag})
|
*m = append(*m, testutil.RequestResponseMapping{Request: getReqWithEtag, Response: getRespWithEtag})
|
||||||
}
|
}
|
||||||
|
|
||||||
func addTestManifest(repo, reference string, content []byte, m *testutil.RequestResponseMap) {
|
func addTestManifest(repo, reference string, mediatype string, content []byte, m *testutil.RequestResponseMap) {
|
||||||
*m = append(*m, testutil.RequestResponseMapping{
|
*m = append(*m, testutil.RequestResponseMapping{
|
||||||
Request: testutil.Request{
|
Request: testutil.Request{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
@ -622,7 +622,7 @@ func addTestManifest(repo, reference string, content []byte, m *testutil.Request
|
|||||||
Headers: http.Header(map[string][]string{
|
Headers: http.Header(map[string][]string{
|
||||||
"Content-Length": {fmt.Sprint(len(content))},
|
"Content-Length": {fmt.Sprint(len(content))},
|
||||||
"Last-Modified": {time.Now().Add(-1 * time.Second).Format(time.ANSIC)},
|
"Last-Modified": {time.Now().Add(-1 * time.Second).Format(time.ANSIC)},
|
||||||
"Content-Type": {schema1.MediaTypeSignedManifest},
|
"Content-Type": {mediatype},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -636,7 +636,7 @@ func addTestManifest(repo, reference string, content []byte, m *testutil.Request
|
|||||||
Headers: http.Header(map[string][]string{
|
Headers: http.Header(map[string][]string{
|
||||||
"Content-Length": {fmt.Sprint(len(content))},
|
"Content-Length": {fmt.Sprint(len(content))},
|
||||||
"Last-Modified": {time.Now().Add(-1 * time.Second).Format(time.ANSIC)},
|
"Last-Modified": {time.Now().Add(-1 * time.Second).Format(time.ANSIC)},
|
||||||
"Content-Type": {schema1.MediaTypeSignedManifest},
|
"Content-Type": {mediatype},
|
||||||
}),
|
}),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -678,8 +678,9 @@ func TestV1ManifestFetch(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
addTestManifest(repo, dgst.String(), pl, &m)
|
addTestManifest(repo, dgst.String(), schema1.MediaTypeSignedManifest, pl, &m)
|
||||||
addTestManifest(repo, "latest", pl, &m)
|
addTestManifest(repo, "latest", schema1.MediaTypeSignedManifest, pl, &m)
|
||||||
|
addTestManifest(repo, "badcontenttype", "text/html", pl, &m)
|
||||||
|
|
||||||
e, c := testServer(m)
|
e, c := testServer(m)
|
||||||
defer c()
|
defer c()
|
||||||
@ -726,6 +727,19 @@ func TestV1ManifestFetch(t *testing.T) {
|
|||||||
if err = checkEqualManifest(v1manifest, m1); err != nil {
|
if err = checkEqualManifest(v1manifest, m1); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
manifest, err = ms.Get(ctx, dgst, WithTag("badcontenttype"))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
v1manifest, ok = manifest.(*schema1.SignedManifest)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Unexpected manifest type from Get: %T", manifest)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = checkEqualManifest(v1manifest, m1); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestManifestFetchWithEtag(t *testing.T) {
|
func TestManifestFetchWithEtag(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user