A user's computer has a static public address from its ISP on the network card itself (203.236.50.70) as well as a private one (10.77.70.2). Settings › Network & sharing listed 203.236.50.70 as the gateway's address but only 10.77.70.2 under "Open magpie in a browser", and they asked why the two differ. The gateway's list (gateway.LANURLs) took every IPv4 address on an interface that is up; the page's (gui.LANAddrs) took private ones only, through net.InterfaceAddrs, down interfaces included. The page server in LAN mode listens on 0.0.0.0, so the public address serves it too. Now one list makes both: gateway.LANHosts, every interface that is up, IPv4, not loopback or link-local, in the interfaces' order. gui.LANAddrs (and so NetworkLinks, the CLI's `magpie web` and daemon links) returns it, MAGPIE_PUBLIC_URL's host still first when set. The page's links now also show a CGNAT/Tailscale 100.64.x address, as the gateway's already did. Run, on mote: go vet ./internal/gateway ./internal/gui ./internal/cli; GOOS=windows go vet ./internal/gateway ./internal/gui; GOOS=linux go vet ./internal/gateway; go test -run "LAN|Lan|URL|TLS|Public|Network|Share|Allow|Container" ./internal/gateway ok; go test ./internal/gui ./internal/cli: cli ok, gui ok but for TestMainWindowCorners/macOS_26_SDK, #3949 (macOS 27, not about addresses). On xiaomi-gpu (Windows): the gateway's LANHosts, PublicURL and TLS address tests ok. New: TestLANHostsKeepAPublicAddress (a stubbed public, private, CGNAT, link-local, loopback and IPv6 address) and TestNetworkLinksAtTheGatewaysHosts. Broken by hand: LANHosts keeping private addresses only, as the page's list did, turns TestLANHostsKeepAPublicAddress red (got [10.77.70.2]). Not run: GOOS=linux vet of internal/gui (needs cgo; the WSL box lacks gtk4 and webkitgtk-6.0 headers); not tried on the reporter's machine.
45 lines
1.7 KiB
Go
45 lines
1.7 KiB
Go
package gui
|
|
|
|
import (
|
|
"net"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/yetone/magpie/internal/gateway"
|
|
)
|
|
|
|
// magpie web behind a reverse proxy (#372): MAGPIE_PUBLIC_URL with no port
|
|
// of its own is where the page is, so the link printed for other machines
|
|
// is it, scheme, path and all — not http://<its host>:<the page's port>,
|
|
// which nothing answers. One with a port names the host the container's
|
|
// ports are published on, and the page is there on its own port.
|
|
func TestNetworkLinksPublicURL(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"},
|
|
{"https://nas.example.com/magpie/", "https://nas.example.com/magpie/?k=0123456789abcdef"},
|
|
{"http://192.168.1.20:3425", "http://192.168.1.20:3430/?k=0123456789abcdef"},
|
|
{"nas.local:13425", "http://nas.local:3430/?k=0123456789abcdef"},
|
|
} {
|
|
t.Setenv("MAGPIE_PUBLIC_URL", c.env)
|
|
if got := NetworkLinks("3430", key); !slices.Equal(got, []string{c.want}) {
|
|
t.Errorf("MAGPIE_PUBLIC_URL=%q: %v, want %s", c.env, got, c.want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// The links printed for other machines are at the gateway's own addresses
|
|
// (gateway.LANHosts), one for one: Settings showed a computer's static
|
|
// public address under the gateway and not under the page.
|
|
func TestNetworkLinksAtTheGatewaysHosts(t *testing.T) {
|
|
t.Setenv("MAGPIE_PUBLIC_URL", "")
|
|
var want []string
|
|
for _, h := range gateway.LANHosts() {
|
|
want = append(want, "http://"+net.JoinHostPort(h, "3430")+"/?k=k")
|
|
}
|
|
if got := NetworkLinks("3430", "/?k=k"); !slices.Equal(got, want) {
|
|
t.Errorf("%v, want %v", got, want)
|
|
}
|
|
}
|