Skip to content

Commit

Permalink
fix: add error when using media type assertion with oci layout (#890)
Browse files Browse the repository at this point in the history
Signed-off-by: wangxiaoxuan273 <wangxiaoxuan119@gmail.com>
  • Loading branch information
wangxiaoxuan273 authored Mar 16, 2023
1 parent a55201b commit dbc0cec
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 44 deletions.
2 changes: 2 additions & 0 deletions cmd/oras/manifest/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ func fetchManifest(opts fetchOptions) (fetchErr error) {
}
if repo, ok := target.(*remote.Repository); ok {
repo.ManifestMediaTypes = opts.mediaTypes
} else if opts.mediaTypes != nil {
return fmt.Errorf("`--media-type` cannot be used with `--oci-layout` at the same time")
}

src, err := opts.CachedTarget(target)
Expand Down
58 changes: 14 additions & 44 deletions test/e2e/suite/command/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ var _ = Describe("Common registry users:", func() {
ExpectFailure().
MatchErrKeyWords(multi_arch.LinuxAMD64.Digest.String(), "error: ", "not found").Exec()
})
It("should fail if no manifest tag or digest is provided", func() {
ORAS("manifest", "fetch", RegistryRef(Host, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "invalid image reference").Exec()
})
})

When("running `manifest push`", func() {
Expand Down Expand Up @@ -331,6 +334,9 @@ var _ = Describe("Common registry users:", func() {
ORAS("manifest", "fetch-config", "--descriptor", "--platform", "linux/amd64", RegistryRef(Host, ImageRepo, multi_arch.Tag)).
MatchContent(multi_arch.LinuxAMD64ConfigDesc).Exec()
})
It("should fail if no manifest tag or digest is provided", func() {
ORAS("manifest", "fetch-config", RegistryRef(Host, ImageRepo, "")).ExpectFailure().MatchErrKeyWords("Error:", "invalid image reference").Exec()
})
})

When("running `manifest delete`", func() {
Expand Down Expand Up @@ -440,52 +446,16 @@ var _ = Describe("OCI image layout users:", func() {
"--platform", "linux/amd64", "--descriptor").
MatchContent(multi_arch.LinuxAMD64IndexDesc).Exec()
})
It("should fetch index content with media type assertion", func() {
root := prepare()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Tag),
"--media-type", "application/vnd.oci.image.index.v1+json").
MatchContent(multi_arch.Manifest).Exec()
})
It("should fetch index descriptor with media type assertion", func() {
root := prepare()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Tag),
"--media-type", "application/vnd.oci.image.index.v1+json", "--descriptor").
MatchContent(multi_arch.Descriptor).Exec()
})
It("should fetch image content with media type assertion and platform selection", func() {
It("should fail to fetch image if media type assertion is used", func() {
root := prepare()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Tag),
"--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json").
MatchContent(multi_arch.LinuxAMD64Manifest).Exec()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Digest),
"--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json", "--descriptor").
MatchContent(multi_arch.LinuxAMD64IndexDesc).Exec()
})
It("should fetch image descriptor with media type assertion and platform selection", func() {
root := prepare()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Tag),
"--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json", "--descriptor").
MatchContent(multi_arch.LinuxAMD64IndexDesc).Exec()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Digest),
"--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.index.v1+json,application/vnd.oci.image.manifest.v1+json", "--descriptor").
MatchContent(multi_arch.LinuxAMD64IndexDesc).Exec()
})
It("should fetch image content with media type assertion and platform validation", func() {
root := prepare()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.LinuxAMD64.Digest.String()),
"--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.manifest.v1+json").
MatchContent(multi_arch.LinuxAMD64Manifest).Exec()
})
It("should fetch image descriptor with media type assertion and platform validation", func() {
root := prepare()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.LinuxAMD64.Digest.String()),
"--platform", "linux/amd64", "--media-type", "application/vnd.oci.image.manifest.v1+json", "--descriptor").
MatchContent(multi_arch.LinuxAMD64DescStr).Exec()
ORAS("manifest", "fetch", Flags.Layout, LayoutRef(root, multi_arch.Digest), "--media-type", "application/vnd.oci.image.manifest.v1+json").
ExpectFailure().
MatchErrKeyWords("Error", "--media-type", "--oci-layout").Exec()
})
It("should fail fetching manifest without reference provided", func() {
It("should fail if no manifest tag or digest is provided", func() {
root := prepare()
ORAS("manifest", "fetch", Flags.Layout, root).ExpectFailure().
MatchErrKeyWords("Error:").Exec()
MatchErrKeyWords("Error:", "invalid image reference").Exec()
})
})

Expand Down Expand Up @@ -528,9 +498,9 @@ var _ = Describe("OCI image layout users:", func() {
ORAS("manifest", "fetch-config", "--descriptor", "--platform", "linux/amd64", Flags.Layout, LayoutRef(root, multi_arch.Tag)).
MatchContent(multi_arch.LinuxAMD64ConfigDesc).Exec()
})
It("should fail if no manifest reference provided", func() {
It("should fail if no manifest tag or digest is provided", func() {
root := prepare(foobar.Tag)
ORAS("manifest", "fetch-config", Flags.Layout, root).ExpectFailure().Exec()
ORAS("manifest", "fetch-config", Flags.Layout, root).ExpectFailure().MatchErrKeyWords("Error:", "invalid image reference").Exec()
})
})
})

0 comments on commit dbc0cec

Please sign in to comment.