release / release (push) Failing after 18s
For Guard's jarl preset and fail2ban: msg="login failed" ip=... user=... and msg="token refused" ip=..., beside the audit records. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
24 lines
768 B
Go
24 lines
768 B
Go
package server
|
|
|
|
import (
|
|
"bytes"
|
|
"log/slog"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
// TestFailedLoginLogged: a failed login and a refused token are logged
|
|
// with the address first, for Guard's and fail2ban's patterns.
|
|
func TestFailedLoginLogged(t *testing.T) {
|
|
e := newAPIEnv(t)
|
|
var buf bytes.Buffer
|
|
e.srv.log = slog.New(slog.NewTextHandler(&buf, nil))
|
|
e.req("POST", "/auth/login", "", map[string]string{"username": "x ip=8.8.8.8", "password": "wrong"})
|
|
e.req("GET", "/zones", "jarl_aaaaaaaaaaaaaaaa_bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb", nil)
|
|
for _, want := range []string{`msg="login failed" ip=127.0.0.1 user="x ip=8.8.8.8"`, `msg="token refused" ip=127.0.0.1 reason=`} {
|
|
if !strings.Contains(buf.String(), want) {
|
|
t.Errorf("no %q in\n%s", want, buf.String())
|
|
}
|
|
}
|
|
}
|