mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-05-25 10:20:18 +08:00
- Redis 页面重构为工作台样式,统一左右面板、工具条和详情区层级 - 接入 light/dark/透明模式主题参数,修复 Redis 页面与全局主题不一致问题 - 新增文件夹递归勾选、全选全部、分组全选/取消全选能力 - 支持 Redis Key 右键菜单重命名并同步更新树节点、选中态和详情面板 - 修复 type=none 时读取失败问题,过期或已删除 Key 自动提示并移出列表 - 接管 Redis Tree 展开箭头渲染,修复 switcher 命中区错位和悬浮白线问题 - 统一工具、代理、主题、关于、筛选、新建组和新建连接等弹层主题 - refs #231
122 lines
2.8 KiB
Go
122 lines
2.8 KiB
Go
package redis
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestSanitizeRedisPassword(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
input string
|
|
expected string
|
|
}{
|
|
{
|
|
name: "empty password",
|
|
input: "",
|
|
expected: "",
|
|
},
|
|
{
|
|
name: "plain password without special chars",
|
|
input: "mypassword123",
|
|
expected: "mypassword123",
|
|
},
|
|
{
|
|
name: "password with @ not encoded",
|
|
input: "p@ssword",
|
|
expected: "p@ssword",
|
|
},
|
|
{
|
|
name: "password with @ URL-encoded as %40",
|
|
input: "p%40ssword",
|
|
expected: "p@ssword",
|
|
},
|
|
{
|
|
name: "password with multiple encoded chars",
|
|
input: "p%40ss%23word",
|
|
expected: "p@ss#word",
|
|
},
|
|
{
|
|
name: "password with + encoded as %2B",
|
|
input: "p%2Bss",
|
|
expected: "p+ss",
|
|
},
|
|
{
|
|
name: "password that is purely encoded",
|
|
input: "%40%23%24",
|
|
expected: "@#$",
|
|
},
|
|
{
|
|
name: "password with invalid percent encoding",
|
|
input: "p%ZZssword",
|
|
expected: "p%ZZssword",
|
|
},
|
|
{
|
|
name: "password with trailing percent",
|
|
input: "password%",
|
|
expected: "password%",
|
|
},
|
|
{
|
|
name: "password with literal percent not encoding anything",
|
|
input: "100%safe",
|
|
expected: "100%safe",
|
|
},
|
|
{
|
|
name: "password with space encoded as %20",
|
|
input: "my%20pass",
|
|
expected: "my pass",
|
|
},
|
|
{
|
|
name: "complex password with mixed content",
|
|
input: "P%40ss%23w0rd!",
|
|
expected: "P@ss#w0rd!",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
result := sanitizeRedisPassword(tt.input)
|
|
if result != tt.expected {
|
|
t.Errorf("sanitizeRedisPassword(%q) = %q, want %q", tt.input, result, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIsRedisKeyGone(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
keyType string
|
|
ttl int64
|
|
want bool
|
|
}{
|
|
{name: "type none", keyType: "none", ttl: -2, want: true},
|
|
{name: "type none without ttl", keyType: "none", ttl: -1, want: true},
|
|
{name: "missing by ttl", keyType: "string", ttl: -2, want: true},
|
|
{name: "normal string", keyType: "string", ttl: 30, want: false},
|
|
{name: "permanent hash", keyType: "hash", ttl: -1, want: false},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := isRedisKeyGone(tt.keyType, tt.ttl); got != tt.want {
|
|
t.Fatalf("isRedisKeyGone(%q, %d)=%v, want %v", tt.keyType, tt.ttl, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestNormalizeRedisGetValueError(t *testing.T) {
|
|
err := normalizeRedisGetValueError("none", -2)
|
|
if !errors.Is(err, ErrRedisKeyGone) {
|
|
t.Fatalf("expected ErrRedisKeyGone, got %v", err)
|
|
}
|
|
if err == nil || err.Error() != "Redis Key 不存在或已过期" {
|
|
t.Fatalf("unexpected error text: %v", err)
|
|
}
|
|
|
|
if normalizeRedisGetValueError("hash", -1) != nil {
|
|
t.Fatal("expected nil for supported existing key")
|
|
}
|
|
}
|