mirror of https://github.com/helm/helm.git
chore: update sign tests to use testify
Signed-off-by: Terry Howe <terrylhowe@gmail.com>
This commit is contained in:
parent
900cf2a93d
commit
f9152dc048
|
@ -26,6 +26,8 @@ import (
|
||||||
|
|
||||||
pgperrors "github.com/ProtonMail/go-crypto/openpgp/errors" //nolint
|
pgperrors "github.com/ProtonMail/go-crypto/openpgp/errors" //nolint
|
||||||
"github.com/ProtonMail/go-crypto/openpgp/packet" //nolint
|
"github.com/ProtonMail/go-crypto/openpgp/packet" //nolint
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
"helm.sh/helm/v4/pkg/chart/v2/loader"
|
"helm.sh/helm/v4/pkg/chart/v2/loader"
|
||||||
|
@ -272,13 +274,9 @@ func TestClearSign(t *testing.T) {
|
||||||
|
|
||||||
func TestMixedKeyringRSASigningAndVerification(t *testing.T) {
|
func TestMixedKeyringRSASigningAndVerification(t *testing.T) {
|
||||||
signer, err := NewFromFiles(testKeyfile, testMixedKeyring)
|
signer, err := NewFromFiles(testKeyfile, testMixedKeyring)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(signer.KeyRing) == 0 {
|
require.NotEmpty(t, signer.KeyRing, "expected signer keyring to be loaded")
|
||||||
t.Fatal("expected signer keyring to be loaded")
|
|
||||||
}
|
|
||||||
|
|
||||||
hasEdDSA := false
|
hasEdDSA := false
|
||||||
for _, entity := range signer.KeyRing {
|
for _, entity := range signer.KeyRing {
|
||||||
|
@ -299,54 +297,29 @@ func TestMixedKeyringRSASigningAndVerification(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !hasEdDSA {
|
assert.True(t, hasEdDSA, "expected %s to include an Ed25519 public key", testMixedKeyring)
|
||||||
t.Fatalf("expected %s to include an Ed25519 public key", testMixedKeyring)
|
|
||||||
}
|
|
||||||
|
|
||||||
if signer.Entity == nil {
|
require.NotNil(t, signer.Entity, "expected signer entity to be loaded")
|
||||||
t.Fatal("expected signer entity to be loaded")
|
require.NotNil(t, signer.Entity.PrivateKey, "expected signer private key to be loaded")
|
||||||
}
|
assert.Equal(t, packet.PubKeyAlgoRSA, signer.Entity.PrivateKey.PubKeyAlgo, "expected RSA key")
|
||||||
|
|
||||||
if signer.Entity.PrivateKey == nil {
|
|
||||||
t.Fatal("expected signer private key to be loaded")
|
|
||||||
}
|
|
||||||
|
|
||||||
if signer.Entity.PrivateKey.PubKeyAlgo != packet.PubKeyAlgoRSA {
|
|
||||||
t.Fatalf("expected RSA key but got %v", signer.Entity.PrivateKey.PubKeyAlgo)
|
|
||||||
}
|
|
||||||
|
|
||||||
metadataBytes := loadChartMetadataForSigning(t, testChartfile)
|
metadataBytes := loadChartMetadataForSigning(t, testChartfile)
|
||||||
|
|
||||||
archiveData, err := os.ReadFile(testChartfile)
|
archiveData, err := os.ReadFile(testChartfile)
|
||||||
if err != nil {
|
require.NoError(t, err)
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
sig, err := signer.ClearSign(archiveData, filepath.Base(testChartfile), metadataBytes)
|
sig, err := signer.ClearSign(archiveData, filepath.Base(testChartfile), metadataBytes)
|
||||||
if err != nil {
|
require.NoError(t, err, "failed to sign chart")
|
||||||
t.Fatalf("failed to sign chart: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
verification, err := signer.Verify(archiveData, []byte(sig), filepath.Base(testChartfile))
|
verification, err := signer.Verify(archiveData, []byte(sig), filepath.Base(testChartfile))
|
||||||
if err != nil {
|
require.NoError(t, err, "failed to verify chart signature")
|
||||||
t.Fatalf("failed to verify chart signature: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if verification.SignedBy == nil {
|
require.NotNil(t, verification.SignedBy, "expected verification to include signer")
|
||||||
t.Fatal("expected verification to include signer")
|
require.NotNil(t, verification.SignedBy.PrimaryKey, "expected verification to include signer primary key")
|
||||||
}
|
assert.Equal(t, packet.PubKeyAlgoRSA, verification.SignedBy.PrimaryKey.PubKeyAlgo, "expected verification to report RSA key")
|
||||||
|
|
||||||
if verification.SignedBy.PrimaryKey == nil {
|
_, ok := verification.SignedBy.Identities[testKeyName]
|
||||||
t.Fatal("expected verification to include signer primary key")
|
assert.True(t, ok, "expected verification to be signed by %q", testKeyName)
|
||||||
}
|
|
||||||
|
|
||||||
if verification.SignedBy.PrimaryKey.PubKeyAlgo != packet.PubKeyAlgoRSA {
|
|
||||||
t.Fatalf("expected verification to report RSA key but got %v", verification.SignedBy.PrimaryKey.PubKeyAlgo)
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, ok := verification.SignedBy.Identities[testKeyName]; !ok {
|
|
||||||
t.Fatalf("expected verification to be signed by %q", testKeyName)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// failSigner always fails to sign and returns an error
|
// failSigner always fails to sign and returns an error
|
||||||
|
|
Loading…
Reference in New Issue