package handlers import ( "html" "net/http" "net/url" "regexp" "strings" "testing" "github.com/mixeme/selfpost/internal/store" "github.com/mixeme/selfpost/internal/web/auth" ) // ---- System log // The page and the fragment polled from it show the tail of mail.log, newest // line first, with the time split off each line. func TestSystemLogPageAndFragmentShowTheTail(t *testing.T) { h := &Handlers{view: mustView(t), cfg: Config{Version: "test"}} h.cfg.MailLogPath = writeMailLog(t, "Sep 21 13:58:09 mail postfix/smtp[2123]: 4XcB7k2Jm9z1: to=, status=deferred (451 Greylisted)", "Sep 21 14:01:52 mail postfix/qmgr[58]: 4XcB9q0Lw2z1: removed", "a line the log format does not stamp", ) page := getBody(t, h.HandleSystemLog, "/server/log") for _, want := range []string{ `

System log

`, `hx-get="/server/log/fragment"`, `Sep 21 14:01:52 mail postfix/qmgr[58]: 4XcB9q0Lw2z1: removed`, `mail postfix/smtp[2123]`, // a deferral is amber `a line the log format does not stamp`, } { if !strings.Contains(page, want) { t.Errorf("the system log page is missing %q", want) } } if strings.Index(page, "a line the log format") > strings.Index(page, "postfix/qmgr") || strings.Index(page, "postfix/qmgr") > strings.Index(page, "postfix/smtp[2123]") { t.Error("the log is not shown newest line first") } frag := getBody(t, h.HandleSystemLogBody, "/server/log/fragment") if !strings.HasPrefix(frag, `
root you`, `root@example.org`, `global`, `domain`, `out.example.comin.example.com`, `All—`, `User updated.`, `3 users`, `href="/server/users/new"`, `Inbound domains`, } { if !strings.Contains(body, want) { t.Errorf("the users page is missing %q", want) } } h.cfg.InboundEnabled = false if body := send(h.HandleUsers, &root, "GET", "/server/users", nil, nil).Body.String(); strings.Contains(body, "Inbound domains") { t.Error("the users list has an inbound column while the inbound feature is off") } } // ---- The user form var ( tagRe = regexp.MustCompile(`<(input|select)\b[^>]*>`) attrRe = regexp.MustCompile(`([a-z-]+)(?:="([^"]*)")?`) optionRe = regexp.MustCompile(`