|
|
|
@ -21,9 +21,11 @@ import (
|
|
|
|
"fmt"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"testing"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v4/internal/plugin"
|
|
|
|
"helm.sh/helm/v4/internal/plugin"
|
|
|
|
"helm.sh/helm/v4/internal/test/ensure"
|
|
|
|
"helm.sh/helm/v4/internal/test/ensure"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -35,13 +37,7 @@ func TestPluginVerifyCmd_NoArgs(t *testing.T) {
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd.SetArgs([]string{})
|
|
|
|
cmd.SetArgs([]string{})
|
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.ErrorContains(t, cmd.Execute(), "requires 1 argument", "expected 'requires 1 argument' error")
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error when no arguments provided")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "requires 1 argument") {
|
|
|
|
|
|
|
|
t.Errorf("expected 'requires 1 argument' error, got: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPluginVerifyCmd_TooManyArgs(t *testing.T) {
|
|
|
|
func TestPluginVerifyCmd_TooManyArgs(t *testing.T) {
|
|
|
|
@ -51,13 +47,7 @@ func TestPluginVerifyCmd_TooManyArgs(t *testing.T) {
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd.SetArgs([]string{"plugin1", "plugin2"})
|
|
|
|
cmd.SetArgs([]string{"plugin1", "plugin2"})
|
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.ErrorContains(t, cmd.Execute(), "requires 1 argument", "expected 'requires 1 argument' error")
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error when too many arguments provided")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "requires 1 argument") {
|
|
|
|
|
|
|
|
t.Errorf("expected 'requires 1 argument' error, got: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPluginVerifyCmd_NonexistentFile(t *testing.T) {
|
|
|
|
func TestPluginVerifyCmd_NonexistentFile(t *testing.T) {
|
|
|
|
@ -67,10 +57,7 @@ func TestPluginVerifyCmd_NonexistentFile(t *testing.T) {
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd.SetArgs([]string{"/nonexistent/plugin.tgz"})
|
|
|
|
cmd.SetArgs([]string{"/nonexistent/plugin.tgz"})
|
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.Error(t, cmd.Execute(), "expected error when plugin file doesn't exist")
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error when plugin file doesn't exist")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPluginVerifyCmd_MissingProvenance(t *testing.T) {
|
|
|
|
func TestPluginVerifyCmd_MissingProvenance(t *testing.T) {
|
|
|
|
@ -84,13 +71,7 @@ func TestPluginVerifyCmd_MissingProvenance(t *testing.T) {
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd.SetArgs([]string{pluginTgz})
|
|
|
|
cmd.SetArgs([]string{pluginTgz})
|
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.ErrorContains(t, cmd.Execute(), "could not find provenance file", "expected 'could not find provenance file' error")
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error when .prov file is missing")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "could not find provenance file") {
|
|
|
|
|
|
|
|
t.Errorf("expected 'could not find provenance file' error, got: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPluginVerifyCmd_InvalidProvenance(t *testing.T) {
|
|
|
|
func TestPluginVerifyCmd_InvalidProvenance(t *testing.T) {
|
|
|
|
@ -102,19 +83,14 @@ func TestPluginVerifyCmd_InvalidProvenance(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
|
|
// Create invalid .prov file
|
|
|
|
// Create invalid .prov file
|
|
|
|
provFile := pluginTgz + ".prov"
|
|
|
|
provFile := pluginTgz + ".prov"
|
|
|
|
if err := os.WriteFile(provFile, []byte("invalid provenance"), 0o644); err != nil {
|
|
|
|
require.NoError(t, os.WriteFile(provFile, []byte("invalid provenance"), 0o644))
|
|
|
|
t.Fatal(err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer os.Remove(provFile)
|
|
|
|
defer os.Remove(provFile)
|
|
|
|
|
|
|
|
|
|
|
|
out := &bytes.Buffer{}
|
|
|
|
out := &bytes.Buffer{}
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd.SetArgs([]string{pluginTgz})
|
|
|
|
cmd.SetArgs([]string{pluginTgz})
|
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.Error(t, cmd.Execute(), "expected error when .prov file is invalid")
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error when .prov file is invalid")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPluginVerifyCmd_DirectoryNotSupported(t *testing.T) {
|
|
|
|
func TestPluginVerifyCmd_DirectoryNotSupported(t *testing.T) {
|
|
|
|
@ -127,13 +103,7 @@ func TestPluginVerifyCmd_DirectoryNotSupported(t *testing.T) {
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd := newPluginVerifyCmd(out)
|
|
|
|
cmd.SetArgs([]string{pluginDir})
|
|
|
|
cmd.SetArgs([]string{pluginDir})
|
|
|
|
|
|
|
|
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.ErrorContains(t, cmd.Execute(), "directory verification not supported", "expected 'directory verification not supported' error")
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error when verifying directory")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !strings.Contains(err.Error(), "directory verification not supported") {
|
|
|
|
|
|
|
|
t.Errorf("expected 'directory verification not supported' error, got: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func TestPluginVerifyCmd_KeyringFlag(t *testing.T) {
|
|
|
|
func TestPluginVerifyCmd_KeyringFlag(t *testing.T) {
|
|
|
|
@ -157,10 +127,7 @@ func TestPluginVerifyCmd_KeyringFlag(t *testing.T) {
|
|
|
|
cmd.SetArgs([]string{"--keyring", keyring, pluginTgz})
|
|
|
|
cmd.SetArgs([]string{"--keyring", keyring, pluginTgz})
|
|
|
|
|
|
|
|
|
|
|
|
// Should fail with keyring error but command parsing should work
|
|
|
|
// Should fail with keyring error but command parsing should work
|
|
|
|
err := cmd.Execute()
|
|
|
|
assert.Error(t, cmd.Execute(), "expected error with empty keyring")
|
|
|
|
if err == nil {
|
|
|
|
|
|
|
|
t.Error("expected error with empty keyring")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// The important thing is that the keyring flag was parsed and used
|
|
|
|
// The important thing is that the keyring flag was parsed and used
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -178,14 +145,10 @@ func createTestPluginDir(t *testing.T) string {
|
|
|
|
// Create temporary directory with plugin structure
|
|
|
|
// Create temporary directory with plugin structure
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
tmpDir := t.TempDir()
|
|
|
|
pluginDir := filepath.Join(tmpDir, "test-plugin")
|
|
|
|
pluginDir := filepath.Join(tmpDir, "test-plugin")
|
|
|
|
if err := os.MkdirAll(pluginDir, 0o755); err != nil {
|
|
|
|
require.NoErrorf(t, os.MkdirAll(pluginDir, 0o755), "Failed to create plugin directory")
|
|
|
|
t.Fatalf("Failed to create plugin directory: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Use the same plugin YAML as other cmd tests
|
|
|
|
// Use the same plugin YAML as other cmd tests
|
|
|
|
if err := os.WriteFile(filepath.Join(pluginDir, "plugin.yaml"), []byte(testPluginYAML), 0o644); err != nil {
|
|
|
|
require.NoErrorf(t, os.WriteFile(filepath.Join(pluginDir, "plugin.yaml"), []byte(testPluginYAML), 0o644), "Failed to create plugin.yaml")
|
|
|
|
t.Fatalf("Failed to create plugin.yaml: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return pluginDir
|
|
|
|
return pluginDir
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -199,14 +162,10 @@ func createTestPluginTarball(t *testing.T) string {
|
|
|
|
tmpDir := filepath.Dir(pluginDir)
|
|
|
|
tmpDir := filepath.Dir(pluginDir)
|
|
|
|
tgzPath := filepath.Join(tmpDir, "test-plugin-1.0.0.tgz")
|
|
|
|
tgzPath := filepath.Join(tmpDir, "test-plugin-1.0.0.tgz")
|
|
|
|
tarFile, err := os.Create(tgzPath)
|
|
|
|
tarFile, err := os.Create(tgzPath)
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, err, "Failed to create tarball file")
|
|
|
|
t.Fatalf("Failed to create tarball file: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
defer tarFile.Close()
|
|
|
|
defer tarFile.Close()
|
|
|
|
|
|
|
|
|
|
|
|
if err := plugin.CreatePluginTarball(pluginDir, "test-plugin", tarFile); err != nil {
|
|
|
|
require.NoErrorf(t, plugin.CreatePluginTarball(pluginDir, "test-plugin", tarFile), "Failed to create tarball")
|
|
|
|
t.Fatalf("Failed to create tarball: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tgzPath
|
|
|
|
return tgzPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -218,9 +177,7 @@ func createProvFile(t *testing.T, provFile, pluginTgz, hash string) {
|
|
|
|
if hash == "" {
|
|
|
|
if hash == "" {
|
|
|
|
// Calculate actual hash of the tarball
|
|
|
|
// Calculate actual hash of the tarball
|
|
|
|
data, err := os.ReadFile(pluginTgz)
|
|
|
|
data, err := os.ReadFile(pluginTgz)
|
|
|
|
if err != nil {
|
|
|
|
require.NoError(t, err, "Failed to read tarball for hashing")
|
|
|
|
t.Fatalf("Failed to read tarball for hashing: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
hashSum := sha256.Sum256(data)
|
|
|
|
hashSum := sha256.Sum256(data)
|
|
|
|
hashStr = fmt.Sprintf("sha256:%x", hashSum)
|
|
|
|
hashStr = fmt.Sprintf("sha256:%x", hashSum)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
@ -243,9 +200,7 @@ Version: GnuPG v1
|
|
|
|
iQEcBAEBCAAGBQJktest...
|
|
|
|
iQEcBAEBCAAGBQJktest...
|
|
|
|
-----END PGP SIGNATURE-----
|
|
|
|
-----END PGP SIGNATURE-----
|
|
|
|
`, hashStr)
|
|
|
|
`, hashStr)
|
|
|
|
if err := os.WriteFile(provFile, []byte(provContent), 0o644); err != nil {
|
|
|
|
require.NoErrorf(t, os.WriteFile(provFile, []byte(provContent), 0o644), "Failed to create provenance file")
|
|
|
|
t.Fatalf("Failed to create provenance file: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func createTestKeyring(t *testing.T) string {
|
|
|
|
func createTestKeyring(t *testing.T) string {
|
|
|
|
@ -256,9 +211,7 @@ func createTestKeyring(t *testing.T) string {
|
|
|
|
keyringPath := filepath.Join(tmpDir, "pubring.gpg")
|
|
|
|
keyringPath := filepath.Join(tmpDir, "pubring.gpg")
|
|
|
|
|
|
|
|
|
|
|
|
// Create empty keyring for testing
|
|
|
|
// Create empty keyring for testing
|
|
|
|
if err := os.WriteFile(keyringPath, []byte{}, 0o644); err != nil {
|
|
|
|
require.NoErrorf(t, os.WriteFile(keyringPath, []byte{}, 0o644), "Failed to create test keyring")
|
|
|
|
t.Fatalf("Failed to create test keyring: %v", err)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return keyringPath
|
|
|
|
return keyringPath
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|