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

Function TestSetImageSignatureCheckFromError

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

Source from the content-addressed store, hash-verified

828}
829
830func TestSetImageSignatureCheckFromError(t *testing.T) {
831 noMatchingSignatures := cosign.ErrNoMatchingSignatures{}
832 f := reflect.ValueOf(&noMatchingSignatures).Elem().Field(0)
833 f = reflect.NewAt(f.Type(), unsafe.Pointer(f.UnsafeAddr())).Elem() //nolint:gosec // G115 - seems to be a false positive
834 f.Set(reflect.ValueOf(errors.New("kaboom!")))
835
836 cases := []struct {
837 name string
838 err error
839 expectedPassed bool
840 expectedResult *evaluator.Result
841 policy func(context.Context) policy.Policy
842 }{
843 {
844 name: "success",
845 expectedPassed: true,
846 expectedResult: &evaluator.Result{
847 Message: "Pass",
848 Metadata: map[string]interface{}{
849 "code": "builtin.image.signature_check",
850 },
851 },
852 },
853 {
854 name: "generic failure",
855 expectedPassed: false,
856 err: errors.New("kaboom!"),
857 expectedResult: &evaluator.Result{
858 Message: "Image signature check failed: kaboom!",
859 Metadata: map[string]interface{}{
860 "code": "builtin.image.signature_check",
861 },
862 },
863 },
864 {
865 name: "missing signatures failure",
866 expectedPassed: false,
867 err: &noMatchingSignatures,
868 expectedResult: &evaluator.Result{
869 Message: fmt.Sprintf(missingSignatureMessage, &noMatchingSignatures),
870 Metadata: map[string]interface{}{
871 "code": "builtin.image.signature_check",
872 },
873 },
874 },
875 {
876 name: "missing signatures failure with keyless",
877 expectedPassed: false,
878 err: &noMatchingSignatures,
879 expectedResult: &evaluator.Result{
880 Message: "Image signature check failed: kaboom!",
881 Metadata: map[string]interface{}{
882 "code": "builtin.image.signature_check",
883 },
884 },
885 policy: func(ctx context.Context) policy.Policy {
886 p, err := policy.NewPolicy(ctx, policy.Options{
887 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