-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
conformance: initial commit for refererrers test
https://github.com/opencontainers/distribution-spec/blob/main/spec.md#enabling-the-referrers-api Based off of 01_pull_test.go Fixes #370 Signed-off-by: Ramkumar Chinchani <[email protected]>
- Loading branch information
Showing
4 changed files
with
404 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
package conformance | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
|
||
"github.com/bloodorangeio/reggie" | ||
g "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var test05Referrers = func() { | ||
g.Context(titleReferrers, func() { | ||
|
||
g.Context("Setup", func() { | ||
|
||
g.Specify("Populate registry with test blob", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/") | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
req = client.NewRequest(reggie.PUT, resp.GetRelativeLocation()). | ||
SetQueryParam("digest", configs[4].Digest). | ||
SetHeader("Content-Type", "application/octet-stream"). | ||
SetHeader("Content-Length", configs[4].ContentLength). | ||
SetBody(configs[4].Content) | ||
resp, err = client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300))) | ||
}) | ||
|
||
g.Specify("Populate registry with test layer", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/") | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
req = client.NewRequest(reggie.PUT, resp.GetRelativeLocation()). | ||
SetQueryParam("digest", layerBlobDigest). | ||
SetHeader("Content-Type", "application/octet-stream"). | ||
SetHeader("Content-Length", layerBlobContentLength). | ||
SetBody(layerBlobData) | ||
resp, err = client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300))) | ||
}) | ||
|
||
g.Specify("Populate registry with test manifest", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
tag := testTagName | ||
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>", | ||
reggie.WithReference(tag)). | ||
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). | ||
SetBody(manifests[4].Content) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300))) | ||
}) | ||
|
||
g.Specify("Populate registry with test references blob", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/") | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
req = client.NewRequest(reggie.PUT, resp.GetRelativeLocation()). | ||
SetQueryParam("digest", configs[4].Digest). | ||
SetHeader("Content-Type", "application/octet-stream"). | ||
SetHeader("Content-Length", configs[4].ContentLength). | ||
SetBody(configs[4].Content) | ||
resp, err = client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300))) | ||
}) | ||
|
||
g.Specify("Populate registry with test references layer", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/") | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
req = client.NewRequest(reggie.PUT, resp.GetRelativeLocation()). | ||
SetQueryParam("digest", testRefBlobADigest). | ||
SetHeader("Content-Type", "application/octet-stream"). | ||
SetHeader("Content-Length", testRefBlobALength). | ||
SetBody(testRefBlobA) | ||
resp, err = client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300))) | ||
}) | ||
|
||
g.Specify("Populate registry with test references manifest", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>", | ||
reggie.WithReference(refsArtifactManifestDigest)). | ||
SetHeader("Content-Type", "application/vnd.oci.artifact.manifest.v1+json"). | ||
SetBody(refsArtifactManifestContent) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300))) | ||
}) | ||
}) | ||
|
||
g.Context("Get references", func() { | ||
g.Specify("GET request to nonexistent blob should result in empty 200 response", func() { | ||
SkipIfDisabled(referrers) | ||
req := client.NewRequest(reggie.GET, "/v2/<name>/referrers/<digest>", | ||
reggie.WithDigest(dummyDigest)) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(Equal(http.StatusOK)) | ||
|
||
var index Index | ||
err = json.Unmarshal(resp.Body(), &index) | ||
Expect(err).To(BeNil()) | ||
Expect(len(index.Manifests)).To(BeZero()) | ||
}) | ||
|
||
g.Specify("GET request to existing blob should yield 200", func() { | ||
SkipIfDisabled(referrers) | ||
req := client.NewRequest(reggie.GET, "/v2/<name>/referrers/<digest>", | ||
reggie.WithDigest(manifests[4].Digest)) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(Equal(http.StatusOK)) | ||
if h := resp.Header().Get("Docker-Content-Digest"); h != "" { | ||
Expect(h).To(Equal(configs[4].Digest)) | ||
} | ||
|
||
var index Index | ||
err = json.Unmarshal(resp.Body(), &index) | ||
Expect(err).To(BeNil()) | ||
Expect(len(index.Manifests)).ToNot(BeZero()) | ||
}) | ||
|
||
g.Specify("GET request to existing blob with filter should yield 200", func() { | ||
SkipIfDisabled(referrers) | ||
req := client.NewRequest(reggie.GET, "/v2/<name>/referrers/<digest>", | ||
reggie.WithDigest(manifests[4].Digest)). | ||
SetQueryParam("artifactType", "application/vnd.oci.conformance") | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(Equal(http.StatusOK)) | ||
if h := resp.Header().Get("Docker-Content-Digest"); h != "" { | ||
Expect(h).To(Equal(configs[4].Digest)) | ||
} | ||
|
||
var index Index | ||
err = json.Unmarshal(resp.Body(), &index) | ||
Expect(err).To(BeNil()) | ||
Expect(len(index.Manifests)).ToNot(BeZero()) | ||
|
||
// also check the annotation "org.opencontainers.referrers.filtersApplied" | ||
_, ok := index.Annotations["org.opencontainers.referrers.filtersApplied"] | ||
Expect(ok).To(BeTrue()) | ||
}) | ||
}) | ||
|
||
g.Context("Error codes", func() { | ||
g.Specify("400 response body should contain OCI-conforming JSON message", func() { | ||
SkipIfDisabled(referrers) | ||
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>", | ||
reggie.WithReference("sha256:totallywrong")). | ||
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json"). | ||
SetBody(invalidManifestContent) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAny( | ||
Equal(http.StatusBadRequest), | ||
Equal(http.StatusNotFound))) | ||
if resp.StatusCode() == http.StatusBadRequest { | ||
errorResponses, err := resp.Errors() | ||
Expect(err).To(BeNil()) | ||
|
||
Expect(errorResponses).ToNot(BeEmpty()) | ||
Expect(errorCodes).To(ContainElement(errorResponses[0].Code)) | ||
} | ||
}) | ||
}) | ||
|
||
g.Context("Teardown", func() { | ||
if deleteManifestBeforeBlobs { | ||
g.Specify("Delete manifest created in setup", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifests[4].Digest)) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAny( | ||
SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300), | ||
), | ||
Equal(http.StatusMethodNotAllowed), | ||
)) | ||
}) | ||
} | ||
|
||
g.Specify("Delete config blob created in setup", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.DELETE, "/v2/<name>/blobs/<digest>", reggie.WithDigest(configs[4].Digest)) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAny( | ||
SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300), | ||
), | ||
Equal(http.StatusMethodNotAllowed), | ||
)) | ||
}) | ||
|
||
g.Specify("Delete layer blob created in setup", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.DELETE, "/v2/<name>/blobs/<digest>", reggie.WithDigest(layerBlobDigest)) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAny( | ||
SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300), | ||
), | ||
Equal(http.StatusMethodNotAllowed), | ||
)) | ||
}) | ||
|
||
if !deleteManifestBeforeBlobs { | ||
g.Specify("Delete manifest created in setup", func() { | ||
SkipIfDisabled(referrers) | ||
RunOnlyIf(runReferencesSetup) | ||
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(manifests[4].Digest)) | ||
resp, err := client.Do(req) | ||
Expect(err).To(BeNil()) | ||
Expect(resp.StatusCode()).To(SatisfyAny( | ||
SatisfyAll( | ||
BeNumerically(">=", 200), | ||
BeNumerically("<", 300), | ||
), | ||
Equal(http.StatusMethodNotAllowed), | ||
)) | ||
}) | ||
} | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.