feat: scope API MCP OAuth by principal

This commit is contained in:
wizardchen
2026-06-30 09:21:49 +08:00
committed by lyingbug
parent 77e4f93e3e
commit cb99736d72
39 changed files with 1566 additions and 108 deletions
+10 -1
View File
@@ -9,7 +9,8 @@ import (
func TestWithIMIdentity(t *testing.T) {
const tenantID uint64 = 42
ctx := withIMIdentity(context.Background(), tenantID)
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 {
@@ -35,4 +36,12 @@ func TestWithIMIdentity(t *testing.T) {
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)
}
}