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
52 lines
1.6 KiB
Go
52 lines
1.6 KiB
Go
package im
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/Tencent/WeKnora/internal/types"
|
|
)
|
|
|
|
func TestWithIMIdentity(t *testing.T) {
|
|
const tenantID uint64 = 42
|
|
msg := &IncomingMessage{Platform: PlatformFeishu, UserID: "open-id-1"}
|
|
ctx := withIMIdentity(context.Background(), tenantID, "channel-1", msg)
|
|
|
|
gotTenant, ok := types.TenantIDFromContext(ctx)
|
|
if !ok || gotTenant != tenantID {
|
|
t.Fatalf("TenantID = %d (ok=%v), want %d", gotTenant, ok, tenantID)
|
|
}
|
|
|
|
userID, ok := types.UserIDFromContext(ctx)
|
|
if !ok || userID == "" {
|
|
t.Fatalf("UserID = %q (ok=%v), want non-empty synthetic user", userID, ok)
|
|
}
|
|
if want := "system-42"; userID != want {
|
|
t.Fatalf("UserID = %q, want %q", userID, want)
|
|
}
|
|
|
|
// The synthetic shape must be recognised so RBAC code does not record it
|
|
// as a resource creator.
|
|
if !types.IsSyntheticUserID(userID) {
|
|
t.Fatalf("IsSyntheticUserID(%q) = false, want true", userID)
|
|
}
|
|
|
|
// Non-empty UserID is the gate the shared-KB resolution relies on; without
|
|
// it Organization-shared KBs are silently skipped on the IM path.
|
|
if role := types.TenantRoleFromContext(ctx); role != types.TenantRoleViewer {
|
|
t.Fatalf("TenantRole = %v, want %v", role, types.TenantRoleViewer)
|
|
}
|
|
|
|
principal, ok := types.PrincipalFromContext(ctx)
|
|
if !ok {
|
|
t.Fatalf("Principal missing")
|
|
}
|
|
if principal.Type != types.PrincipalIMUser || principal.ID != "42:channel-1:feishu:open-id-1" {
|
|
t.Fatalf("Principal = %#v, want im_user for the external IM user", principal)
|
|
}
|
|
|
|
if !types.IsMCPOAuthNonInteractive(ctx) {
|
|
t.Fatal("IM context should mark MCP OAuth as non-interactive")
|
|
}
|
|
}
|