- CHANGELOG.md:v2.8.0 条目(中英双语); - README.md:版本行 2.7.1→2.8.0 + 愿景第 6 条(知识可证明); - doc/releases/v2.8.0.md:双语发版说明(亮点/用法/已知限制); - skills/marqdo-dev/index.mq.md:新增 prove 任务(路径/目录模式/ require_lean/json;参数用 + 行声明升参,check 与 narrative-ratio 通过); - 设计文档 §12.5 标记已合入;发版链接统一指向 doc/releases/v2.8.0.md。
59 lines
1.7 KiB
Go
Executable File
59 lines
1.7 KiB
Go
Executable File
package httpx
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/marqdo/marqdo/plugins/web/internal/session"
|
|
)
|
|
|
|
func TestGoMuxPattern(t *testing.T) {
|
|
if got := goMuxPattern("/_media/{*key}"); got != "/_media/{key...}" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
if got := goMuxPattern("/post/{slug}"); got != "/post/{slug}" {
|
|
t.Fatalf("got %q", got)
|
|
}
|
|
}
|
|
|
|
func TestPathParamNamesIncludesID(t *testing.T) {
|
|
got := pathParamNames("/desk/posts/{id}")
|
|
if len(got) != 1 || got[0] != "id" {
|
|
t.Fatalf("got %#v", got)
|
|
}
|
|
got = pathParamNames("/post/{slug}")
|
|
if len(got) != 1 || got[0] != "slug" {
|
|
t.Fatalf("got %#v", got)
|
|
}
|
|
}
|
|
|
|
func TestResolveSessionReplacesStaleCookie(t *testing.T) {
|
|
session.Configure(session.Config{TTLSec: 3600})
|
|
session.Reset(3600)
|
|
|
|
req := httptest.NewRequest("GET", "/login", nil)
|
|
req.Header.Set("Cookie", "marqdo_sid="+strings.Repeat("ab", 32))
|
|
sid, csrf, setCookie := resolveSession(req)
|
|
if sid == "" || csrf == "" {
|
|
t.Fatalf("expected fresh sid+csrf, got sid=%q csrf=%q", sid, csrf)
|
|
}
|
|
if setCookie == nil || !strings.Contains(*setCookie, "marqdo_sid=") {
|
|
t.Fatalf("expected Set-Cookie for replacement session, got %#v", setCookie)
|
|
}
|
|
if !session.ValidateCSRF(sid, csrf) {
|
|
t.Fatal("csrf should validate for new session")
|
|
}
|
|
|
|
// Live session should keep the same id without re-issuing cookie.
|
|
req2 := httptest.NewRequest("GET", "/login", nil)
|
|
req2.Header.Set("Cookie", "marqdo_sid="+sid)
|
|
sid2, csrf2, setCookie2 := resolveSession(req2)
|
|
if sid2 != sid || csrf2 != csrf {
|
|
t.Fatalf("live session should be stable: %q/%q vs %q/%q", sid, csrf, sid2, csrf2)
|
|
}
|
|
if setCookie2 != nil {
|
|
t.Fatalf("live session should not Set-Cookie again")
|
|
}
|
|
}
|