Extract Grammaratur, Dregarnuhr, Geduldh, Mestionora, Ordoschnellic, Schutzaria, Kunstzeal and Seheweit behind compatible application contracts. Include accumulated editor resilience, navigation and theme UX, remote CLI, storage/schema and DR groundwork, tests and design/operations documentation. Verified: uncached full Go suite; go vet ./...; race tests for all eight components; 11 targeted Chromium tests; Node suites; 19 Python CLI tests; reproducible editor build. No push, release tag or deployment in this checkpoint.
51 lines
1.7 KiB
Go
51 lines
1.7 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/url"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestSessionPolicyAdminUIAndCookie(t *testing.T) {
|
|
s, token, domain := configFixture(t)
|
|
form := url.Values{"action": {"save_session_policy"}, "session_minutes": {"60"}}
|
|
w := configRequest(s, token, "POST", "/-/sys/config/auth", form)
|
|
if w.Code != http.StatusSeeOther || w.Header().Get("Location") != "/-/sys/config?panel=auth-sessions&saved=1" {
|
|
t.Fatalf("policy save %d %s", w.Code, w.Body.String())
|
|
}
|
|
if s.store.AuthSessionLifetimeMinutes(domain) != 60 {
|
|
t.Fatal("policy not saved")
|
|
}
|
|
w = configRequest(s, token, "GET", "/-/sys/config?panel=auth-sessions", nil)
|
|
if w.Code != 200 || !strings.Contains(w.Body.String(), `name="session_minutes" value="60"`) {
|
|
t.Fatal("policy control missing")
|
|
}
|
|
for _, bad := range []string{"", "abc", "0", "99999999999999999999999"} {
|
|
form.Set("session_minutes", bad)
|
|
if w = configRequest(s, token, "POST", "/-/sys/config/auth", form); w.Code != 400 {
|
|
t.Fatalf("bad lifetime %q accepted", bad)
|
|
}
|
|
}
|
|
user, err := s.store.CreatePasswordAccount(domain, "reader", "a long test password", "Reader", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
reader, err := s.store.CreateAuthSession(domain, user.UUID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
form.Set("session_minutes", "120")
|
|
if w = configRequest(s, reader, "POST", "/-/sys/config/auth", form); w.Code != 403 {
|
|
t.Fatalf("non-admin policy change: %d", w.Code)
|
|
}
|
|
w = httptest.NewRecorder()
|
|
r := httptest.NewRequest("GET", "https://localhost/", nil)
|
|
s.setAuthCookie(w, r, "fixture-token")
|
|
cookies := w.Result().Cookies()
|
|
if len(cookies) != 1 || cookies[0].MaxAge != 3600 || !cookies[0].HttpOnly || !cookies[0].Secure {
|
|
t.Fatalf("cookie policy %#v", cookies)
|
|
}
|
|
}
|