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 all 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
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()
})
})
})