(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func 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 | |
| 122 | func TestEncryptWithPublicKeyEmptyPlaintext(t *testing.T) { |
| 123 | validKey := "YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXpBQkNERUY=" |
nothing calls this directly
no test coverage detected