mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-11 01:03:51 +08:00
- 新增 WebDAV 与 S3 独立配置、凭据和远端状态管理 - 使用 Argon2id 与 AES-256-GCM 加密连接及配置备份 - 支持分类备份、自动同步、远端预览和一次性确认恢复 - 连接与已保存查询按 ID 合并恢复,并保留本地独有数据 - 补充前后端回归测试、六语言文案和恢复失败回滚
45 lines
1.2 KiB
Go
45 lines
1.2 KiB
Go
package cloudbackup
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
)
|
|
|
|
func TestEncryptDecryptRoundTrip(t *testing.T) {
|
|
plain := []byte(`{"schemaVersion":1,"connections":[{"name":"prod"}]}`)
|
|
ciphertext, err := Encrypt(plain, "correct horse battery staple")
|
|
if err != nil {
|
|
t.Fatalf("Encrypt returned error: %v", err)
|
|
}
|
|
if bytes.Contains(ciphertext, plain) {
|
|
t.Fatal("encrypted envelope contains plaintext payload")
|
|
}
|
|
decoded, err := Decrypt(ciphertext, "correct horse battery staple")
|
|
if err != nil {
|
|
t.Fatalf("Decrypt returned error: %v", err)
|
|
}
|
|
if !bytes.Equal(decoded, plain) {
|
|
t.Fatalf("round trip mismatch: got %q want %q", decoded, plain)
|
|
}
|
|
}
|
|
|
|
func TestDecryptRejectsWrongPasswordAndTampering(t *testing.T) {
|
|
ciphertext, err := Encrypt([]byte("secret"), "password")
|
|
if err != nil {
|
|
t.Fatalf("Encrypt returned error: %v", err)
|
|
}
|
|
if _, err := Decrypt(ciphertext, "wrong"); err == nil {
|
|
t.Fatal("wrong password should fail")
|
|
}
|
|
ciphertext[len(ciphertext)-2] ^= 1
|
|
if _, err := Decrypt(ciphertext, "password"); err == nil {
|
|
t.Fatal("tampered envelope should fail")
|
|
}
|
|
}
|
|
|
|
func TestEncryptRequiresPassword(t *testing.T) {
|
|
if _, err := Encrypt([]byte("payload"), " "); err == nil {
|
|
t.Fatal("empty password should fail")
|
|
}
|
|
}
|