From 70ac446f2703f85a2da598e05cc23450f24e2aba Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 15:09:30 +0800 Subject: [PATCH 01/12] feat: return error when header flags used on oci layout Signed-off-by: Billy Zha --- cmd/oras/internal/option/target.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index bf0a4650a..9109f8f6a 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -17,6 +17,7 @@ package option import ( "context" + "errors" "fmt" "os" "strings" @@ -86,6 +87,9 @@ func (opts *Target) Parse() error { switch { case opts.isOCILayout: opts.Type = TargetTypeOCILayout + if len(opts.headerFlags) != 0 { + return errors.New("customer headers([--{from|to}]-header/H cannot be used on OCI image layout target") + } return nil default: opts.Type = TargetTypeRemote From 2515e8733e33298fa46a2433a1990460b044d7e6 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 15:51:44 +0800 Subject: [PATCH 02/12] add e2e tests Signed-off-by: Billy Zha --- cmd/oras/internal/option/target.go | 2 +- test/e2e/suite/command/customer_header.go | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/e2e/suite/command/customer_header.go diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index 9109f8f6a..2c2f55ddc 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -88,7 +88,7 @@ func (opts *Target) Parse() error { case opts.isOCILayout: opts.Type = TargetTypeOCILayout if len(opts.headerFlags) != 0 { - return errors.New("customer headers([--{from|to}]-header/H cannot be used on OCI image layout target") + return errors.New("customer header([--{from|to}]-header/H) cannot be used on OCI image layout target") } return nil default: diff --git a/test/e2e/suite/command/customer_header.go b/test/e2e/suite/command/customer_header.go new file mode 100644 index 000000000..90bfdb199 --- /dev/null +++ b/test/e2e/suite/command/customer_header.go @@ -0,0 +1,31 @@ +/* +Copyright The ORAS Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package command + +import ( + . "github.com/onsi/ginkgo/v2" + . "oras.land/oras/test/e2e/internal/utils" +) + +var _ = Describe("OCI image layout users:", func() { + When("custom header is provided", func() { + It("should fail attach", func() { + ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example"). + WithWorkDir(GinkgoT().TempDir()). + ExpectFailure(). + MatchErrKeyWords("customer header"). + Exec() + }) + }) +}) From 9899ac6e403322f5db5090345c5c52c76971cc00 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 15:52:47 +0800 Subject: [PATCH 03/12] fix e2e Signed-off-by: Billy Zha --- test/e2e/suite/command/customer_header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/suite/command/customer_header.go b/test/e2e/suite/command/customer_header.go index 90bfdb199..1e601b1ab 100644 --- a/test/e2e/suite/command/customer_header.go +++ b/test/e2e/suite/command/customer_header.go @@ -21,7 +21,7 @@ import ( var _ = Describe("OCI image layout users:", func() { When("custom header is provided", func() { It("should fail attach", func() { - ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example"). + ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example", "--oci-layout"). WithWorkDir(GinkgoT().TempDir()). ExpectFailure(). MatchErrKeyWords("customer header"). From 407a658b9fe18667104f2fb5fbbb4b3751b3703b Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 16:13:19 +0800 Subject: [PATCH 04/12] fix e2e Signed-off-by: Billy Zha --- test/e2e/suite/command/customer_header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/suite/command/customer_header.go b/test/e2e/suite/command/customer_header.go index 1e601b1ab..cf3448410 100644 --- a/test/e2e/suite/command/customer_header.go +++ b/test/e2e/suite/command/customer_header.go @@ -21,7 +21,7 @@ import ( var _ = Describe("OCI image layout users:", func() { When("custom header is provided", func() { It("should fail attach", func() { - ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example", "--oci-layout"). + ORAS("attach", ".:test", "-a", "test=true", "--artifact-type", "doc/example", "--oci-layout", "-H=foo:bar"). WithWorkDir(GinkgoT().TempDir()). ExpectFailure(). MatchErrKeyWords("customer header"). From 426813a4aa677df25e6d6810831711110a78022b Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 2 Mar 2023 07:46:19 +0800 Subject: [PATCH 05/12] improve prompt message Signed-off-by: Billy Zha --- cmd/oras/internal/option/target.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index 2c2f55ddc..e2939f448 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -88,7 +88,7 @@ func (opts *Target) Parse() error { case opts.isOCILayout: opts.Type = TargetTypeOCILayout if len(opts.headerFlags) != 0 { - return errors.New("customer header([--{from|to}]-header/H) cannot be used on OCI image layout target") + return errors.New("customer header flags cannot be used on an OCI image layout target") } return nil default: From 201f96a0f28bdd9e3d3f4e964f391ae6052242c6 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 15:09:30 +0800 Subject: [PATCH 06/12] feat: return error when header flags used on oci layout Signed-off-by: Billy Zha --- cmd/oras/internal/option/target.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index fe4c066f9..31c1d2cbb 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -17,6 +17,7 @@ package option import ( "context" + "errors" "fmt" "os" "strings" @@ -86,6 +87,9 @@ func (opts *Target) Parse() error { switch { case opts.isOCILayout: opts.Type = TargetTypeOCILayout + if len(opts.headerFlags) != 0 { + return errors.New("customer headers([--{from|to}]-header/H cannot be used on OCI image layout target") + } return nil default: opts.Type = TargetTypeRemote From 0ed78dcb5c89e6d03ea1ba0e45fc6a420583f45a Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 15:51:44 +0800 Subject: [PATCH 07/12] add e2e tests Signed-off-by: Billy Zha --- cmd/oras/internal/option/target.go | 2 +- test/e2e/suite/command/customer_header.go | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/e2e/suite/command/customer_header.go diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index 31c1d2cbb..4a4f5614a 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -88,7 +88,7 @@ func (opts *Target) Parse() error { case opts.isOCILayout: opts.Type = TargetTypeOCILayout if len(opts.headerFlags) != 0 { - return errors.New("customer headers([--{from|to}]-header/H cannot be used on OCI image layout target") + return errors.New("customer header([--{from|to}]-header/H) cannot be used on OCI image layout target") } return nil default: diff --git a/test/e2e/suite/command/customer_header.go b/test/e2e/suite/command/customer_header.go new file mode 100644 index 000000000..90bfdb199 --- /dev/null +++ b/test/e2e/suite/command/customer_header.go @@ -0,0 +1,31 @@ +/* +Copyright The ORAS Authors. +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at +http://www.apache.org/licenses/LICENSE-2.0 +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package command + +import ( + . "github.com/onsi/ginkgo/v2" + . "oras.land/oras/test/e2e/internal/utils" +) + +var _ = Describe("OCI image layout users:", func() { + When("custom header is provided", func() { + It("should fail attach", func() { + ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example"). + WithWorkDir(GinkgoT().TempDir()). + ExpectFailure(). + MatchErrKeyWords("customer header"). + Exec() + }) + }) +}) From f1b873f0f1c75fe5ff9db4be680f388b8a294621 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 15:52:47 +0800 Subject: [PATCH 08/12] fix e2e Signed-off-by: Billy Zha --- test/e2e/suite/command/customer_header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/suite/command/customer_header.go b/test/e2e/suite/command/customer_header.go index 90bfdb199..1e601b1ab 100644 --- a/test/e2e/suite/command/customer_header.go +++ b/test/e2e/suite/command/customer_header.go @@ -21,7 +21,7 @@ import ( var _ = Describe("OCI image layout users:", func() { When("custom header is provided", func() { It("should fail attach", func() { - ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example"). + ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example", "--oci-layout"). WithWorkDir(GinkgoT().TempDir()). ExpectFailure(). MatchErrKeyWords("customer header"). From cb193a70b55381b2d746a3452d02dd9cdd6b4784 Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Tue, 28 Feb 2023 16:13:19 +0800 Subject: [PATCH 09/12] fix e2e Signed-off-by: Billy Zha --- test/e2e/suite/command/customer_header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/suite/command/customer_header.go b/test/e2e/suite/command/customer_header.go index 1e601b1ab..cf3448410 100644 --- a/test/e2e/suite/command/customer_header.go +++ b/test/e2e/suite/command/customer_header.go @@ -21,7 +21,7 @@ import ( var _ = Describe("OCI image layout users:", func() { When("custom header is provided", func() { It("should fail attach", func() { - ORAS("attach", "root:test", "-a", "test=true", "--artifact-type", "doc/example", "--oci-layout"). + ORAS("attach", ".:test", "-a", "test=true", "--artifact-type", "doc/example", "--oci-layout", "-H=foo:bar"). WithWorkDir(GinkgoT().TempDir()). ExpectFailure(). MatchErrKeyWords("customer header"). From 41eebc1efe1134a3dc65c46b21aa67a9a8720bfa Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 2 Mar 2023 07:46:19 +0800 Subject: [PATCH 10/12] improve prompt message Signed-off-by: Billy Zha --- cmd/oras/internal/option/target.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index 4a4f5614a..beb402470 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -88,7 +88,7 @@ func (opts *Target) Parse() error { case opts.isOCILayout: opts.Type = TargetTypeOCILayout if len(opts.headerFlags) != 0 { - return errors.New("customer header([--{from|to}]-header/H) cannot be used on OCI image layout target") + return errors.New("customer header flags cannot be used on an OCI image layout target") } return nil default: From a9927ca4c205b1b9a045f9f68bb9ad07543e0aca Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 2 Mar 2023 16:39:55 +0800 Subject: [PATCH 11/12] resolve comments Signed-off-by: Billy Zha --- test/e2e/suite/command/customer_header.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/e2e/suite/command/customer_header.go b/test/e2e/suite/command/customer_header.go index cf3448410..d50aa4eaa 100644 --- a/test/e2e/suite/command/customer_header.go +++ b/test/e2e/suite/command/customer_header.go @@ -24,7 +24,7 @@ var _ = Describe("OCI image layout users:", func() { ORAS("attach", ".:test", "-a", "test=true", "--artifact-type", "doc/example", "--oci-layout", "-H=foo:bar"). WithWorkDir(GinkgoT().TempDir()). ExpectFailure(). - MatchErrKeyWords("customer header"). + MatchErrKeyWords("custom header"). Exec() }) }) From 336968f70e05f87475ecc7c2b8ba0911188adbad Mon Sep 17 00:00:00 2001 From: Billy Zha Date: Thu, 2 Mar 2023 16:46:24 +0800 Subject: [PATCH 12/12] fix e2e Signed-off-by: Billy Zha --- cmd/oras/internal/option/target.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/oras/internal/option/target.go b/cmd/oras/internal/option/target.go index beb402470..fef1ddeb5 100644 --- a/cmd/oras/internal/option/target.go +++ b/cmd/oras/internal/option/target.go @@ -88,7 +88,7 @@ func (opts *Target) Parse() error { case opts.isOCILayout: opts.Type = TargetTypeOCILayout if len(opts.headerFlags) != 0 { - return errors.New("customer header flags cannot be used on an OCI image layout target") + return errors.New("custom header flags cannot be used on an OCI image layout target") } return nil default: