(t *testing.T)
| 573 | } |
| 574 | |
| 575 | func TestValidateImageSkipImageSigCheck(t *testing.T) { |
| 576 | tests := []struct { |
| 577 | name string |
| 578 | skipImageSigCheck bool |
| 579 | expectImageSigResult bool |
| 580 | }{ |
| 581 | { |
| 582 | name: "skip image signature check disabled (default)", |
| 583 | skipImageSigCheck: false, |
| 584 | expectImageSigResult: true, |
| 585 | }, |
| 586 | { |
| 587 | name: "skip image signature check enabled", |
| 588 | skipImageSigCheck: true, |
| 589 | expectImageSigResult: false, |
| 590 | }, |
| 591 | } |
| 592 | |
| 593 | for _, tt := range tests { |
| 594 | t.Run(tt.name, func(t *testing.T) { |
| 595 | fs := afero.NewMemMapFs() |
| 596 | ctx := utils.WithFS(context.Background(), fs) |
| 597 | |
| 598 | // Create a test component with a valid SHA256 digest |
| 599 | comp := app.SnapshotComponent{ |
| 600 | ContainerImage: imageRef, // Use the existing imageRef constant |
| 601 | } |
| 602 | |
| 603 | // Set up mock image infrastructure like other tests |
| 604 | ctx = withImageConfig(ctx, comp.ContainerImage) |
| 605 | client := ecoci.NewClient(ctx) |
| 606 | fakeClient := client.(*fake.FakeClient) |
| 607 | |
| 608 | // Set up minimal fake data for image to pass accessibility check |
| 609 | // and signature/attestation checks (they will fail but create results) |
| 610 | fakeClient.On("Head", ref).Return(&v1.Descriptor{MediaType: types.OCIManifestSchema1}, nil) |
| 611 | fakeClient.On("HasBundles", mock.Anything, refNoTag).Return(false, nil) |
| 612 | fakeClient.On("VerifyImageSignatures", refNoTag, mock.Anything).Return([]oci.Signature{}, false, fmt.Errorf("no signatures found")) |
| 613 | fakeClient.On("VerifyImageAttestations", refNoTag, mock.Anything).Return([]oci.Signature{}, false, fmt.Errorf("no attestations found")) |
| 614 | |
| 615 | // Create policy options to set SkipImageSigCheck |
| 616 | opts := policy.Options{ |
| 617 | EffectiveTime: policy.Now, |
| 618 | SkipImageSigCheck: tt.skipImageSigCheck, |
| 619 | Identity: cosign.Identity{ |
| 620 | Issuer: "https://example.com/oidc", |
| 621 | Subject: "test@example.com", |
| 622 | }, |
| 623 | } |
| 624 | |
| 625 | // Apply the options to create the policy |
| 626 | updatedPolicy, _, err := policy.PreProcessPolicy(ctx, opts) |
| 627 | require.NoError(t, err) |
| 628 | |
| 629 | // Create a mock snapshot spec |
| 630 | snap := &app.SnapshotSpec{} |
| 631 | |
| 632 | // Create empty evaluators slice |
nothing calls this directly
no test coverage detected