ad6cdab418
The web proxy binds the wildcard and drops connections that are not loopback or Tailscale at both ends. A LAN listener is opt-in (web.lan) and refuses sign-in and signed-in pages over plain HTTP unless web.lan_plain_login is set. Existing installs keep their bind address with a warning. Without the LAN the mDNS advert carries only the tailnet and public routes (lan=0).
50 lines
1.6 KiB
Go
50 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
)
|
|
|
|
func TestMDNSEnvironmentSwitches(t *testing.T) {
|
|
for value, want := range map[string]bool{"": true, "1": true, "on": true, "off": false, "0": false, "FALSE": false, " disabled ": false} {
|
|
if got := envEnabled(value); got != want {
|
|
t.Errorf("envEnabled(%q) = %v, want %v", value, got, want)
|
|
}
|
|
}
|
|
for value, want := range map[string]int{"": 0, "8083": 8083, "x": 0, "70000": 0} {
|
|
if got := envPort(value); got != want {
|
|
t.Errorf("envPort(%q) = %d, want %d", value, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
// A loopback-only server with no proxy port publishes nothing and does not
|
|
// fail: the caller only defers a non-nil stop.
|
|
func TestAdvertiseSkipsLoopbackWithoutFailing(t *testing.T) {
|
|
if stop := advertise("127.0.0.1:0", 0, true); stop != nil {
|
|
stop()
|
|
t.Fatal("loopback-only server was advertised")
|
|
}
|
|
}
|
|
|
|
func TestSameAddressesIgnoresOrder(t *testing.T) {
|
|
a := []net.IP{net.ParseIP("10.0.0.75"), net.ParseIP("192.168.104.82")}
|
|
b := []net.IP{net.ParseIP("192.168.104.82"), net.ParseIP("10.0.0.75")}
|
|
if !sameAddresses(a, b) {
|
|
t.Fatal("same addresses in another order compared unequal")
|
|
}
|
|
if sameAddresses(a, b[:1]) || sameAddresses(nil, b) || sameAddresses(a, []net.IP{net.ParseIP("10.0.0.75"), net.ParseIP("10.0.0.76")}) {
|
|
t.Fatal("different address sets compared equal")
|
|
}
|
|
if !sameAddresses(nil, nil) {
|
|
t.Fatal("two empty sets must compare equal")
|
|
}
|
|
}
|
|
|
|
// keepAdvertising on a loopback-only server publishes nothing, keeps its
|
|
// watcher running and stops cleanly.
|
|
func TestKeepAdvertisingStopsCleanly(t *testing.T) {
|
|
stop := keepAdvertising("127.0.0.1:0", 0, true)
|
|
stop()
|
|
}
|