zotregistry.dev/zot@v1.4.4-0.20240314164342-eec277e14d20/pkg/extensions/imagetrust/image_trust_disabled_test.go (about)

     1  //go:build !imagetrust
     2  
     3  package imagetrust_test
     4  
     5  import (
     6  	"os"
     7  	"path"
     8  	"testing"
     9  
    10  	. "github.com/smartystreets/goconvey/convey"
    11  
    12  	"zotregistry.dev/zot/pkg/extensions/imagetrust"
    13  	. "zotregistry.dev/zot/pkg/test/image-utils"
    14  )
    15  
    16  func TestImageTrust(t *testing.T) {
    17  	Convey("binary doesn't include imagetrust", t, func() {
    18  		rootDir := t.TempDir()
    19  
    20  		cosignDir := path.Join(rootDir, "_cosign")
    21  		_, err := os.Stat(cosignDir)
    22  		So(os.IsNotExist(err), ShouldBeTrue)
    23  
    24  		notationDir := path.Join(rootDir, "_notation")
    25  		_, err = os.Stat(notationDir)
    26  		So(os.IsNotExist(err), ShouldBeTrue)
    27  
    28  		repo := "repo"
    29  
    30  		image := CreateRandomImage()
    31  
    32  		localImgTrustStore, err := imagetrust.NewLocalImageTrustStore(rootDir)
    33  		So(err, ShouldBeNil)
    34  
    35  		author, expTime, ok, err := localImgTrustStore.VerifySignature("cosign",
    36  			[]byte(""), "", image.Digest(), image.AsImageMeta(), repo,
    37  		)
    38  		So(author, ShouldBeEmpty)
    39  		So(expTime, ShouldBeZeroValue)
    40  		So(ok, ShouldBeFalse)
    41  		So(err, ShouldBeNil)
    42  
    43  		_, err = os.Stat(cosignDir)
    44  		So(os.IsNotExist(err), ShouldBeTrue)
    45  
    46  		_, err = os.Stat(notationDir)
    47  		So(os.IsNotExist(err), ShouldBeTrue)
    48  
    49  		cloudImgTrustStore, err := imagetrust.NewAWSImageTrustStore("region",
    50  			"endpoint",
    51  		)
    52  		So(err, ShouldBeNil)
    53  
    54  		author, expTime, ok, err = cloudImgTrustStore.VerifySignature("cosign",
    55  			[]byte(""), "", image.Digest(), image.AsImageMeta(), repo,
    56  		)
    57  		So(author, ShouldBeEmpty)
    58  		So(expTime, ShouldBeZeroValue)
    59  		So(ok, ShouldBeFalse)
    60  		So(err, ShouldBeNil)
    61  	})
    62  }