|
| 1 | +From bf3a40aef3af6919bba73bfeaadac2d0c169628d Mon Sep 17 00:00:00 2001 |
| 2 | +From: Fredrik Skogman <kommendorkapten@github.com> |
| 3 | +Date: Tue, 11 Feb 2025 09:07:51 +0100 |
| 4 | +Subject: [PATCH] Exit with error if no matching predicate type exists |
| 5 | + |
| 6 | +Signed-off-by: Fredrik Skogman <kommendorkapten@github.com> |
| 7 | +--- |
| 8 | + pkg/cmd/attestation/verify/verify.go | 2 +- |
| 9 | + pkg/cmd/attestation/verify/verify_test.go | 12 ++++++++++++ |
| 10 | + 2 files changed, 13 insertions(+), 1 deletion(-) |
| 11 | + |
| 12 | +diff --git a/pkg/cmd/attestation/verify/verify.go b/pkg/cmd/attestation/verify/verify.go |
| 13 | +index 90242a9fed2..0a8de8b4599 100644 |
| 14 | +--- a/pkg/cmd/attestation/verify/verify.go |
| 15 | ++++ b/pkg/cmd/attestation/verify/verify.go |
| 16 | +@@ -236,7 +236,7 @@ func runVerify(opts *Options) error { |
| 17 | + filteredAttestations := verification.FilterAttestations(ec.PredicateType, attestations) |
| 18 | + if len(filteredAttestations) == 0 { |
| 19 | + opts.Logger.Printf(opts.Logger.ColorScheme.Red("✗ No attestations found with predicate type: %s\n"), opts.PredicateType) |
| 20 | +- return err |
| 21 | ++ return fmt.Errorf("no matching predicate found") |
| 22 | + } |
| 23 | + attestations = filteredAttestations |
| 24 | + |
| 25 | +diff --git a/pkg/cmd/attestation/verify/verify_test.go b/pkg/cmd/attestation/verify/verify_test.go |
| 26 | +index 87ffa96f090..092a009d81e 100644 |
| 27 | +--- a/pkg/cmd/attestation/verify/verify_test.go |
| 28 | ++++ b/pkg/cmd/attestation/verify/verify_test.go |
| 29 | +@@ -501,6 +501,18 @@ func TestRunVerify(t *testing.T) { |
| 30 | + require.Nil(t, runVerify(&customOpts)) |
| 31 | + }) |
| 32 | + |
| 33 | ++ t.Run("with valid OCI artifact with UseBundleFromRegistry flag and unknown predicate type", func(t *testing.T) { |
| 34 | ++ customOpts := publicGoodOpts |
| 35 | ++ customOpts.ArtifactPath = "oci://ghcr.io/github/test" |
| 36 | ++ customOpts.BundlePath = "" |
| 37 | ++ customOpts.UseBundleFromRegistry = true |
| 38 | ++ customOpts.PredicateType = "https://predicate.type" |
| 39 | ++ |
| 40 | ++ err := runVerify(&customOpts) |
| 41 | ++ require.Error(t, err) |
| 42 | ++ require.ErrorContains(t, err, "no matching predicate found") |
| 43 | ++ }) |
| 44 | ++ |
| 45 | + t.Run("with valid OCI artifact with UseBundleFromRegistry flag but no bundle return from registry", func(t *testing.T) { |
| 46 | + customOpts := publicGoodOpts |
| 47 | + customOpts.ArtifactPath = "oci://ghcr.io/github/test" |
0 commit comments