forked from kubescape/kubescape
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fetch Rekor before cosign validation
Signed-off-by: Matthias Bertschy <[email protected]>
- Loading branch information
Showing
2 changed files
with
60 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,57 @@ | ||
package opaprocessor | ||
|
||
// func Test_verify(t *testing.T) { | ||
// type args struct { | ||
// img string | ||
// key string | ||
// } | ||
// tests := []struct { | ||
// name string | ||
// args args | ||
// want bool | ||
// wantErr assert.ErrorAssertionFunc | ||
// }{ | ||
// { | ||
// "valid signature", | ||
// args{ | ||
// img: "hisu/cosign-tests:signed", | ||
// key: "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGnMCUU0jGe6r4mPsPuyTXf61PE4e\nNwB/31SvUMmnoyd/1UxSqd+MRPXPU6pcub4k6E9G9SprVCuf6Sydcbyiqw==\n-----END PUBLIC KEY-----", | ||
// }, | ||
// true, | ||
// assert.NoError, | ||
// }, | ||
// { | ||
// "no signature", | ||
// args{ | ||
// img: "hisu/cosign-tests:unsigned", | ||
// key: "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEGnMCUU0jGe6r4mPsPuyTXf61PE4e\nNwB/31SvUMmnoyd/1UxSqd+MRPXPU6pcub4k6E9G9SprVCuf6Sydcbyiqw==\n-----END PUBLIC KEY-----", | ||
// }, | ||
// false, | ||
// assert.Error, | ||
// }, | ||
// } | ||
// for _, tt := range tests { | ||
// t.Run(tt.name, func(t *testing.T) { | ||
// got, err := verify(tt.args.img, tt.args.key) | ||
// if !tt.wantErr(t, err, fmt.Sprintf("verify(%v, %v)", tt.args.img, tt.args.key)) { | ||
// return | ||
// } | ||
// assert.Equalf(t, tt.want, got, "verify(%v, %v)", tt.args.img, tt.args.key) | ||
// }) | ||
// } | ||
// } | ||
import ( | ||
"fmt" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func Test_verify(t *testing.T) { | ||
type args struct { | ||
img string | ||
key string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want bool | ||
wantErr assert.ErrorAssertionFunc | ||
}{ | ||
{ | ||
"valid signature", | ||
args{ | ||
img: "quay.io/kubescape/kubescape:v3.0.3", | ||
key: "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbgIMZrMTTlEFDLEeZXz+4R/908BG\nEeO70x6oMN7E4JQgzgbCB5rinqhK5t7dB61saVKQTb4P2NGtjPjXVbSTwQ==\n-----END PUBLIC KEY-----\n", | ||
}, | ||
true, | ||
assert.NoError, | ||
}, | ||
{ | ||
"wrong signature", | ||
args{ | ||
img: "quay.io/kubescape/kubescape:v2.9.2", | ||
key: "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbgIMZrMTTlEFDLEeZXz+4R/908BG\nEeO70x6oMN7E4JQgzgbCB5rinqhK5t7dB61saVKQTb4P2NGtjPjXVbSTwQ==\n-----END PUBLIC KEY-----\n", | ||
}, | ||
false, | ||
assert.Error, | ||
}, | ||
{ | ||
"no matching signature", | ||
args{ | ||
img: "quay.io/kubescape/kubescape:v2.0.171", | ||
key: "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbgIMZrMTTlEFDLEeZXz+4R/908BG\nEeO70x6oMN7E4JQgzgbCB5rinqhK5t7dB61saVKQTb4P2NGtjPjXVbSTwQ==\n-----END PUBLIC KEY-----\n", | ||
}, | ||
false, | ||
assert.Error, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := verify(tt.args.img, tt.args.key) | ||
if !tt.wantErr(t, err, fmt.Sprintf("verify(%v, %v)", tt.args.img, tt.args.key)) { | ||
return | ||
} | ||
assert.Equalf(t, tt.want, got, "verify(%v, %v)", tt.args.img, tt.args.key) | ||
}) | ||
} | ||
} |