MCPcopy Create free account
hub / github.com/conforma/cli / TestPrivateKeyFromKeyRef

Function TestPrivateKeyFromKeyRef

internal/utils/private_key_test.go:32–207  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30)
31
32func TestPrivateKeyFromKeyRef(t *testing.T) {
33 tests := []struct {
34 name string
35 keyRef string
36 setup func(fs afero.Fs, ctx context.Context)
37 expectErr bool
38 errMsg string
39 }{
40 {
41 name: "file path",
42 keyRef: "/path/to/key.pem",
43 setup: func(fs afero.Fs, ctx context.Context) {
44 err := afero.WriteFile(fs, "/path/to/key.pem", []byte("test key content"), 0o600)
45 require.NoError(t, err)
46 },
47 expectErr: false,
48 },
49 {
50 name: "k8s secret with explicit key field",
51 keyRef: "k8s://test-namespace/test-secret/private-key",
52 setup: func(fs afero.Fs, ctx context.Context) {
53 // This will be handled in the test loop
54 },
55 expectErr: false,
56 },
57 {
58 name: "k8s secret with single key (auto-select)",
59 keyRef: "k8s://test-namespace/single-key-secret",
60 setup: func(fs afero.Fs, ctx context.Context) {
61 // This will be handled in the test loop
62 },
63 expectErr: false,
64 },
65 {
66 name: "k8s secret with multiple keys (no key field specified, defaults to cosign.key)",
67 keyRef: "k8s://test-namespace/multi-key-secret",
68 setup: func(fs afero.Fs, ctx context.Context) {
69 // This will be handled in the test loop
70 },
71 expectErr: true,
72 errMsg: "key field \"cosign.key\" not found in secret",
73 },
74 {
75 name: "k8s secret with default cosign.key field",
76 keyRef: "k8s://test-namespace/cosign-key-secret",
77 setup: func(fs afero.Fs, ctx context.Context) {
78 // This will be handled in the test loop
79 },
80 expectErr: false,
81 },
82 {
83 name: "k8s secret with cosign.key among multiple keys (defaults to cosign.key)",
84 keyRef: "k8s://test-namespace/mixed-secret",
85 setup: func(fs afero.Fs, ctx context.Context) {
86 // This will be handled in the test loop
87 },
88 expectErr: false,
89 },

Callers

nothing calls this directly

Calls 3

PrivateKeyFromKeyRefFunction · 0.85
RunMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected