grok2api / backend /internal /infra /security /cipher_test.go
fromozuzhouzzz
Deploy grok2api v3.0.11 to HF Spaces
f1dd159
Raw
History Blame Contribute Delete
619 Bytes
package security
import (
"crypto/rand"
"encoding/base64"
"testing"
)
func TestCipherRoundTrip(t *testing.T) {
key := make([]byte, 32)
if _, err := rand.Read(key); err != nil {
t.Fatal(err)
}
cipher, err := NewCipher(base64.StdEncoding.EncodeToString(key))
if err != nil {
t.Fatal(err)
}
encrypted, err := cipher.Encrypt("refresh-secret")
if err != nil {
t.Fatal(err)
}
if encrypted == "refresh-secret" {
t.Fatal("密文不应等于明文")
}
plain, err := cipher.Decrypt(encrypted)
if err != nil {
t.Fatal(err)
}
if plain != "refresh-secret" {
t.Fatalf("解密结果 = %q", plain)
}
}