Skip to content

Commit

Permalink
should validate manifest own media type of JSON object
Browse files Browse the repository at this point in the history
Signed-off-by: xiekeyang <xiekeyang@huawei.com>
  • Loading branch information
xiekeyang committed Nov 8, 2016
1 parent dc5e6b1 commit 7b13896
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
18 changes: 18 additions & 0 deletions schema/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,24 @@ func TestManifest(t *testing.T) {
fail: false,
},

// expected failure strictly: unknown manifest.mediaType
{
strict: true,
manifest: `
{
"schemaVersion": 2,
"mediaType": "application/customized+json",
"config": {
"mediaType": "application/vnd.oci.image.config.v1+json",
"size": 1470,
"digest": "sha256:c86f7763873b6c0aae22d963bab59b4f5debbed6685761b5951584f6efb0633b"
},
"layers": []
}
`,
fail: true,
},

// expected failure strictly: unknown config.mediaType
{
strict: true,
Expand Down
8 changes: 8 additions & 0 deletions schema/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ func validateManifestDescendants(r io.Reader, strict bool) error {
return errors.Wrap(err, "manifest format mismatch")
}

if header.MediaType != string(v1.MediaTypeImageManifest) {
msg := fmt.Sprintf("manifest has an unknown media type: %s\n", header.MediaType)
if strict {
return fmt.Errorf("%s", msg)
}
fmt.Printf("warning: %s\n", msg)
}

if header.Config.MediaType != string(v1.MediaTypeImageConfig) {
msg := fmt.Sprintf("config %s has an unknown media type: %s", header.Config.Digest, header.Config.MediaType)
if strict {
Expand Down

0 comments on commit 7b13896

Please sign in to comment.