MCPcopy Create free account
hub / github.com/conforma/cli / TestSetAttestationSignatureCheckFromError

Function TestSetAttestationSignatureCheckFromError

internal/output/output_test.go:917–1002  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

915}
916
917func TestSetAttestationSignatureCheckFromError(t *testing.T) {
918 noMatchingAttestations := cosign.ErrNoMatchingAttestations{}
919 f := reflect.ValueOf(&noMatchingAttestations).Elem().Field(0)
920 f = reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Elem() //nolint:gosec // G115 - seems to be a false positive
921 f.Set(reflect.ValueOf(errors.New("kaboom!")))
922
923 cases := []struct {
924 name string
925 err error
926 expectedPassed bool
927 expectedResult *evaluator.Result
928 policy func(context.Context) policy.Policy
929 }{
930 {
931 name: "success",
932 expectedPassed: true,
933 expectedResult: &evaluator.Result{
934 Message: "Pass",
935 Metadata: map[string]interface{}{
936 "code": "builtin.attestation.signature_check",
937 },
938 },
939 },
940 {
941 name: "generic failure",
942 expectedPassed: false,
943 err: errors.New("kaboom!"),
944 expectedResult: &evaluator.Result{
945 Message: "Image attestation check failed: kaboom!",
946 Metadata: map[string]interface{}{
947 "code": "builtin.attestation.signature_check",
948 },
949 },
950 },
951 {
952 name: "missing attestations failure",
953 expectedPassed: false,
954 err: &noMatchingAttestations,
955 expectedResult: &evaluator.Result{
956 Message: fmt.Sprintf(missingAttestationMessage, &noMatchingAttestations),
957 Metadata: map[string]interface{}{
958 "code": "builtin.attestation.signature_check",
959 },
960 },
961 },
962 {
963 name: "missing attestations failure with keyless",
964 expectedPassed: false,
965 err: &noMatchingAttestations,
966 expectedResult: &evaluator.Result{
967 Message: "Image attestation check failed: kaboom!",
968 Metadata: map[string]interface{}{
969 "code": "builtin.attestation.signature_check",
970 },
971 },
972 policy: func(ctx context.Context) policy.Policy {
973 p, err := policy.NewPolicy(ctx, policy.Options{
974 EffectiveTime: policy.Now,

Callers

nothing calls this directly

Calls 8

NewPolicyFunction · 0.92
SetTestRekorPublicKeyFunction · 0.92
SetTestFulcioRootsFunction · 0.92
SetTestCTLogPublicKeyFunction · 0.92
TypeMethod · 0.65
RunMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected