jiakun_zhao on X ran `magpie web` in a terminal beside the desktop app, to manage it through a Cloudflare tunnel. Settings › Network and sharing › Browser access now has the app serve the same page itself: Off, This computer (127.0.0.1, for a tunnel or SSH forward) or Local network. Access is magpie web's, unchanged: the key in the link is traded for the cookie (webGuard), the allow list holds, and the gateway's client routes on the page's port need a gateway key (onePort). A rebound Host and Origin: null get no cookie. There is no way to serve it without the key. The key and choice live in web-page.json (0600) beside settings.json, so a sync never carries them. GET/POST /api/web-page are the app windows' alone: a browser on the page can't read the key or turn the page off. A busy port (magpie web, the magpie before an update) is tried every 4s; `magpie web` on the same port opens the app's link instead. Run at d43b7c40d (this change onef155a5ca), then rebased onto the four newer main commits, which touch gateway, usage, proc and library only: - gofmt -l internal/gui internal/cli: nothing. go vet, GOOS=linux go vet -tags nogui and GOOS=windows go vet of internal/gui and internal/cli: clean. go build: ok. - go test -timeout 45m ./internal/gui/ ./internal/cli/: ok (180s, 70s). - GUI, alone: browser-access.test.cjs and model-test-one.test.cjs pass in both engines; i18n-keys 23 of 24, its red is #3897 ("Runs as" from7f827b3b0), not this change. agent-stale-copies.test.cjs 80 of 80 at 8d343a811 (this change before the rebase). - Full GUI suite at 8d343a811: cut short. The disk filled (708MB free): browsers failed to launch with ENOSPC in agent-stale-copies, which then passed 80 of 80 alone, and node ended with exit 7 before the rest of the files ran. There is no full GUI record for this change. Not tried: a real Cloudflare tunnel to the page, and Local network from another machine.
57 lines
2.1 KiB
Go
57 lines
2.1 KiB
Go
package cli
|
|
|
|
import "testing"
|
|
|
|
// magpie web on loopback behind a reverse proxy (#1479) prints the proxy's
|
|
// link with the key when told the proxy's address, so nobody joins
|
|
// "/?k=…" onto it by hand: MAGPIE_WEB_URL, else MAGPIE_PUBLIC_URL with no
|
|
// port (one with a port isn't a proxy). None is printed without either.
|
|
func TestWebProxyLink(t *testing.T) {
|
|
key := "/?k=0123456789abcdef"
|
|
for _, c := range []struct{ env, want string }{
|
|
{"https://magpie.example.com", "https://magpie.example.com/?k=0123456789abcdef"},
|
|
{"https://magpie.example.com/", "https://magpie.example.com/?k=0123456789abcdef"},
|
|
{"magpie.example.com", "http://magpie.example.com/?k=0123456789abcdef"},
|
|
{"https://example.com/magpie/", "https://example.com/magpie/?k=0123456789abcdef"},
|
|
{"http://192.168.1.20:3425", ""},
|
|
{"", ""},
|
|
} {
|
|
t.Setenv("MAGPIE_PUBLIC_URL", c.env)
|
|
if got := proxyLink(key); got != c.want {
|
|
t.Errorf("MAGPIE_PUBLIC_URL=%q: %q, want %q", c.env, got, c.want)
|
|
}
|
|
}
|
|
// the page's own proxy address, when the gateway's is elsewhere
|
|
t.Setenv("MAGPIE_PUBLIC_URL", "https://api.example.com")
|
|
for _, c := range []struct{ env, want string }{
|
|
{"https://magpie.example.com/", "https://magpie.example.com/?k=0123456789abcdef"},
|
|
{"magpie.example.com:8443", "https://magpie.example.com:8443/?k=0123456789abcdef"},
|
|
{"https://magpie.example.com/?x=1", ""},
|
|
{"ftp://magpie.example.com", ""},
|
|
} {
|
|
t.Setenv("MAGPIE_WEB_URL", c.env)
|
|
if got := proxyLink(key); got != c.want {
|
|
t.Errorf("MAGPIE_WEB_URL=%q: %q, want %q", c.env, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// `magpie web` opens the app's page when the app serves it on the port it
|
|
// would take, and starts its own on any other.
|
|
func TestWebSamePort(t *testing.T) {
|
|
for _, c := range []struct {
|
|
a, b string
|
|
want bool
|
|
}{
|
|
{"127.0.0.1:3430", "127.0.0.1:3430", true},
|
|
{"0.0.0.0:3430", "127.0.0.1:3430", true},
|
|
{"127.0.0.1:3430", "0.0.0.0:3431", false},
|
|
{"", "127.0.0.1:3430", false},
|
|
{"127.0.0.1:3430", "3430", false},
|
|
} {
|
|
if got := samePort(c.a, c.b); got != c.want {
|
|
t.Errorf("samePort(%q, %q) = %v", c.a, c.b, got)
|
|
}
|
|
}
|
|
}
|