Files
xinmi/internal/handler/initialization_config_redaction_test.go
T
yawan f7fc992f57
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
WeKnora deployment source with the reviewed wiki identity, summary and recovery fixes
2026-09-22 16:19:06 +08:00

59 lines
1.7 KiB
Go

package handler
import (
"context"
"encoding/json"
"testing"
"github.com/Tencent/WeKnora/internal/types"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestBuildConfigResponse_ViewerOmitsModelBaseURL(t *testing.T) {
h := &InitializationHandler{}
ctx := context.WithValue(context.Background(), types.TenantRoleContextKey, types.TenantRoleViewer)
models := []*types.Model{{
Type: types.ModelTypeKnowledgeQA,
Name: "custom-llm",
Parameters: types.ModelParameters{
BaseURL: "https://tenant-private.example.com",
APIKey: "sk-secret-do-not-leak",
},
}}
kb := &types.KnowledgeBase{}
config := h.buildConfigResponse(ctx, models, kb, false)
llm, ok := config["llm"].(map[string]interface{})
require.True(t, ok)
assert.Empty(t, llm["baseUrl"])
body, err := json.Marshal(config)
require.NoError(t, err)
assert.NotContains(t, string(body), "tenant-private.example.com")
assert.NotContains(t, string(body), "sk-secret-do-not-leak")
}
func TestBuildConfigResponse_AdminKeepsModelBaseURL(t *testing.T) {
h := &InitializationHandler{}
ctx := context.WithValue(context.Background(), types.TenantRoleContextKey, types.TenantRoleAdmin)
models := []*types.Model{{
Type: types.ModelTypeKnowledgeQA,
Name: "custom-llm",
Parameters: types.ModelParameters{
BaseURL: "https://tenant-private.example.com",
APIKey: "sk-secret-do-not-leak",
},
}}
kb := &types.KnowledgeBase{}
config := h.buildConfigResponse(ctx, models, kb, false)
llm, ok := config["llm"].(map[string]interface{})
require.True(t, ok)
assert.Equal(t, "https://tenant-private.example.com", llm["baseUrl"])
body, err := json.Marshal(config)
require.NoError(t, err)
assert.NotContains(t, string(body), "sk-secret-do-not-leak")
}