fix: allow agent JWT to use attached online_db_id (Z14c)

Agent tokens use agent_id as user_id while Binding is under the human member; authorize schema/push/ensure against the agent's mounted OnlineDBID.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
whm
2026-08-05 18:22:57 +08:00
parent 4fae7ae718
commit bb59bb5efd
3 changed files with 63 additions and 10 deletions

View File

@@ -0,0 +1,20 @@
package handler
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"aijianzhan/platform/internal/authx"
)
func TestAgentOwnsOnlineDBUsesContextAgent(t *testing.T) {
// 无 Agents store 时必须安全返回 false
r := httptest.NewRequest(http.MethodPost, "/", nil)
ctx := authx.WithFullClaims(context.Background(), 2, 99, authx.Role智能体, 99, 0, []string{authx.Perm数据同步})
r = r.WithContext(ctx)
if agentOwnsOnlineDB(nil, r, 2, "ch1", "ch1_u3") {
t.Fatal("expected false without svc")
}
}