MCPcopy Create free account
hub / github.com/github/gh-aw / TestEncryptWithPublicKeyInvalidKey

Function TestEncryptWithPublicKeyInvalidKey

pkg/cli/secret_set_command_test.go:88–120  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

86}
87
88func TestEncryptWithPublicKeyInvalidKey(t *testing.T) {
89 tests := []struct {
90 name string
91 key string
92 plaintext string
93 errContains string
94 }{
95 {
96 name: "invalid base64",
97 key: "not-valid-base64!@#$",
98 plaintext: "secret",
99 errContains: "decode public key",
100 },
101 {
102 name: "wrong key length",
103 key: "YWJjZA==", // "abcd" in base64 = 4 bytes, not 32
104 plaintext: "secret",
105 errContains: "unexpected public key length",
106 },
107 }
108
109 for _, tt := range tests {
110 t.Run(tt.name, func(t *testing.T) {
111 _, err := encryptWithPublicKey(tt.key, tt.plaintext)
112 if err == nil {
113 t.Fatal("encryptWithPublicKey() expected error, got nil")
114 }
115 if !strings.Contains(err.Error(), tt.errContains) {
116 t.Errorf("expected error containing %q, got %v", tt.errContains, err)
117 }
118 })
119 }
120}
121
122func TestEncryptWithPublicKeyEmptyPlaintext(t *testing.T) {
123 validKey := "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUY="

Callers

nothing calls this directly

Calls 4

encryptWithPublicKeyFunction · 0.85
RunMethod · 0.45
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected