MCPcopy
hub / github.com/helm/helm / TestSignPlugin

Function TestSignPlugin

internal/plugin/sign_test.go:27–98  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestSignPlugin(t *testing.T) {
28 // Create a test plugin directory
29 tempDir := t.TempDir()
30 pluginDir := filepath.Join(tempDir, "test-plugin")
31 if err := os.MkdirAll(pluginDir, 0755); err != nil {
32 t.Fatal(err)
33 }
34
35 // Create a plugin.yaml file
36 pluginYAML := `apiVersion: v1
37name: test-plugin
38type: cli/v1
39runtime: subprocess
40version: 1.0.0
41runtimeConfig:
42 platformCommand:
43 - command: echo`
44 if err := os.WriteFile(filepath.Join(pluginDir, "plugin.yaml"), []byte(pluginYAML), 0644); err != nil {
45 t.Fatal(err)
46 }
47
48 // Create a tarball
49 tarballPath := filepath.Join(tempDir, "test-plugin.tgz")
50 tarFile, err := os.Create(tarballPath)
51 if err != nil {
52 t.Fatal(err)
53 }
54 if err := CreatePluginTarball(pluginDir, "test-plugin", tarFile); err != nil {
55 tarFile.Close()
56 t.Fatal(err)
57 }
58 tarFile.Close()
59
60 // Create a test key for signing
61 keyring := "../../pkg/cmd/testdata/helm-test-key.secret"
62 signer, err := provenance.NewFromKeyring(keyring, "helm-test")
63 if err != nil {
64 t.Fatal(err)
65 }
66 if err := signer.DecryptKey(func(_ string) ([]byte, error) {
67 return []byte(""), nil
68 }); err != nil {
69 t.Fatal(err)
70 }
71
72 // Read the tarball data
73 tarballData, err := os.ReadFile(tarballPath)
74 if err != nil {
75 t.Fatalf("failed to read tarball: %v", err)
76 }
77
78 // Sign the plugin tarball
79 sig, err := SignPlugin(tarballData, filepath.Base(tarballPath), signer)
80 if err != nil {
81 t.Fatalf("failed to sign plugin: %v", err)
82 }
83
84 // Verify the signature contains the expected content

Callers

nothing calls this directly

Calls 12

NewFromKeyringFunction · 0.92
DigestFileFunction · 0.92
CreatePluginTarballFunction · 0.85
SignPluginFunction · 0.85
FatalMethod · 0.80
CloseMethod · 0.80
DecryptKeyMethod · 0.80
FatalfMethod · 0.80
ContainsMethod · 0.80
CreateMethod · 0.65
WriteFileMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…