An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
// SiYuan - https://github.com/siyuan-note/siyuan
// Copyright (c) 2020-present, b3log.org
// SPDX-License-Identifier: AGPL-3.0-or-later
package api
import (
"reflect"
"testing"
"github.com/gin-gonic/gin"
"github.com/siyuan-note/siyuan/kernel/apicontract"
"github.com/siyuan-note/siyuan/kernel/model"
)
func TestAPIContractAuthorizationHandlers(t *testing.T) {
handler := func(*gin.Context) {}
for _, test := range []struct {
actual []gin.HandlerFunc
want []gin.HandlerFunc
}{
{contractRouteHandlers(apicontract.Version, handler), []gin.HandlerFunc{handler}},
{contractRouteHandlers(apicontract.GetBlockDOM, handler), []gin.HandlerFunc{model.CheckAuth, handler}},
{contractRouteHandlers(apicontract.NetworkForwardProxy, handler), []gin.HandlerFunc{model.CheckAuth, model.CheckAdminRole, handler}},
{contractRouteHandlers(apicontract.ChangeAttrViewLayout, handler), []gin.HandlerFunc{model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, handler}},
{contractRouteHandlers(apicontract.SystemDownloadUpdate, handler), []gin.HandlerFunc{model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, handler}},
} {
if len(test.actual) != len(test.want) {
t.Fatalf("middleware count changed: got %d want %d", len(test.actual), len(test.want))
}
for index, expected := range test.want {
if reflect.ValueOf(test.actual[index]).Pointer() != reflect.ValueOf(expected).Pointer() {
t.Fatalf("middleware order changed at %d", index)
}
}
}
}