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

Function TestValidateImageSkipAttSigCheck

internal/image/validate_test.go:659–761  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

657}
658
659func TestValidateImageSkipAttSigCheck(t *testing.T) {
660 tests := []struct {
661 name string
662 skipAttSigCheck bool
663 skipImageSigCheck bool
664 fetchAttErr error
665 expectAttSigResult bool
666 expectImgSigResult bool
667 }{
668 {
669 name: "skip attestation signature check disabled (default)",
670 skipAttSigCheck: false,
671 expectAttSigResult: true,
672 expectImgSigResult: true,
673 },
674 {
675 name: "skip attestation signature check enabled",
676 skipAttSigCheck: true,
677 expectAttSigResult: false,
678 expectImgSigResult: true,
679 },
680 {
681 name: "skip attestation signature check with fetch error",
682 skipAttSigCheck: true,
683 fetchAttErr: fmt.Errorf("registry unavailable"),
684 expectAttSigResult: true,
685 expectImgSigResult: true,
686 },
687 {
688 name: "skip both image and attestation signature checks",
689 skipAttSigCheck: true,
690 skipImageSigCheck: true,
691 expectAttSigResult: false,
692 expectImgSigResult: false,
693 },
694 }
695
696 for _, tt := range tests {
697 t.Run(tt.name, func(t *testing.T) {
698 fs := afero.NewMemMapFs()
699 ctx := utils.WithFS(context.Background(), fs)
700
701 comp := app.SnapshotComponent{
702 ContainerImage: imageRef,
703 }
704
705 ctx = withImageConfig(ctx, comp.ContainerImage)
706 client := ecoci.NewClient(ctx)
707 fakeClient := client.(*fake.FakeClient)
708
709 fakeClient.On("Head", ref).Return(&v1.Descriptor{MediaType: types.OCIManifestSchema1}, nil)
710 fakeClient.On("HasBundles", mock.Anything, refNoTag).Return(false, nil)
711 fakeClient.On("VerifyImageSignatures", refNoTag, mock.Anything).Return([]oci.Signature{}, false, fmt.Errorf("no signatures found"))
712 fakeClient.On("VerifyImageAttestations", refNoTag, mock.Anything).Return([]oci.Signature{}, false, fmt.Errorf("no attestations found"))
713 if tt.fetchAttErr != nil {
714 fakeClient.On("FetchAttestationLayers", refNoTag).Return([]oci.Signature(nil), tt.fetchAttErr)
715 } else {
716 fakeClient.On("FetchAttestationLayers", refNoTag).Return([]oci.Signature{validAttestation}, nil)

Callers

nothing calls this directly

Calls 6

WithFSFunction · 0.92
PreProcessPolicyFunction · 0.92
withImageConfigFunction · 0.85
ValidateImageFunction · 0.85
ErrorfMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected