Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add error when using media type assertion with oci layout #890

Merged
merged 3 commits into from
Mar 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
44 changes: 4 additions & 40 deletions test/e2e/suite/command/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,47 +440,11 @@ 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() {
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),
"--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() {
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() {
root := prepare()
Expand Down