diff options
| author | Chia <Chia@93.nz> | 2026-08-04 19:58:52 +1200 |
|---|---|---|
| committer | Chia <Chia@93.nz> | 2026-08-04 20:43:23 +1200 |
| commit | 5b651488b081b65fda8a323f228e139adb79a35d (patch) | |
| tree | 08baf40efb8fe103b32721cd991ff712323e3173 /internal/security/credentials_test.go | |
Build AI gateway control plane and admin UI
Diffstat (limited to 'internal/security/credentials_test.go')
| -rw-r--r-- | internal/security/credentials_test.go | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/internal/security/credentials_test.go b/internal/security/credentials_test.go new file mode 100644 index 0000000..07fa59e --- /dev/null +++ b/internal/security/credentials_test.go @@ -0,0 +1,30 @@ +package security + +import ( + "encoding/base64" + "strings" + "testing" +) + +func TestCredentialCipherRoundTrip(t *testing.T) { + key := base64.StdEncoding.EncodeToString([]byte(strings.Repeat("k", 32))) + cipher, err := NewCredentialCipher(key) + if err != nil { + t.Fatal(err) + } + ciphertext, err := cipher.Encrypt("upstream-secret") + if err != nil { + t.Fatal(err) + } + plaintext, err := cipher.Decrypt(ciphertext) + if err != nil { + t.Fatal(err) + } + if plaintext != "upstream-secret" { + t.Fatalf("unexpected plaintext: %q", plaintext) + } + ciphertext[len(ciphertext)-1] ^= 1 + if _, err := cipher.Decrypt(ciphertext); err == nil { + t.Fatal("expected authentication failure for modified ciphertext") + } +} |
