feat(web): Go W-G5 session, auth, password, and RBAC gates

Wire password hash, session CRUD, auth login/check/logout, and
app.auth/gate ABIs so security and C0/C1 offline smokes pass on libweb.so.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
cflmyandCursor committed 2026-09-10 17:31:07 +08:00
1 parent 4357045904
commit 6e94d0a179
14 files changed
+1592 -10

No files matched your search

@@ -0,0 +1,86 @@
package session_test
import (
"os"
"path/filepath"
"testing"
"github.com/marqdo/marqdo/plugins/web/internal/db"
"github.com/marqdo/marqdo/plugins/web/internal/session"
)
func TestSessionSetGetDel(t *testing.T) {
session.Configure(session.Config{TTLSec: 3600})
session.Reset(3600)
id := session.NewID(0)
if id == "" {
t.Fatal("empty id")
}
if !session.SetValue(id, "username", "admin") {
t.Fatal("set")
}
v, ok := session.GetValue(id, "username")
if !ok || v != "admin" {
t.Fatalf("get=%v ok=%v", v, ok)
}
got := session.Get(id, "username")
if got["ok"] != true || got["value"] != "admin" {
t.Fatalf("Get ABI: %v", got)
}
if !session.DelKey(id, "username") {
t.Fatal("del")
}
if _, ok := session.GetValue(id, "username"); ok {
t.Fatal("del leftover")
}
if !session.DestroyID(id) {
t.Fatal("destroy")
}
}
func TestCSRFAndCookie(t *testing.T) {
session.Reset(3600)
id := session.NewID(0)
tok, ok := session.CSRFFor(id)
if !ok || tok == "" {
t.Fatal("csrf")
}
if !session.ValidateCSRF(id, tok) {
t.Fatal("validate")
}
if session.ValidateCSRF(id, "bad") {
t.Fatal("bad csrf")
}
cookie := session.SessionCookie(id, 3600, false)
got, ok := session.IDFromCookie("theme=light; " + cookie)
if !ok || got != id {
t.Fatalf("cookie parse %q != %q", got, id)
}
}
func TestSessionPersistsInSQLite(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "persist.db")
url := "sqlite:" + path
db.ResetPool()
session.Configure(session.Config{DBURL: url, TTLSec: 3600})
id := session.NewID(0)
if !session.SetValue(id, "theme", "dark") {
t.Fatal("set")
}
session.Configure(session.Config{DBURL: url, TTLSec: 3600})
v, ok := session.GetValue(id, "theme")
if !ok || v != "dark" {
t.Fatalf("persist get=%v ok=%v", v, ok)
}
_ = os.RemoveAll(dir)
}
func TestNewABI(t *testing.T) {
session.Reset(120)
out := session.New(120)
id, _ := out["id"].(string)
if id == "" {
t.Fatal(out)
}
}