Zane on Discord: in Settings' proxy, Off saves "direct" and Auto saves "", so the Custom address and its user and password were gone the next time Custom was picked. settings.Save now keeps the last proxy of the user's own as proxyCustom (set only from Proxy, never from the page; the POST /api/settings handler copies the saved one over what the page sends). It is stored as Proxy is: plainly in settings.json, as before, the same as the proxy itself, nowhere more plainly. KeepOwn keeps it this computer's own, as Proxy, so sync and restore never carry another computer's. Custom picked after Off or Auto fills its fields from it; nothing that reads settings.proxy changes, and Off and Auto still send requests as they did. Run at base61b92529e(this tree): - go test ./internal/settings ./internal/backup ./internal/davsync ./internal/netproxy: ok. TestProxyCustomRemembered (gui, through Handler) and TestProxyCustomOwn (settings): ok. - settings-proxy-remember.test.cjs (new; en, zh, zh-TW, ja, de, chromium and webkit): Custom with user "名 a@b" and password "p@ss 密" -> Off -> Custom shows the same address and user; the same after a reload and after Auto; an unsaved draft is not what comes back; the page never posts proxyCustom. 10/10. - TestSettingsSaveKeepsWhatItDoesNotSend (the guard that every field the page doesn't send outlives its save) now sets ProxyCustom; red without the api.go line. - settings-proxy-auth, proxy-test, proxy-own-wording: 54 pass. - Full GUI suite (make test-ui, both engines) on a copy of this tree: 11735 tests, 70 red over 23 files at load ~150-260. Run again two at a time, 15 of those files pass; the other 8 are red on origin/main8278fd9b0too, run the same way, and are filed: mobile-web (#2658), quota-count-wrap and quota-name-translated (#2228), s3-sync (#2448), usage-agents-hide and usage-fold (#2399), usage-checkin (#2549, #3091), usage-ledger (#3104). - gofmt -l clean; go vet darwin, GOOS=linux -tags nogui, GOOS=windows: ok. Broken by hand, each red, then put back: - no proxyCustom in save(): TestProxyCustomRemembered red. - no KeepOwn line: TestProxyCustomOwn red. - no api.go line (page's value taken): the GUI test red. - renderProxy filling from "" again: the GUI test red in chromium. Not tried: the real app with a real SOCKS proxy that needs a login; a sync between two real computers.
58 lines
2.0 KiB
Go
58 lines
2.0 KiB
Go
package gui
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/settings"
|
|
)
|
|
|
|
// Custom proxy remembered (Zane on Discord): a proxy of the user's own,
|
|
// login and all, is kept as proxyCustom when Off ("direct") or Auto ("")
|
|
// is chosen after it, so Settings' Custom can bring it back, and the page
|
|
// is told it. Only the proxy sets it: a proxyCustom the page sends is not
|
|
// taken, and neither Off nor Auto changes what the gateway's requests go
|
|
// through.
|
|
func TestProxyCustomRemembered(t *testing.T) {
|
|
h := t.TempDir()
|
|
t.Setenv("HOME", h)
|
|
t.Setenv("USERPROFILE", h)
|
|
t.Setenv("XDG_CONFIG_HOME", filepath.Join(h, ".config"))
|
|
t.Setenv("XDG_CACHE_HOME", filepath.Join(h, ".cache"))
|
|
srv := Handler(nil, nil)
|
|
post := func(body string) map[string]any {
|
|
t.Helper()
|
|
rec := httptest.NewRecorder()
|
|
r := httptest.NewRequest("POST", "/api/settings", strings.NewReader(body))
|
|
r.RemoteAddr = "127.0.0.1:50000"
|
|
srv.ServeHTTP(rec, r)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("%s: %d %s", body, rec.Code, rec.Body)
|
|
}
|
|
var out map[string]any
|
|
if err := json.Unmarshal(rec.Body.Bytes(), &out); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
return out
|
|
}
|
|
own := "socks5://n%40me:p%40ss@127.0.0.1:1080"
|
|
if out := post(`{"theme":"dark","lang":"en","proxy":"` + own + `"}`); out["proxyCustom"] != own {
|
|
t.Fatalf("custom saved, page told %v", out["proxyCustom"])
|
|
}
|
|
for _, other := range []string{"direct", ""} {
|
|
out := post(`{"theme":"dark","lang":"en","proxy":"` + other + `","proxyCustom":"http://page.example:1"}`)
|
|
if s := settings.Load(); s.Proxy != other || s.ProxyCustom != own || out["proxyCustom"] != own {
|
|
t.Fatalf("proxy %q: saved %q, remembered %q, page told %v", other, s.Proxy, s.ProxyCustom, out["proxyCustom"])
|
|
}
|
|
}
|
|
next := "http://127.0.0.1:7890"
|
|
post(`{"theme":"dark","lang":"en","proxy":"` + next + `"}`)
|
|
if s := settings.Load(); s.Proxy != next || s.ProxyCustom != next {
|
|
t.Fatalf("a new custom proxy: saved %q, remembered %q", s.Proxy, s.ProxyCustom)
|
|
}
|
|
}
|