Skip to content

RAGFlow is an agent-native database: a Retrieval-Augmented Generation (RAG) engine that grew into context infrastructure.

test: seed the permission fixtures the enterprise policy needs (#21745)

Zhichang Yua41d70218bf7
diff --git a/internal/handler/agent_component_test.go b/internal/handler/agent_component_test.go
index eefd6dc4fb..c2cbed2282 100644
--- a/internal/handler/agent_component_test.go
+++ b/internal/handler/agent_component_test.go
@@ -31,6 +31,7 @@ import (
agentruntime "ragflow/internal/agent/runtime"
"ragflow/internal/dao"
"ragflow/internal/entity"
+ "ragflow/internal/permission"
)
// componentCtx builds a Gin context for one of the
@@ -46,6 +47,10 @@ func componentCtx(t *testing.T, method, path, body string) (*gin.Context, *httpt
c.Request.Header.Set("Content-Type", "application/json")
}
c.Set("user", &entity.User{ID: "u-1"})
+ // The auth middleware attaches the permission subject in production; the
+ // enterprise policy needs the tenant from it, so mirror that here.
+ c.Request = c.Request.WithContext(permission.WithSubject(
+ c.Request.Context(), permission.Subject{UserID: "u-1", TenantID: "u-1"}))
return c, w
}
diff --git a/internal/handler/agent_model_inputs_test.go b/internal/handler/agent_model_inputs_test.go
index 8374611338..7989041a40 100644
--- a/internal/handler/agent_model_inputs_test.go
+++ b/internal/handler/agent_model_inputs_test.go
@@ -17,6 +17,7 @@ import (
"ragflow/internal/dao"
"ragflow/internal/entity"
"ragflow/internal/entity/models"
+ "ragflow/internal/permission/testsupport"
)
type modelInputDebugEnvelope struct {
@@ -33,6 +34,9 @@ func setupModelInputDebug(t *testing.T, endpoint string) (*AgentHandler, *entity
previous := dao.DB
dao.DB = db
t.Cleanup(func() { dao.DB = previous })
+ if err := testsupport.PrepareEnterprisePermissionFixture(db, "u-1", "u-1"); err != nil {
+ t.Fatalf("prepare agent model input permission fixture: %v", err)
+ }
previousHostSetting := common.AllowAnyHostForTest
common.AllowAnyHostForTest = true
t.Cleanup(func() { common.AllowAnyHostForTest = previousHostSetting })
diff --git a/internal/service/document/document_preview_seed_stub_test.go b/internal/service/document/document_preview_seed_stub_test.go
new file mode 100644
index 0000000000..246ff837c5
--- /dev/null
+++ b/internal/service/document/document_preview_seed_stub_test.go
@@ -0,0 +1,30 @@
+//
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//go:build !ee
+
+package document
+
+import (
+ "testing"
+
+ "gorm.io/gorm"
+)
+
+// seedDocumentPreviewMemberAccessEE does nothing: the community edition lets
+// tenant members read a tenant dataset without a grant row or feature role.
+func seedDocumentPreviewMemberAccessEE(_ *testing.T, _ *gorm.DB) {
+}
diff --git a/internal/service/document/document_test.go b/internal/service/document/document_test.go
index 3d361f6b04..1db5fd3ca1 100644
--- a/internal/service/document/document_test.go
+++ b/internal/service/document/document_test.go
@@ -582,6 +582,9 @@ func seedDocumentPreviewMemberAccess(t *testing.T, db *gorm.DB) {
}).Error; err != nil {
t.Fatalf("insert Tenant member: %v", err)
}
+ // The enterprise policy resolves shared datasets through an explicit grant
+ // plus a feature role; the community edition needs neither (no-op stub).
+ seedDocumentPreviewMemberAccessEE(t, db)
}
func testDocumentService(t *testing.T) *DocumentService {
diff --git a/internal/service/test_helpers_stub_test.go b/internal/service/test_helpers_stub_test.go
new file mode 100644
index 0000000000..573fd87a72
--- /dev/null
+++ b/internal/service/test_helpers_stub_test.go
@@ -0,0 +1,27 @@
+//
+// Copyright 2026 The InfiniFlow Authors. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+//go:build !ee
+
+package service
+
+import "testing"
+
+// grantServiceTestResource grants nothing: the community edition has no
+// per-resource permission table to seed. It lives here, behind !ee, because
+// the enterprise repository defines the same helper for its build.
+func grantServiceTestResource(_ *testing.T, _ string, _ string, _ string, _ string, _ int32) {
+}
diff --git a/internal/service/test_helpers_test.go b/internal/service/test_helpers_test.go
index 369ec6f1f1..600bc07e7f 100644
--- a/internal/service/test_helpers_test.go
+++ b/internal/service/test_helpers_test.go
@@ -275,11 +275,6 @@ func insertTestIngestionTask(t *testing.T, id, userID, docID, datasetID string)
insertTestIngestionTaskWithStatus(t, id, userID, docID, datasetID, common.CREATED)
}
-// grantServiceTestResource grants nothing: the community edition has no
-// per-resource permission table to seed.
-func grantServiceTestResource(_ *testing.T, _ string, _ string, _ string, _ string, _ int32) {
-}
-
// permissionChangeLogTestModels adds no tables: the community edition has no
// permission audit log.
func permissionChangeLogTestModels() []interface{} { return nil }