Skip to content

Commit

Permalink
fix(test): fix TestAttestVerify
Browse files Browse the repository at this point in the history
Signed-off-by: Erkan Zileli <[email protected]>
  • Loading branch information
erkanzileli committed Sep 10, 2021
1 parent 3a738f1 commit f124f24
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 10 additions & 10 deletions cmd/cosign/cli/verify_attestation.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,20 @@ import (
"github.com/sigstore/sigstore/pkg/signature/dsse"
)

type policies struct {
entrypoints []string
type Policies struct {
EntryPoints []string
}

func (p *policies) Set(s string) error {
if p.entrypoints == nil {
p.entrypoints = []string{}
func (p *Policies) Set(s string) error {
if p.EntryPoints == nil {
p.EntryPoints = []string{}
}
p.entrypoints = append(p.entrypoints, s)
p.EntryPoints = append(p.EntryPoints, s)
return nil
}

func (p *policies) String() string {
return strings.Join(p.entrypoints, ",")
func (p *Policies) String() string {
return strings.Join(p.EntryPoints, ",")
}

// VerifyAttestationCommand verifies a signature on a supplied container image
Expand All @@ -64,7 +64,7 @@ type VerifyAttestationCommand struct {
FulcioURL string
RekorURL string
PredicateType string
Policies policies
Policies Policies
}

func applyVerifyAttestationFlags(cmd *VerifyAttestationCommand, flagset *flag.FlagSet) {
Expand Down Expand Up @@ -271,7 +271,7 @@ func (c *VerifyAttestationCommand) Exec(ctx context.Context, args []string) (err
return fmt.Errorf("error when generating SPDXStatement: %w", err)
}
}
if err := cue.ValidateJSON(payload, c.Policies.entrypoints); err != nil {
if err := cue.ValidateJSON(payload, c.Policies.EntryPoints); err != nil {
return fmt.Errorf("validating policy: %w", err)
}
}
Expand Down
10 changes: 9 additions & 1 deletion test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestAttestVerify(t *testing.T) {
KeyRef: pubKeyPath,
}

attestation := "helloworld"
attestation := `{"x": 1}`
ap := filepath.Join(td, "attestation")
if err := ioutil.WriteFile(ap, []byte(attestation), 0600); err != nil {
t.Fatal(err)
Expand All @@ -176,6 +176,14 @@ func TestAttestVerify(t *testing.T) {
ko := cli.KeyOpts{KeyRef: privKeyPath, PassFunc: passFunc}
must(cli.AttestCmd(ctx, ko, imgName, "", true, ap, false, "custom"), t)

cuePolicy := "x: 2"
policyPath := filepath.Join(td, "policy.cue")
if err := ioutil.WriteFile(policyPath, []byte(cuePolicy), 0600); err != nil {
t.Fatal(err)
}
verifyAttestation.PredicateType = "custom"
verifyAttestation.Policies = cli.Policies{EntryPoints: []string{policyPath}}

// Now verify and download should work!
must(verifyAttestation.Exec(ctx, []string{imgName}), t)
// Look for a specific annotation
Expand Down

0 comments on commit f124f24

Please sign in to comment.