@@ -60,6 +60,37 @@ func TestFastRestartStamp(t *testing.T) {
6060 })
6161}
6262
63+ func TestIsSignatureCosignTag (t * testing.T ) {
64+ Convey ("isSignature handles cosign-style tags safely" , t , func () {
65+ manifest := ispec.Manifest {}
66+
67+ Convey ("a short tag matching the cosign regex does not panic and is not a signature" , func () {
68+ ok , sigType , digest := isSignature ("sha256-abc.sig" , manifest )
69+ So (ok , ShouldBeFalse )
70+ So (sigType , ShouldBeEmpty )
71+ So (digest , ShouldBeEmpty )
72+ })
73+
74+ Convey ("a tag with a non-hex digest of the right length is not a signature" , func () {
75+ nonHex := ""
76+ for range 64 {
77+ nonHex += "z"
78+ }
79+ ok , _ , _ := isSignature ("sha256-" + nonHex + ".sig" , manifest )
80+ So (ok , ShouldBeFalse )
81+ })
82+
83+ Convey ("a well-formed cosign tag is recognized as a signature" , func () {
84+ signed := godigest .FromString ("signed-image" )
85+ tag := "sha256-" + signed .Encoded () + ".sig"
86+ ok , sigType , digest := isSignature (tag , manifest )
87+ So (ok , ShouldBeTrue )
88+ So (sigType , ShouldEqual , CosignType )
89+ So (digest , ShouldEqual , signed )
90+ })
91+ })
92+ }
93+
6394func TestParseStorageStats (t * testing.T ) {
6495 logger := log .NewTestLogger ()
6596
0 commit comments