Skip to content

Commit

Permalink
Support referrers to a missing manifest
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Mitchell <git@bmitch.net>
  • Loading branch information
sudo-bmitch committed Nov 14, 2023
1 parent 91ba954 commit f695222
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 1 deletion.
30 changes: 30 additions & 0 deletions conformance/03_discovery_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ var test03ContentDiscovery = func() {
BeNumerically(">=", 200),
BeNumerically("<", 300)))
Expect(resp.Header().Get("OCI-Subject")).To(Equal(manifests[4].Digest))

// Populate registry with test references manifest to a non-existent subject
req = client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(refsManifestCLayerArtifactDigest)).
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
SetBody(refsManifestCLayerArtifactContent)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300)))
Expect(resp.Header().Get("OCI-Subject")).To(Equal(manifests[3].Digest))
})
})

Expand Down Expand Up @@ -345,6 +357,22 @@ var test03ContentDiscovery = func() {
Warn("filtering by artifact-type is not implemented")
}
})

g.Specify("GET request to missing manifest should yield 200", func() {
SkipIfDisabled(contentDiscovery)
req := client.NewRequest(reggie.GET, "/v2/<name>/referrers/<digest>",
reggie.WithDigest(manifests[3].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
Expect(resp.Header().Get("Content-Type")).To(Equal("application/vnd.oci.image.index.v1+json"))

var index index
err = json.Unmarshal(resp.Body(), &index)
Expect(err).To(BeNil())
Expect(len(index.Manifests)).To(Equal(1))
Expect(index.Manifests[0].Digest.String()).To(Equal(refsManifestCLayerArtifactDigest))
})
})

g.Context("Teardown", func() {
Expand All @@ -361,6 +389,7 @@ var test03ContentDiscovery = func() {
testTagName,
refsManifestBConfigArtifactDigest,
refsManifestBLayerArtifactDigest,
refsManifestCLayerArtifactDigest,
}
for _, ref := range references {
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(ref))
Expand Down Expand Up @@ -421,6 +450,7 @@ var test03ContentDiscovery = func() {
testTagName,
refsManifestBConfigArtifactDigest,
refsManifestBLayerArtifactDigest,
refsManifestCLayerArtifactDigest,
}
for _, ref := range references {
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(ref))
Expand Down
29 changes: 29 additions & 0 deletions conformance/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ var (
refsManifestBConfigArtifactDigest string
refsManifestBLayerArtifactContent []byte
refsManifestBLayerArtifactDigest string
refsManifestCLayerArtifactContent []byte
refsManifestCLayerArtifactDigest string
refsIndexArtifactContent []byte
refsIndexArtifactDigest string
reportJUnitFilename string
Expand Down Expand Up @@ -440,6 +442,33 @@ func init() {

refsManifestBLayerArtifactDigest = godigest.FromBytes(refsManifestBLayerArtifactContent).String()

// ManifestCLayerArtifact is the same as B but based on a subject that has not been pushed
refsManifestCLayerArtifact := manifest{
SchemaVersion: 2,
MediaType: "application/vnd.oci.image.manifest.v1+json",
ArtifactType: testRefArtifactTypeB,
Config: emptyJSONDescriptor,
Subject: &descriptor{
MediaType: "application/vnd.oci.image.manifest.v1+json",
Size: int64(len(manifests[3].Content)),
Digest: godigest.FromBytes(manifests[3].Content),
},
Layers: []descriptor{
{
MediaType: testRefArtifactTypeB,
Size: int64(len(testRefBlobB)),
Digest: godigest.FromBytes(testRefBlobB),
},
},
}

refsManifestCLayerArtifactContent, err = json.MarshalIndent(&refsManifestCLayerArtifact, "", "\t")
if err != nil {
log.Fatal(err)
}

refsManifestCLayerArtifactDigest = godigest.FromBytes(refsManifestCLayerArtifactContent).String()

testRefArtifactTypeIndex = "application/vnd.food.stand"
refsIndexArtifact := index{
SchemaVersion: 2,
Expand Down
1 change: 0 additions & 1 deletion spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ The descriptors MUST include an `artifactType` field that is set to the value of
If the `artifactType` is empty or missing in the image manifest, the value of `artifactType` MUST be set to the config descriptor `mediaType` value.
The descriptors MUST include annotations from the image manifest.
If a query results in no matching referrers, an empty manifest list MUST be returned.
If a manifest with the digest `<digest>` does not exist, a registry MAY return an empty manifest list.
After a manifest with the digest `<digest>` is pushed, the registry MUST include previously pushed entries in the referrers list.

```json
Expand Down

0 comments on commit f695222

Please sign in to comment.