* pass policy to Verify method Signed-off-by: Meredith Lancaster <malancas@github.com> * remove policy argument from SigstoreVerifier constructor Signed-off-by: Meredith Lancaster <malancas@github.com> * add SigstoreVerifier interface and introduce mock SigstoreVerifier struct for unit testing Signed-off-by: Meredith Lancaster <malancas@github.com> * gofmt Signed-off-by: Meredith Lancaster <malancas@github.com> * rename LiveSigstoreVerifier constructor Signed-off-by: Meredith Lancaster <malancas@github.com> * pr feedback, add todos for tests that need to be reimplemented Signed-off-by: Meredith Lancaster <malancas@github.com> * remove unused import Signed-off-by: Meredith Lancaster <malancas@github.com> * add more missing TODO statements Signed-off-by: Meredith Lancaster <malancas@github.com> * update skipped test Signed-off-by: Meredith Lancaster <malancas@github.com> --------- Signed-off-by: Meredith Lancaster <malancas@github.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
package verification
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/cli/cli/v2/pkg/cmd/attestation/api"
|
|
"github.com/cli/cli/v2/pkg/cmd/attestation/test/data"
|
|
|
|
"github.com/in-toto/in-toto-golang/in_toto"
|
|
"github.com/sigstore/sigstore-go/pkg/verify"
|
|
)
|
|
|
|
const SLSAPredicateType = "https://slsa.dev/provenance/v1"
|
|
|
|
type MockSigstoreVerifier struct {
|
|
t *testing.T
|
|
}
|
|
|
|
func (v *MockSigstoreVerifier) Verify(attestations []*api.Attestation, policy verify.PolicyBuilder) *SigstoreResults {
|
|
statement := &in_toto.Statement{}
|
|
statement.PredicateType = SLSAPredicateType
|
|
|
|
result := AttestationProcessingResult{
|
|
Attestation: &api.Attestation{
|
|
Bundle: data.SigstoreBundle(v.t),
|
|
},
|
|
VerificationResult: &verify.VerificationResult{
|
|
Statement: statement,
|
|
},
|
|
}
|
|
|
|
results := []*AttestationProcessingResult{&result}
|
|
|
|
return &SigstoreResults{
|
|
VerifyResults: results,
|
|
}
|
|
}
|
|
|
|
func NewMockSigstoreVerifier(t *testing.T) *MockSigstoreVerifier {
|
|
return &MockSigstoreVerifier{t}
|
|
}
|
|
|
|
type FailSigstoreVerifier struct{}
|
|
|
|
func (v *FailSigstoreVerifier) Verify(attestations []*api.Attestation, policy verify.PolicyBuilder) *SigstoreResults {
|
|
return &SigstoreResults{
|
|
Error: fmt.Errorf("failed to verify attestations"),
|
|
}
|
|
}
|