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

Function Test_FailureOutput

cmd/validate/image_test.go:1051–1118  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1049}
1050
1051func Test_FailureOutput(t *testing.T) {
1052 validate := func(_ context.Context, component app.SnapshotComponent, _ *app.SnapshotSpec, _ policy.Policy, _ []evaluator.Evaluator, _ bool) (*output.Output, error) {
1053 return &output.Output{
1054 ImageSignatureCheck: output.VerificationStatus{
1055 Passed: false,
1056 Result: &evaluator.Result{Message: "failed image signature check"},
1057 },
1058 ImageAccessibleCheck: output.VerificationStatus{
1059 Passed: true,
1060 },
1061 AttestationSignatureCheck: output.VerificationStatus{
1062 Passed: false,
1063 Result: &evaluator.Result{Message: "failed attestation signature check"},
1064 },
1065 ImageURL: component.ContainerImage,
1066 }, nil
1067 }
1068
1069 validateImageCmd := validateImageCmd(validate)
1070 cmd := setUpCobra(validateImageCmd)
1071 cmd.SilenceUsage = true // The root command is set to prevent usage printouts when running the CLI directly. This setup is temporary workaround.
1072
1073 client := fake.FakeClient{}
1074 commonMockClient(&client)
1075 ctx := utils.WithFS(context.Background(), afero.NewMemMapFs())
1076 ctx = oci.WithClient(ctx, &client)
1077 cmd.SetContext(ctx)
1078
1079 effectiveTimeTest := time.Now().UTC().Format(time.RFC3339Nano)
1080
1081 cmd.SetArgs(append(rootArgs, []string{
1082 "--image",
1083 "registry/image:tag",
1084 "--policy",
1085 fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON),
1086 "--effective-time",
1087 effectiveTimeTest,
1088 }...))
1089
1090 var out bytes.Buffer
1091 cmd.SetOut(&out)
1092
1093 utils.SetTestRekorPublicKey(t)
1094
1095 err := cmd.Execute()
1096 assert.Error(t, err)
1097 assert.JSONEq(t, fmt.Sprintf(`{
1098 "success": false,
1099 "ec-version": "development",
1100 "effective-time": %q,
1101 "key": %s,
1102 "components": [
1103 {
1104 "name": "Unnamed",
1105 "containerImage": "registry/image:tag",
1106 "source": {},
1107 "violations": [
1108 {"msg": "failed attestation signature check"},

Callers

nothing calls this directly

Calls 8

WithFSFunction · 0.92
WithClientFunction · 0.92
SetTestRekorPublicKeyFunction · 0.92
validateImageCmdFunction · 0.85
commonMockClientFunction · 0.85
setUpCobraFunction · 0.70
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected