The link holds the admin token. Where the terminal is a log (containers) it would end up in log storage; the notice then only says where the token file is. The Kubernetes manifest uses it. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
35 lines
1.2 KiB
Go
35 lines
1.2 KiB
Go
package main
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestLoginURL(t *testing.T) {
|
|
for addr, want := range map[string]string{
|
|
"127.0.0.1:8080": "http://127.0.0.1:8080/#/login/tok",
|
|
"0.0.0.0:8080": "http://127.0.0.1:8080/#/login/tok", // a wildcard cannot be opened
|
|
"[::]:9000": "http://127.0.0.1:9000/#/login/tok",
|
|
"[::1]:8080": "http://[::1]:8080/#/login/tok",
|
|
"192.0.2.7:80": "http://192.0.2.7:80/#/login/tok",
|
|
} {
|
|
if got := loginURL(addr, "tok"); got != want {
|
|
t.Errorf("loginURL(%q) = %q, want %q", addr, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestLoginNoticeCanHideTheLink(t *testing.T) {
|
|
shown := loginNotice("127.0.0.1:8080", "sekret", false, true, "/data")
|
|
if !strings.Contains(shown, "#/login/sekret") || !strings.Contains(shown, "follows no region") {
|
|
t.Fatalf("the default shows the link and the region hint:\n%s", shown)
|
|
}
|
|
hidden := loginNotice("127.0.0.1:8080", "sekret", true, true, "/data")
|
|
if strings.Contains(hidden, "sekret") || strings.Contains(hidden, "login/") {
|
|
t.Fatalf("the token must not be printed:\n%s", hidden)
|
|
}
|
|
if !strings.Contains(hidden, "/data/admin.token") {
|
|
t.Fatalf("it should say where the token is:\n%s", hidden)
|
|
}
|
|
}
|