The user whose network card holds a static public address (203.236.50.70,27bf14790) asked on Discord, on the latest version, whether "Share on local network" should be exposed at a public address. LANHosts kept the interfaces' order, so the public address came first: Settings offered it as the share address by default, and the Gateway page listed it under "Local network". The gateway does answer there while shared (it listens on every address), behind a gateway key, and nothing said so. - LANHosts puts private addresses first (RFC 1918, 100.64/10 for Tailscale, 198.18/15 for proxy TUNs), the public ones after in the interfaces' order; LANURLs, magpie web's links and the CLI follow. - gateway.PublicIP / PublicURLs name the internet ones; /api/settings and /api/providers' gateway give them as lanPublic. - Settings marks such an address "On the internet" in the picker, and picked, the row says anyone online can reach magpie there with a key and to list the network's range under Allowed addresses (or, with a list, that only it gets in). The Gateway page lists it under "On the internet", not "Local network". zh, zh-TW, ja, de. - Not changed: with no allow list every address is still let in. Refusing internet peers by default would shut out networks whose computers all hold public addresses (campus networks, this user's ISP setup), so the address is named and the allow list pointed to instead. Run on mote at4ca64c21bplus this change: gofmt; go vet ./internal/gateway ./internal/gui; GOOS=windows go vet ./internal/gateway ./internal/gui; GOOS=linux go vet ./internal/gateway; go test ./internal/gateway -run 'LAN|Lan|URL|TLS|Public|Network|Share|Allow|Container' ok; go test -tags nogui ./internal/gui ./internal/cli ok; node --test lan-public (new), lan-docker, gateway-card, gateway-connect-keys, public-url, browser-access, i18n-keys: 73/74, the red is i18n-keys' "a plugin's words are its own" on routing's "masking…", #4053, red on main. Every file using the caller-keys fixture (changed: lanPublic) ata8c71f198: the reds are gateway-key-cycle, gateway-key-limit and a flaky connect-snippet-shell, the same on untoucheda8c71f198, filed as #4072. Broken by hand: public-first order turns TestLANHostsKeepAPublicAddress red; no Settings note, or no Gateway-page split, turns lan-public red (3/3 chromium). Not tried: a real machine with a public address on its card.
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package gateway
|
|
|
|
import (
|
|
"net"
|
|
"slices"
|
|
"testing"
|
|
)
|
|
|
|
// A computer whose ISP assigns a static public address to its network
|
|
// card is reached there as well as at its private one: both are offered,
|
|
// private ones first, and the public ones are named. Loopback, link-local
|
|
// and IPv6 are not offered.
|
|
func TestLANHostsKeepAPublicAddress(t *testing.T) {
|
|
t.Setenv("MAGPIE_PUBLIC_URL", "")
|
|
t.Setenv("MAGPIE_ADDR", "")
|
|
was := hostIPs
|
|
t.Cleanup(func() { hostIPs = was })
|
|
hostIPs = func() []net.IP {
|
|
var out []net.IP
|
|
for _, s := range []string{"203.236.50.70", "10.77.70.2", "100.64.0.1", "169.254.3.4", "127.0.0.2", "fe80::1", "2001:db8::5", "198.18.0.1", "8.8.4.4"} {
|
|
out = append(out, net.ParseIP(s))
|
|
}
|
|
return out
|
|
}
|
|
// private ones first, so the address Settings offers by default is on
|
|
// this network; the public ones after, in the interfaces' order
|
|
want := []string{"10.77.70.2", "100.64.0.1", "198.18.0.1", "203.236.50.70", "8.8.4.4"}
|
|
if got := LANHosts(); !slices.Equal(got, want) {
|
|
t.Fatalf("LANHosts: %v, want %v", got, want)
|
|
}
|
|
var urls []string
|
|
for _, h := range want {
|
|
urls = append(urls, Scheme()+"://"+net.JoinHostPort(h, Port()))
|
|
}
|
|
if got := LANURLs(); !slices.Equal(got, urls) {
|
|
t.Errorf("LANURLs: %v, want %v", got, urls)
|
|
}
|
|
if got := PublicURLs(urls); !slices.Equal(got, urls[3:]) {
|
|
t.Errorf("PublicURLs: %v, want %v", got, urls[3:])
|
|
}
|
|
}
|