Skip to content

Commit

Permalink
Merge pull request opencontainers#1022 from vbatts/fix_descriptor_schema
Browse files Browse the repository at this point in the history
descriptor schema: add missing data and artifactType definitions
  • Loading branch information
sajayantony authored and KilloKoxu committed Mar 11, 2023
1 parent 0126d30 commit f55e368
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
8 changes: 8 additions & 0 deletions schema/content-descriptor.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
"description": "a list of urls from which this object may be downloaded",
"$ref": "defs-descriptor.json#/definitions/urls"
},
"data": {
"description": "an embedding of the targeted content (base64 encoded)",
"$ref": "defs.json#/definitions/base64"
},
"artifactType": {
"description": "the IANA media type of this artifact",
"$ref": "defs-descriptor.json#/definitions/mediaType"
},
"annotations": {
"id": "https://opencontainers.org/schema/image/descriptor/annotations",
"$ref": "defs-descriptor.json#/definitions/annotations"
Expand Down
6 changes: 6 additions & 0 deletions schema/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
}
]
},
"base64": {
"type": "string",
"media": {
"binaryEncoding": "base64"
}
},
"stringPointer": {
"oneOf": [
{
Expand Down
51 changes: 51 additions & 0 deletions schema/descriptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,46 @@ func TestDescriptor(t *testing.T) {
`,
fail: true,
},

// expected success: artifactType is present and an IANA compliant value
{
descriptor: `
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"artifactType": "application/vnd.oci.image.manifest.v1+json",
"size": 7682,
"digest": "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270"
}
`,
fail: false,
},

// expected failure: artifactType does not match pattern (invalid first subtype character)
{
descriptor: `
{
"mediaType": "application/vnd.oci.image.manifest.v1+json",
"artifactType": "foo/.bar",
"size": 7682,
"digest": "sha256:5b0bcabd1ed22e9fb1310cf6c2dec7cdef19f0ad69efa1f392e94a4333501270"
}
`,
fail: true,
},

// expected success: data field is present and has base64 content
{
descriptor: `
{
"mediaType": "text/plain",
"size": 34,
"data": "aHR0cHM6Ly9naXRodWIuY29tL29wZW5jb250YWluZXJzCg==",
"digest": "sha256:2690af59371e9eca9453dc29882643f46e5ca47ec2862bd517b5e17351325153"
}
`,
fail: false,
},

{
descriptor: `{
"mediaType": "application/vnd.oci.image.config.v1+json",
Expand Down Expand Up @@ -292,6 +332,17 @@ func TestDescriptor(t *testing.T) {
"mediaType": "application/vnd.oci.image.config.v1+json"
}`,
},
{
descriptor: `
{
"mediaType": "text/plain",
"size": 34,
"data": "aHR0cHM6Ly9naXRodWIuY29tL29wZW5jb250YWluZXJzCg",
"digest": "sha256:2690af59371e9eca9453dc29882643f46e5ca47ec2862bd517b5e17351325153"
}
`,
fail: true,
},
} {
r := strings.NewReader(tt.descriptor)
err := schema.ValidatorMediaTypeDescriptor.Validate(r)
Expand Down

0 comments on commit f55e368

Please sign in to comment.