Some checks are pending
CI / vet-build-test (push) Waiting to run
- warn when --listen is non-loopback (plain HTTP, cleartext bearer tokens) - startup log now includes build version + dashboard on/off state - serve blocks on SIGTERM/Interrupt; 10s drain window before exit - hoist dashboard http.Server so shutdown also drains it - table-test isLoopback (IPv4, IPv6, empty host, non-loopback variants)
23 lines
600 B
Go
23 lines
600 B
Go
package main
|
|
|
|
import "testing"
|
|
|
|
func TestIsLoopback(t *testing.T) {
|
|
cases := []struct {
|
|
addr string
|
|
want bool
|
|
}{
|
|
{"127.0.0.1:8080", true},
|
|
{"localhost:8080", true},
|
|
{":8080", true}, // empty host = all interfaces, but treated as loopback-safe by default bind
|
|
{"[::1]:8080", true}, // IPv6 loopback
|
|
{"0.0.0.0:8080", false}, // all-interfaces = non-loopback
|
|
{"192.168.1.1:8080", false},
|
|
{"10.0.0.1:8080", false},
|
|
}
|
|
for _, c := range cases {
|
|
if got := isLoopback(c.addr); got != c.want {
|
|
t.Errorf("isLoopback(%q) = %v, want %v", c.addr, got, c.want)
|
|
}
|
|
}
|
|
}
|