Files
MyGoNavi/internal/app/global_proxy_secret_test.go
2026-04-05 11:39:34 +08:00

67 lines
1.6 KiB
Go

package app
import (
"testing"
"GoNavi-Wails/internal/connection"
)
func TestSaveGlobalProxyStripsPasswordFromView(t *testing.T) {
store := newFakeAppSecretStore()
app := NewAppWithSecretStore(store)
app.configDir = t.TempDir()
view, err := app.saveGlobalProxy(connection.SaveGlobalProxyInput{
Enabled: true,
Type: "http",
Host: "127.0.0.1",
Port: 8080,
User: "ops",
Password: "proxy-secret",
})
if err != nil {
t.Fatalf("saveGlobalProxy returned error: %v", err)
}
if view.Password != "" {
t.Fatal("global proxy view must not expose plaintext password")
}
if !view.HasPassword {
t.Fatal("expected hasPassword=true")
}
snapshot := currentGlobalProxyConfig()
if snapshot.Proxy.Password != "proxy-secret" {
t.Fatalf("expected runtime proxy password to be preserved, got %q", snapshot.Proxy.Password)
}
}
func TestGetGlobalProxyConfigReturnsSecretlessView(t *testing.T) {
store := newFakeAppSecretStore()
app := NewAppWithSecretStore(store)
app.configDir = t.TempDir()
if _, err := app.saveGlobalProxy(connection.SaveGlobalProxyInput{
Enabled: true,
Type: "http",
Host: "127.0.0.1",
Port: 8080,
User: "ops",
Password: "proxy-secret",
}); err != nil {
t.Fatalf("saveGlobalProxy returned error: %v", err)
}
result := app.GetGlobalProxyConfig()
view, ok := result.Data.(connection.GlobalProxyView)
if !ok {
t.Fatalf("expected GlobalProxyView, got %T", result.Data)
}
if view.Password != "" {
t.Fatal("GetGlobalProxyConfig must not expose plaintext password")
}
if !view.HasPassword {
t.Fatal("expected hasPassword=true")
}
}