Boot started a ticker goroutine inside lagoon.OnDatabase that nothing stopped, so every booting process (serve, each console command, each test boot) leaked one and swept the blacklist once per process. The sweep is now the console command user:jwt-blacklist-sweep, which the conga scheduler runs on the job worker every golem15.user.jwt.blacklist_sweep_interval (default 10m, 0 for none), once per period across instances. An interval the scheduler cannot run (unparsable, negative, under 1s, not dividing 24h) now fails boot.
60 lines
1.9 KiB
Go
60 lines
1.9 KiB
Go
package classes
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"git.golem15.com/golem15/summercms/modules/backpack"
|
|
)
|
|
|
|
// TestBlacklistSweepInterval reads golem15.user.jwt.blacklist_sweep_interval:
|
|
// 10m by default, 0 for no sweep (string, duration or unquoted YAML int, and
|
|
// from a SUMMER_ variable), and an error naming the key for a value the
|
|
// scheduler cannot run.
|
|
func TestBlacklistSweepInterval(t *testing.T) {
|
|
const key = "golem15.user.jwt.blacklist_sweep_interval"
|
|
if got, err := BlacklistSweepInterval(nil); got != DefaultBlacklistSweepInterval || err != nil {
|
|
t.Errorf("nil app: %v %v", got, err)
|
|
}
|
|
if got, err := BlacklistSweepInterval(&backpack.App{}); got != DefaultBlacklistSweepInterval || err != nil {
|
|
t.Errorf("nil config: %v %v", got, err)
|
|
}
|
|
if got, err := BlacklistSweepInterval(mailTestApp(t)); got != 10*time.Minute || err != nil {
|
|
t.Errorf("unset: %v %v", got, err)
|
|
}
|
|
for _, tc := range []struct {
|
|
value any
|
|
want time.Duration
|
|
}{
|
|
{"10m", 10 * time.Minute},
|
|
{"1h", time.Hour},
|
|
{"30s", 30 * time.Second},
|
|
{"24h", 24 * time.Hour},
|
|
{" 1m ", time.Minute},
|
|
{"0", 0},
|
|
{"0s", 0},
|
|
{0, 0},
|
|
} {
|
|
app := mailTestApp(t)
|
|
if err := app.Config.Set(key, tc.value); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, err := BlacklistSweepInterval(app); got != tc.want || err != nil {
|
|
t.Errorf("%#v: %v %v, want %v", tc.value, got, err, tc.want)
|
|
}
|
|
}
|
|
if got, err := BlacklistSweepInterval(mailTestApp(t, "SUMMER_GOLEM15__USER__JWT__BLACKLIST_SWEEP_INTERVAL=0")); got != 0 || err != nil {
|
|
t.Errorf("SUMMER_ 0: %v %v", got, err)
|
|
}
|
|
for _, bad := range []any{"soon", "3", "-1m", "500ms", "7m", "48h", -5} {
|
|
app := mailTestApp(t)
|
|
if err := app.Config.Set(key, bad); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got, err := BlacklistSweepInterval(app); err == nil || got != 0 || !strings.Contains(err.Error(), key) {
|
|
t.Errorf("%#v: %v %v, want an error naming %s", bad, got, err, key)
|
|
}
|
|
}
|
|
}
|