Skip to content

Commit

Permalink
conformance: skip check (by default) for zero layers in image manifest (
Browse files Browse the repository at this point in the history
opencontainers#421)

* conformance: always run but warn if empty layer manifest not supported

As per image-spec, since this is a SHOULD (hence recommended) and now
turned off by default.

https://raw.githubusercontent.com/opencontainers/image-spec/main/manifest.md
===

    layers array of objects

    Each item in the array MUST be a descriptor. For portability, layers
    SHOULD have at least one entry.

===

One can enable this test by setting env var:
OCI_SKIP_EMPTY_LAYER_PUSH_TEST=0

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>

* conformance: delete the empty manifest in teardown

emptyLayerManifest is being pushed but not deleted during teardown

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>

---------

Signed-off-by: Ramkumar Chinchani <rchincha@cisco.com>
  • Loading branch information
rchincha authored and sudo-bmitch committed Aug 18, 2023
1 parent c2b8d5c commit 5c4708c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
37 changes: 33 additions & 4 deletions conformance/02_push_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var test02Push = func() {
g.Context(titlePush, func() {

var lastResponse, prevResponse *reggie.Response
var emptyLayerManifestRef string

g.Context("Setup", func() {
// No setup required at this time for push tests
Expand Down Expand Up @@ -350,16 +351,20 @@ var test02Push = func() {

g.Specify("Registry should accept a manifest upload with no layers", func() {
SkipIfDisabled(push)
RunOnlyIfNot(skipEmptyLayerTest)
req := client.NewRequest(reggie.PUT, "/v2/<name>/manifests/<reference>",
reggie.WithReference(emptyLayerTestTag)).
SetHeader("Content-Type", "application/vnd.oci.image.manifest.v1+json").
SetBody(emptyLayerManifestContent)
resp, err := client.Do(req)
Expect(err).To(BeNil())
location := resp.Header().Get("Location")
Expect(location).ToNot(BeEmpty())
Expect(resp.StatusCode()).To(Equal(http.StatusCreated))
if resp.StatusCode() == http.StatusCreated {
location := resp.Header().Get("Location")
emptyLayerManifestRef = location
Expect(location).ToNot(BeEmpty())
Expect(resp.StatusCode()).To(Equal(http.StatusCreated))
} else {
Warn("image manifest with no layers is not supported")
}
})

g.Specify("GET request to manifest URL (digest) should yield 200 response", func() {
Expand Down Expand Up @@ -387,6 +392,18 @@ var test02Push = func() {
),
Equal(http.StatusMethodNotAllowed),
))
if emptyLayerManifestRef != "" {
req = client.NewRequest(reggie.DELETE, emptyLayerManifestRef)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
}
})
}

Expand Down Expand Up @@ -434,6 +451,18 @@ var test02Push = func() {
),
Equal(http.StatusMethodNotAllowed),
))
if emptyLayerManifestRef != "" {
req = client.NewRequest(reggie.DELETE, emptyLayerManifestRef)
resp, err = client.Do(req)
Expect(err).To(BeNil())
Expect(resp.StatusCode()).To(SatisfyAny(
SatisfyAll(
BeNumerically(">=", 200),
BeNumerically("<", 300),
),
Equal(http.StatusMethodNotAllowed),
))
}
})
}
})
Expand Down
13 changes: 10 additions & 3 deletions conformance/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ import (
"math/big"
mathrand "math/rand"
"os"
"runtime"
"strconv"

"github.com/bloodorangeio/reggie"
"github.com/google/uuid"
g "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/formatter"
godigest "github.com/opencontainers/go-digest"
)

Expand Down Expand Up @@ -128,7 +130,6 @@ var (
runPushSetup bool
runContentDiscoverySetup bool
runContentManagementSetup bool
skipEmptyLayerTest bool
deleteManifestBeforeBlobs bool
runAutomaticCrossmountTest bool
automaticCrossmountEnabled bool
Expand Down Expand Up @@ -309,7 +310,6 @@ func init() {
runPushSetup = true
runContentDiscoverySetup = true
runContentManagementSetup = true
skipEmptyLayerTest = false
deleteManifestBeforeBlobs = true

if os.Getenv(envVarTagName) != "" &&
Expand All @@ -322,7 +322,6 @@ func init() {
runContentDiscoverySetup = false
}

skipEmptyLayerTest, _ = strconv.ParseBool(os.Getenv(envVarPushEmptyLayer))
if v, ok := os.LookupEnv(envVarDeleteManifestBeforeBlobs); ok {
deleteManifestBeforeBlobs, _ = strconv.ParseBool(v)
}
Expand Down Expand Up @@ -354,6 +353,14 @@ func RunOnlyIfNot(v bool) {
}
}

func Warn(message string) {
// print message
fmt.Fprint(os.Stderr, formatter.Fi(2, "\n{{magenta}}WARNING: %s\n{{/}}", message))
// print file:line
_, file, line, _ := runtime.Caller(1)
fmt.Fprint(os.Stderr, formatter.Fi(2, "\n%s:%d\n", file, line))
}

func generateSkipReport() string {
buf := new(bytes.Buffer)
fmt.Fprintf(buf, "you have skipped this test; if this is an error, check your environment variable settings:\n")
Expand Down

0 comments on commit 5c4708c

Please sign in to comment.