Skip to content

Commit

Permalink
Merge pull request #2651 from mikebrow/manifest-version-test-on-put
Browse files Browse the repository at this point in the history
adds validation testing for schema version values
  • Loading branch information
dmp42 authored Aug 20, 2018
2 parents 6411087 + 2fdb2ac commit 53bd46a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
4 changes: 4 additions & 0 deletions registry/storage/manifestlisthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (ms *manifestListHandler) Put(ctx context.Context, manifestList distributio
func (ms *manifestListHandler) verifyManifest(ctx context.Context, mnfst manifestlist.DeserializedManifestList, skipDependencyVerification bool) error {
var errs distribution.ErrManifestVerification

if mnfst.SchemaVersion != 2 {
return fmt.Errorf("unrecognized manifest list schema version %d", mnfst.SchemaVersion)
}

if !skipDependencyVerification {
// This manifest service is different from the blob service
// returned by Blob. It uses a linked blob store to ensure that
Expand Down
15 changes: 14 additions & 1 deletion registry/storage/manifeststore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,22 @@ func testOCIManifestStorage(t *testing.T, testname string, includeMediaTypes boo
t.Fatalf("%s: unexpected error generating manifest: %v", testname, err)
}

// before putting the manifest test for proper handling of SchemaVersion

if manifest.(*ocischema.DeserializedManifest).Manifest.SchemaVersion != 2 {
t.Fatalf("%s: unexpected error generating default version for oci manifest", testname)
}
manifest.(*ocischema.DeserializedManifest).Manifest.SchemaVersion = 0

var manifestDigest digest.Digest
if manifestDigest, err = ms.Put(ctx, manifest); err != nil {
t.Fatalf("%s: unexpected error putting manifest: %v", testname, err)
if err.Error() != "unrecognized manifest schema version 0" {
t.Fatalf("%s: unexpected error putting manifest: %v", testname, err)
}
manifest.(*ocischema.DeserializedManifest).Manifest.SchemaVersion = 2
if manifestDigest, err = ms.Put(ctx, manifest); err != nil {
t.Fatalf("%s: unexpected error putting manifest: %v", testname, err)
}
}

// Also create an image index that contains the manifest
Expand Down
4 changes: 4 additions & 0 deletions registry/storage/ocimanifesthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ func (ms *ocischemaManifestHandler) Put(ctx context.Context, manifest distributi
func (ms *ocischemaManifestHandler) verifyManifest(ctx context.Context, mnfst ocischema.DeserializedManifest, skipDependencyVerification bool) error {
var errs distribution.ErrManifestVerification

if mnfst.Manifest.SchemaVersion != 2 {
return fmt.Errorf("unrecognized manifest schema version %d", mnfst.Manifest.SchemaVersion)
}

if skipDependencyVerification {
return nil
}
Expand Down
4 changes: 4 additions & 0 deletions registry/storage/schema2manifesthandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ func (ms *schema2ManifestHandler) Put(ctx context.Context, manifest distribution
func (ms *schema2ManifestHandler) verifyManifest(ctx context.Context, mnfst schema2.DeserializedManifest, skipDependencyVerification bool) error {
var errs distribution.ErrManifestVerification

if mnfst.Manifest.SchemaVersion != 2 {
return fmt.Errorf("unrecognized manifest schema version %d", mnfst.Manifest.SchemaVersion)
}

if skipDependencyVerification {
return nil
}
Expand Down

0 comments on commit 53bd46a

Please sign in to comment.