WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
Anydoc / anydoc parser engine (push) Canceled after 0s
App / Format, vet, test, and build (push) Canceled after 0s
CLI / test (macos-latest / go 1.26) (push) Canceled after 0s
CLI / test (ubuntu-latest / go 1.26) (push) Canceled after 0s
CLI / test (windows-latest / go 1.26) (push) Canceled after 0s
Build and Push Docker Image / build-ui (push) Canceled after 0s
Build and Push Docker Image / build-docreader (push) Canceled after 0s
Build and Push Docker Image / build-sandbox (push) Canceled after 0s
Build and Push Docker Image / build-app (amd64, linux/amd64, ubuntu-latest) (push) Canceled after 0s
Build and Push Docker Image / build-app (arm64, linux/arm64, ubuntu-24.04-arm) (push) Canceled after 0s
DocReader / Python tests and Go client tests (push) Canceled after 0s
Build & Publish (dsh-weknora) / Typecheck, test, pack (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (pinned) (push) Canceled after 0s
Build & Publish (dsh-weknora) / End-to-end inside dsh (latest, advisory) (push) Canceled after 0s
Frontend / Test, type-check, and build (push) Canceled after 0s
Go Lint Cache / warm lint cache (.) (push) Canceled after 0s
Go Lint Cache / warm lint cache (cli) (push) Canceled after 0s
Go Lint Cache / warm lint cache (client) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.10) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.11) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.12) (push) Canceled after 0s
Build & Publish (mcp-server) / Test (Python 3.13) (push) Canceled after 0s
Build and Push Docker Image / merge (push) Canceled after 0s
Build & Publish (dsh-weknora) / Publish to npm (push) Canceled after 0s
Build & Publish (mcp-server) / Build sdist + wheel (push) Canceled after 0s
Build & Publish (mcp-server) / Publish to PyPI (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"github.com/Tencent/WeKnora/internal/types"
|
||||
)
|
||||
|
||||
func TestRequireTenantAPIKeyKnowledgeBaseAllowsUnrestrictedCaller(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
if err := requireTenantAPIKeyKnowledgeBase(ctx, "kb-1"); err != nil {
|
||||
t.Fatalf("unrestricted caller error = %v, want nil", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequireTenantAPIKeyKnowledgeBaseRejectsOutOfScopeKB(t *testing.T) {
|
||||
ctx := types.WithTenantAPIKeyScope(context.Background(), types.TenantAPIKeyScope{
|
||||
KnowledgeBaseIDs: types.StringArray{"kb-1"},
|
||||
})
|
||||
if err := requireTenantAPIKeyKnowledgeBase(ctx, "kb-2"); err == nil {
|
||||
t.Fatal("expected forbidden for out-of-scope kb_id")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntersectKBAllowSetCombinesAgentAndAPIKeyScopes(t *testing.T) {
|
||||
got := intersectKBAllowSet(
|
||||
map[string]bool{"kb-1": true, "kb-2": true},
|
||||
map[string]bool{"kb-2": true, "kb-3": true},
|
||||
)
|
||||
if len(got) != 1 || !got["kb-2"] {
|
||||
t.Fatalf("intersection = %#v, want only kb-2", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterKnowledgesByKBAllowSet(t *testing.T) {
|
||||
in := []*types.Knowledge{
|
||||
{ID: "k1", KnowledgeBaseID: "kb-1"},
|
||||
{ID: "k2", KnowledgeBaseID: "kb-2"},
|
||||
}
|
||||
got := filterKnowledgesByKBAllowSet(in, map[string]bool{"kb-1": true})
|
||||
if len(got) != 1 || got[0].ID != "k1" {
|
||||
t.Fatalf("filtered = %#v, want only k1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFilterKnowledgeSearchScopesForAPIKey(t *testing.T) {
|
||||
ctx := types.WithTenantAPIKeyScope(context.Background(), types.TenantAPIKeyScope{
|
||||
KnowledgeBaseIDs: types.StringArray{"kb-1"},
|
||||
})
|
||||
scopes := []types.KnowledgeSearchScope{
|
||||
{TenantID: 1, KBID: "kb-1"},
|
||||
{TenantID: 1, KBID: "kb-2"},
|
||||
}
|
||||
got := filterKnowledgeSearchScopesForAPIKey(ctx, scopes)
|
||||
if len(got) != 1 || got[0].KBID != "kb-1" {
|
||||
t.Fatalf("filtered scopes = %#v, want only kb-1", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestTenantAPIKeySearchScopesUsesCallerTenant(t *testing.T) {
|
||||
ctx := types.WithTenantAPIKeyScope(context.Background(), types.TenantAPIKeyScope{
|
||||
KnowledgeBaseIDs: types.StringArray{"kb-1", "kb-2"},
|
||||
})
|
||||
ctx = context.WithValue(ctx, types.TenantIDContextKey, uint64(42))
|
||||
|
||||
scopes, restricted := tenantAPIKeySearchScopes(ctx)
|
||||
if !restricted {
|
||||
t.Fatal("expected restricted search scopes")
|
||||
}
|
||||
if len(scopes) != 2 {
|
||||
t.Fatalf("scopes len = %d, want 2", len(scopes))
|
||||
}
|
||||
for _, scope := range scopes {
|
||||
if scope.TenantID != 42 {
|
||||
t.Fatalf("scope tenant_id = %d, want 42", scope.TenantID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequireTenantAPIKeyKnowledgeBasesRejectsPartialOverlap(t *testing.T) {
|
||||
ctx := types.WithTenantAPIKeyScope(context.Background(), types.TenantAPIKeyScope{
|
||||
KnowledgeBaseIDs: types.StringArray{"kb-1"},
|
||||
})
|
||||
if err := requireTenantAPIKeyKnowledgeBases(ctx, "kb-1", "kb-2"); err == nil {
|
||||
t.Fatal("expected forbidden when one kb_id is out of scope")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user