feat: make http session cookie path & duration configurable (fixes #10522) (#10632)

Signed-off-by: Vikram Vaswani <2571660+vvaswani@users.noreply.github.com>
Signed-off-by: Jakob Borg <jakob@kastelo.net>
Co-authored-by: Jakob Borg <jakob@kastelo.net>
This commit is contained in:
vvaswani
2026-04-26 07:59:24 +00:00
committed by GitHub
co-authored by Jakob Borg
parent 1f57187461
commit 987e631176
5 changed files with 124 additions and 17 deletions
+41
View File
@@ -7,6 +7,7 @@
package api
import (
"math"
"testing"
"time"
@@ -192,3 +193,43 @@ func TestTokenManager(t *testing.T) {
t.Errorf("token %q should be invalid", t3)
}
}
func TestTokenManagerNoExpiry(t *testing.T) {
t.Parallel()
mdb, err := sqlite.Open(t.TempDir())
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
mdb.Close()
})
kdb := db.NewMiscDB(mdb)
clock := &mockClock{now: time.Now()}
tm := newTokenManager("testTokensNoExpiry", kdb, -1, 3)
tm.timeNow = clock.Now
token := tm.New()
if expiry, ok := tm.tokens.Tokens[token]; !ok || expiry != 0 {
t.Fatalf("token should have no expiry, got %d", expiry)
}
clock.wind(365 * 24 * time.Hour)
if !tm.Check(token) {
t.Fatal("token should still be valid after long time when no-expiry is enabled")
}
}
func TestSessionCookieMaxAgeNoExpiry(t *testing.T) {
t.Parallel()
m := tokenCookieManager{
guiCfg: config.GUIConfiguration{
SessionCookieDurationS: -1,
},
}
if got := m.sessionCookieMaxAge(); got != math.MaxInt32 {
t.Fatalf("unexpected max age %d", got)
}
}