(t *testing.T)
| 978 | } |
| 979 | |
| 980 | func Test_FailureImageAccessibility(t *testing.T) { |
| 981 | validate := func(_ context.Context, component app.SnapshotComponent, _ *app.SnapshotSpec, _ policy.Policy, _ []evaluator.Evaluator, _ bool) (*output.Output, error) { |
| 982 | return &output.Output{ |
| 983 | ImageSignatureCheck: output.VerificationStatus{ |
| 984 | Passed: false, |
| 985 | Result: &evaluator.Result{Message: "skipped due to inaccessible image ref"}, |
| 986 | }, |
| 987 | ImageAccessibleCheck: output.VerificationStatus{ |
| 988 | Passed: false, |
| 989 | Result: &evaluator.Result{Message: "image ref not accessible. HEAD registry/image:tag: unexpected status code 404 Not Found (HEAD responses have no body, use GET for details)"}, |
| 990 | }, |
| 991 | AttestationSignatureCheck: output.VerificationStatus{ |
| 992 | Passed: false, |
| 993 | Result: &evaluator.Result{Message: "skipped due to inaccessible image ref"}, |
| 994 | }, |
| 995 | ImageURL: component.ContainerImage, |
| 996 | }, nil |
| 997 | } |
| 998 | |
| 999 | validateImageCmd := validateImageCmd(validate) |
| 1000 | cmd := setUpCobra(validateImageCmd) |
| 1001 | cmd.SilenceUsage = true // The root command is set to prevent usage printouts when running the CLI directly. This setup is temporary workaround. |
| 1002 | |
| 1003 | client := fake.FakeClient{} |
| 1004 | commonMockClient(&client) |
| 1005 | ctx := utils.WithFS(context.Background(), afero.NewMemMapFs()) |
| 1006 | ctx = oci.WithClient(ctx, &client) |
| 1007 | cmd.SetContext(ctx) |
| 1008 | |
| 1009 | effectiveTimeTest := time.Now().UTC().Format(time.RFC3339Nano) |
| 1010 | |
| 1011 | cmd.SetArgs(append(rootArgs, []string{ |
| 1012 | "--image", |
| 1013 | "registry/image:tag", |
| 1014 | "--policy", |
| 1015 | fmt.Sprintf(`{"publicKey": %s}`, utils.TestPublicKeyJSON), |
| 1016 | "--effective-time", |
| 1017 | effectiveTimeTest, |
| 1018 | }...)) |
| 1019 | |
| 1020 | var out bytes.Buffer |
| 1021 | cmd.SetOut(&out) |
| 1022 | |
| 1023 | utils.SetTestRekorPublicKey(t) |
| 1024 | |
| 1025 | err := cmd.Execute() |
| 1026 | assert.Error(t, err) |
| 1027 | assert.JSONEq(t, fmt.Sprintf(`{ |
| 1028 | "success": false, |
| 1029 | "ec-version": "development", |
| 1030 | "effective-time": %q, |
| 1031 | "key": %s, |
| 1032 | "components": [ |
| 1033 | { |
| 1034 | "name": "Unnamed", |
| 1035 | "containerImage": "registry/image:tag", |
| 1036 | "source": {}, |
| 1037 | "violations": [ |
nothing calls this directly
no test coverage detected