Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
Signed-off-by: cpanato <[email protected]>
  • Loading branch information
cpanato committed Oct 2, 2023
1 parent 9d729f0 commit af3d4d6
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/config/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type cfgKey struct{}
const (
// PolicyControllerConfigName is the name of the configmap used to configure
// policy-controller.
PolicyControllerConfigName = "config-policy-controller"
PolicyControllerConfigName = "config-policy-controller" //nolint: gosec

// Specifies that if an image is not found to match any policy, it should
// be rejected.
Expand Down
40 changes: 30 additions & 10 deletions pkg/webhook/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"context"
"crypto"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/x509"
"encoding/base64"
"encoding/json"
Expand Down Expand Up @@ -208,11 +207,18 @@ func TestValidatePodSpec(t *testing.T) {
authorityPublicKeyCVS := func(ctx context.Context, signedImgRef name.Reference, co *cosign.CheckOpts) (checkedSignatures []oci.Signature, bundleVerified bool, err error) {
actualPublicKey, _ := co.SigVerifier.PublicKey()
actualECDSAPubkey := actualPublicKey.(*ecdsa.PublicKey)
actualKeyData := elliptic.Marshal(actualECDSAPubkey, actualECDSAPubkey.X, actualECDSAPubkey.Y)

expectedKeyData := elliptic.Marshal(authorityKeyCosignPub, authorityKeyCosignPub.X, authorityKeyCosignPub.Y)
actualPubKey, err := actualECDSAPubkey.ECDH()
if err != nil {
return nil, false, errors.New("failed to get edch pub key")
}

authorityKeyPubKey, err := authorityKeyCosignPub.ECDH()
if err != nil {
return nil, false, errors.New("failed to get edch pub key")
}

if bytes.Equal(actualKeyData, expectedKeyData) {
if bytes.Equal(actualPubKey.Bytes(), authorityKeyPubKey.Bytes()) {
return pass(ctx, signedImgRef, co)
}

Expand Down Expand Up @@ -1589,11 +1595,18 @@ func TestValidatePolicy(t *testing.T) {
}
actualPublicKey, _ := co.SigVerifier.PublicKey()
actualECDSAPubkey := actualPublicKey.(*ecdsa.PublicKey)
actualKeyData := elliptic.Marshal(actualECDSAPubkey, actualECDSAPubkey.X, actualECDSAPubkey.Y)

expectedKeyData := elliptic.Marshal(authorityKeyCosignPub, authorityKeyCosignPub.X, authorityKeyCosignPub.Y)
actualPubKey, err := actualECDSAPubkey.ECDH()
if err != nil {
return nil, false, errors.New("failed to get edch pub key")
}

if bytes.Equal(actualKeyData, expectedKeyData) {
authorityKeyPubKey, err := authorityKeyCosignPub.ECDH()
if err != nil {
return nil, false, errors.New("failed to get edch pub key")
}

if bytes.Equal(actualPubKey.Bytes(), authorityKeyPubKey.Bytes()) {
return pass(ctx, signedImgRef, co)
}

Expand Down Expand Up @@ -2022,11 +2035,18 @@ func TestValidatePodSpecNonDefaultNamespace(t *testing.T) {
authorityPublicKeyCVS := func(ctx context.Context, signedImgRef name.Reference, co *cosign.CheckOpts) (checkedSignatures []oci.Signature, bundleVerified bool, err error) {
actualPublicKey, _ := co.SigVerifier.PublicKey()
actualECDSAPubkey := actualPublicKey.(*ecdsa.PublicKey)
actualKeyData := elliptic.Marshal(actualECDSAPubkey, actualECDSAPubkey.X, actualECDSAPubkey.Y)

expectedKeyData := elliptic.Marshal(authorityKeyCosignPub, authorityKeyCosignPub.X, authorityKeyCosignPub.Y)
actualPubKey, err := actualECDSAPubkey.ECDH()
if err != nil {
return nil, false, errors.New("failed to get edch pub key")
}

authorityKeyPubKey, err := authorityKeyCosignPub.ECDH()
if err != nil {
return nil, false, errors.New("failed to get edch pub key")
}

if bytes.Equal(actualKeyData, expectedKeyData) {
if bytes.Equal(actualPubKey.Bytes(), authorityKeyPubKey.Bytes()) {
return pass(ctx, signedImgRef, co)
}

Expand Down

0 comments on commit af3d4d6

Please sign in to comment.