(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func 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 |
| 37 | name: test-plugin |
| 38 | type: cli/v1 |
| 39 | runtime: subprocess |
| 40 | version: 1.0.0 |
| 41 | runtimeConfig: |
| 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…