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

Function TestEncryptDecryptRoundTrip

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

Source from the content-addressed store, hash-verified

135}
136
137func TestEncryptDecryptRoundTrip(t *testing.T) {
138 // Generate a real key pair for testing
139 pub, priv, err := box.GenerateKey(rand.Reader)
140 if err != nil {
141 t.Fatalf("failed to generate key pair: %v", err)
142 }
143
144 // Encode public key as base64
145 pubB64 := base64.StdEncoding.EncodeToString(pub[:])
146 plaintext := "test-secret-value"
147
148 // Encrypt using our function
149 encrypted, err := encryptWithPublicKey(pubB64, plaintext)
150 if err != nil {
151 t.Fatalf("encryptWithPublicKey() error = %v", err)
152 }
153
154 // Decrypt using NaCl box to verify correctness
155 cipherBytes, err := base64.StdEncoding.DecodeString(encrypted)
156 if err != nil {
157 t.Fatalf("failed to decode encrypted data: %v", err)
158 }
159
160 decrypted, ok := box.OpenAnonymous(nil, cipherBytes, pub, priv)
161 if !ok {
162 t.Fatal("decryption failed - ciphertext was not valid")
163 }
164
165 if string(decrypted) != plaintext {
166 t.Errorf("decrypted = %q, want %q", string(decrypted), plaintext)
167 }
168}
169
170func TestSecretSetClientOptions(t *testing.T) {
171 t.Run("defaults include timeout", func(t *testing.T) {

Callers

nothing calls this directly

Calls 2

encryptWithPublicKeyFunction · 0.85
ErrorfMethod · 0.45

Tested by

no test coverage detected