mirror of
https://github.com/distribution/distribution.git
synced 2026-10-28 10:15:27 +08:00
wire validateManifestList into manifest list unmarshal
Signed-off-by: alhudz <al.hudz.k@gmail.com>
This commit is contained in:
1 parent
af1b4b4e9a
commit
b5ffd21301
2 files changed
+21
No files matched your search
@@ -36,6 +36,10 @@ func init() {
|
||||
}
|
||||
|
||||
func unmarshalManifestList(b []byte) (distribution.Manifest, v1.Descriptor, error) {
|
||||
if err := validateManifestList(b); err != nil {
|
||||
return nil, v1.Descriptor{}, err
|
||||
}
|
||||
|
||||
m := &DeserializedManifestList{}
|
||||
if err := m.UnmarshalJSON(b); err != nil {
|
||||
return nil, v1.Descriptor{}, err
|
||||
|
||||
@@ -204,3 +204,20 @@ func TestValidateManifestList(t *testing.T) {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestUnmarshalManifestListRejectsManifest(t *testing.T) {
|
||||
// A document carrying the manifest-list media type but also image-manifest
|
||||
// fields (config/layers) is ambiguous and must be rejected by the
|
||||
// registered unmarshal path, not just by validateManifestList in isolation.
|
||||
b := []byte(`{
|
||||
"schemaVersion": 2,
|
||||
"mediaType": "` + MediaTypeManifestList + `",
|
||||
"config": {"size": 1},
|
||||
"layers": [{"size": 2}],
|
||||
"manifests": [{"size": 3}]
|
||||
}`)
|
||||
|
||||
if _, _, err := distribution.UnmarshalManifest(MediaTypeManifestList, b); err == nil {
|
||||
t.Fatal("ambiguous manifest/list document should not unmarshal as a manifest list")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user