feat: add browser upload queue and trusted sessions with bounded projections
Build and publish container images / images (push) Successful in 11m37s
Release container images / release (push) Successful in 22s

This commit is contained in:
Anya Tokugawa committed 2026-11-08 20:27:04 +09:00
1 parent 84d52390f9
commit b90aef79d0
79 files changed
+1962 -196

No files matched your search

@@ -6,6 +6,7 @@ import (
"net/url"
"strings"
"testing"
"time"
)
func TestSessionPolicyAdminUIAndCookie(t *testing.T) {
@@ -48,3 +49,99 @@ func TestSessionPolicyAdminUIAndCookie(t *testing.T) {
t.Fatalf("cookie policy %#v", cookies)
}
}
func TestTrustedSessionPolicyAndRevocation(t *testing.T) {
s, admin, domain := configFixture(t)
p := s.mustCLIPrincipal(t, domain, admin)
for _, days := range []string{"30", "7", "0"} {
form := url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {days}}
w := configRequest(s, admin, "POST", "/-/sys/config/auth", form)
if w.Code != 303 {
t.Fatalf("policy %s: %d %s", days, w.Code, w.Body.String())
}
want := 24 * time.Hour
if days == "30" {
want *= 30
}
if days == "7" {
want *= 7
}
for _, browser := range []bool{false, true} {
token, lifetime, err := s.store.CreateLoginSession(domain, p, 0, browser, true)
if err != nil || lifetime != want {
t.Fatalf("duration %v %v", lifetime, err)
}
if _, err = s.store.PrincipalForSession(domain, token); err != nil {
t.Fatal(err)
}
if err = s.store.RevokeAuthSession(token); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
t.Fatal("revoked trusted session accepted")
}
}
w = httptest.NewRecorder()
s.handleAuth(w, httptest.NewRequest("GET", "https://localhost/_/auth/login", nil))
if strings.Contains(w.Body.String(), `id="auth-remember"`) != (days != "0") {
t.Fatal("login choice does not reflect policy")
}
}
for _, bad := range []string{"", "-1", "31", "abc"} {
w := configRequest(s, admin, "POST", "/-/sys/config/auth", url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {bad}})
if w.Code != 400 {
t.Fatalf("invalid policy %q accepted: %d", bad, w.Code)
}
}
user, err := s.store.CreatePasswordAccount(domain, "trusted-reader", "a long test password", "Reader", "")
if err != nil {
t.Fatal(err)
}
if err = s.store.SetConfigInDomain(domain, "auth_trusted_session_days", "30"); err != nil {
t.Fatal(err)
}
token, _, err := s.store.CreateLoginSession(domain, user.UUID, 0, false, true)
if err != nil {
t.Fatal(err)
}
w := configRequest(s, token, "POST", "/-/sys/config/auth", url.Values{"action": {"save_trusted_session_policy"}, "trusted_session_days": {"7"}})
if w.Code != 403 {
t.Fatalf("reader changed trusted policy: %d", w.Code)
}
if err = s.store.SetPrincipalState(domain, user.UUID, "suspended"); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
t.Fatal("suspended trusted session accepted")
}
}
func TestTrustedSessionExpiryIsFixed(t *testing.T) {
s, admin, domain := configFixture(t)
p := s.mustCLIPrincipal(t, domain, admin)
token, lifetime, err := s.store.CreateLoginSession(domain, p, 0, false, true)
if err != nil || lifetime != 30*24*time.Hour {
t.Fatalf("trusted default: %v %v", lifetime, err)
}
var id string
var expiry int64
if err = s.store.DB.QueryRow(`SELECT uuid,expires_at_ms FROM auth_sessions ORDER BY rowid DESC LIMIT 1`).Scan(&id, &expiry); err != nil {
t.Fatal(err)
}
if err = s.store.SetConfigInDomain(domain, "auth_trusted_session_days", "0"); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err != nil {
t.Fatal(err)
}
var after int64
if err = s.store.DB.QueryRow(`SELECT expires_at_ms FROM auth_sessions WHERE uuid=?`, id).Scan(&after); err != nil || after != expiry {
t.Fatalf("policy/read changed expiry: %d %d %v", expiry, after, err)
}
if _, err = s.store.DB.Exec(`UPDATE auth_sessions SET expires_at_ms=? WHERE uuid=?`, time.Now().Add(-time.Second).UnixMilli(), id); err != nil {
t.Fatal(err)
}
if _, err = s.store.PrincipalForSession(domain, token); err == nil {
t.Fatal("expired trusted session accepted")
}
}