Skip to content

Commit

Permalink
Support sha512 content
Browse files Browse the repository at this point in the history
Signed-off-by: Brandon Mitchell <[email protected]>
  • Loading branch information
sudo-bmitch committed Jul 13, 2024
1 parent 58d034e commit 811619c
Show file tree
Hide file tree
Showing 5 changed files with 361 additions and 17 deletions.
163 changes: 149 additions & 14 deletions conformance/01_pull_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package conformance

import (
"net/http"
"os"

"github.com/bloodorangeio/reggie"
g "github.com/onsi/ginkgo/v2"
Expand All @@ -12,8 +11,6 @@ import (
var test01Pull = func() {
g.Context(titlePull, func() {

var tag string

g.Context("Setup", func() {
g.Specify("Populate registry with test blob", func() {
SkipIfDisabled(pull)
Expand Down Expand Up @@ -72,9 +69,8 @@ var test01Pull = func() {
g.Specify("Populate registry with test manifest", func() {
SkipIfDisabled(pull)
RunOnlyIf(runPullSetup)
tag = testTagName
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(tag)).
reggie.WithReference(testTagName)).
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
SetBody(manifests[0].Content)
resp, err := client.Do(req)
Expand All @@ -98,14 +94,41 @@ var test01Pull = func() {
BeNumerically("<", 300)))
})

g.Specify("Get tag name from environment", func() {
g.Specify("Populate registry with sha512 blobs", func() {
SkipIfDisabled(pull)
RunOnlyIfNot(runPullSetup)
tmp := os.Getenv(envVarTagName)
if tmp != "" {
tag = tmp
RunOnlyIf(runPull512Setup)
for _, blob := range testBlobs["sha512"] {
req := client.NewRequest(reggie.POST, "/v2/<name>/blobs/uploads/").
SetQueryParam("digest-algorithm", "sha512")
resp, err := client.Do(req)
Expect(err).To(BeNil())
req = client.NewRequest(reggie.PUT, resp.GetRelativeLocation()).
SetQueryParam("digest", blob.Digest).
SetHeader("Content-Type", "application/octet-stream").
SetHeader("Content-Length", blob.ContentLength).
SetBody(blob.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 sha512 manifest", func() {
SkipIfDisabled(pull)
RunOnlyIf(runPull512Setup)
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(testTag512Name)).
SetQueryParam("digest", testManifests["sha512"].Digest).
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
SetBody(testManifests["sha512"].Content)
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300)))
})
})

g.Context("Pull blobs", func() {
Expand All @@ -130,6 +153,18 @@ var test01Pull = func() {
}
})

g.Specify("HEAD request to existing sha512 blob should yield 200", func() {
SkipIfDisabled(pull)
req := client.NewRequest(reggie.HEAD, "/v2/<name>/blobs/<digest>",
reggie.WithDigest(testBlobs["sha512"][0].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(testBlobs["sha512"][0].Digest))
}
})

g.Specify("GET nonexistent blob should result in 404 response", func() {
SkipIfDisabled(pull)
req := client.NewRequest(reggie.GET, "/v2/<name>/blobs/<digest>",
Expand All @@ -146,6 +181,15 @@ var test01Pull = func() {
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
})

g.Specify("GET request to existing sha512 blob URL should yield 200", func() {
SkipIfDisabled(pull)
req := client.NewRequest(reggie.GET, "/v2/<name>/blobs/<digest>",
reggie.WithDigest(testBlobs["sha512"][0].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
})
})

g.Context("Pull manifests", func() {
Expand Down Expand Up @@ -182,10 +226,23 @@ var test01Pull = func() {
}
})

g.Specify("HEAD request to sha512 manifest (digest) should yield 200 response", func() {
SkipIfDisabled(pull)
req := client.NewRequest(reggie.HEAD, "/v2/<name>/manifests/<digest>",
reggie.WithDigest(testManifests["sha512"].Digest)).
SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json")
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(testManifests["sha512"].Digest))
}
})

g.Specify("HEAD request to manifest path (tag) should yield 200 response", func() {
SkipIfDisabled(pull)
Expect(tag).ToNot(BeEmpty())
req := client.NewRequest(reggie.HEAD, "/v2/<name>/manifests/<reference>", reggie.WithReference(tag)).
Expect(testTagName).ToNot(BeEmpty())
req := client.NewRequest(reggie.HEAD, "/v2/<name>/manifests/<reference>", reggie.WithReference(testTagName)).
SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json")
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expand All @@ -195,6 +252,19 @@ var test01Pull = func() {
}
})

g.Specify("HEAD request to sha512 manifest (tag) should yield 200 response", func() {
SkipIfDisabled(pull)
Expect(testTag512Name).ToNot(BeEmpty())
req := client.NewRequest(reggie.HEAD, "/v2/<name>/manifests/<reference>", reggie.WithReference(testTag512Name)).
SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json")
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(testManifests["sha512"].Digest))
}
})

g.Specify("GET nonexistent manifest should return 404", func() {
SkipIfDisabled(pull)
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<reference>",
Expand Down Expand Up @@ -222,10 +292,29 @@ var test01Pull = func() {
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
})

g.Specify("GET request to sha512 manifest (digest) should yield 200 response", func() {
SkipIfDisabled(pull)
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<digest>", reggie.WithDigest(testManifests["sha512"].Digest)).
SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json")
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
})

g.Specify("GET request to manifest path (tag) should yield 200 response", func() {
SkipIfDisabled(pull)
Expect(tag).ToNot(BeEmpty())
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<reference>", reggie.WithReference(tag)).
Expect(testTagName).ToNot(BeEmpty())
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<reference>", reggie.WithReference(testTagName)).
SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json")
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(Equal(http.StatusOK))
})

g.Specify("GET request to sha512 manifest (tag) should yield 200 response", func() {
SkipIfDisabled(pull)
Expect(testTag512Name).ToNot(BeEmpty())
req := client.NewRequest(reggie.GET, "/v2/<name>/manifests/<reference>", reggie.WithReference(testTag512Name)).
SetHeader("Accept", "application/vnd.oci.image.manifest.v1+json")
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expand Down Expand Up @@ -285,6 +374,20 @@ var test01Pull = func() {
Equal(http.StatusMethodNotAllowed),
))
})
g.Specify("Delete sha512 manifest created in setup", func() {
SkipIfDisabled(pull)
RunOnlyIf(runPull512Setup)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(testManifests["sha512"].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[0] blob created in setup", func() {
Expand Down Expand Up @@ -331,6 +434,24 @@ var test01Pull = func() {
))
})

for _, blob := range testBlobs["sha512"] {
g.Specify("Delete blob created in setup", func() {
SkipIfDisabled(pull)
RunOnlyIf(runPull512Setup)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/blobs/<digest>", reggie.WithDigest(blob.Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusNotFound),
Equal(http.StatusMethodNotAllowed),
))
})
}

if !deleteManifestBeforeBlobs {
g.Specify("Delete manifest[0] created in setup", func() {
SkipIfDisabled(pull)
Expand Down Expand Up @@ -360,6 +481,20 @@ var test01Pull = func() {
Equal(http.StatusMethodNotAllowed),
))
})
g.Specify("Delete sha512 manifest created in setup", func() {
SkipIfDisabled(pull)
RunOnlyIf(runPull512Setup)
req := client.NewRequest(reggie.DELETE, "/v2/<name>/manifests/<digest>", reggie.WithDigest(testManifests["sha512"].Digest))
resp, err := client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
})
}
})
})
Expand Down
Loading

0 comments on commit 811619c

Please sign in to comment.