From 56d87ec18a74a69ab8a7eaaacfeb1340b70f3de7 Mon Sep 17 00:00:00 2001 From: veypi Date: Wed, 25 Feb 2026 18:13:20 +0800 Subject: [PATCH] test: Update tests for scoped RBAC and remove org tests - Remove org-related test cases from edge_case_test.go - Remove OrgResp type from main_test.go - Update none_auth_test removing org endpoints - Add permission grants in OAuth tests for proper access control - Fix race condition tests with retry logic for SQLite locking - Update resource_perm_test to accept 401 or 403 status codes - Add new role_access_test.go for role API permission testing - Add new scoped_auth_test.go for scoped permission testing --- tests/edge_case_test.go | 41 ++------- tests/main_test.go | 6 -- tests/none_auth_test.go | 2 - tests/oauth_client_test.go | 29 ++++-- tests/oauth_security_test.go | 8 ++ tests/race_condition_test.go | 170 ++++++++++++----------------------- tests/resource_perm_test.go | 12 +-- tests/role_access_test.go | 54 +++++++++++ tests/role_test.go | 6 ++ tests/scoped_auth_test.go | 151 +++++++++++++++++++++++++++++++ 10 files changed, 307 insertions(+), 172 deletions(-) create mode 100644 tests/role_access_test.go create mode 100644 tests/scoped_auth_test.go diff --git a/tests/edge_case_test.go b/tests/edge_case_test.go index 951b93e..621dd07 100644 --- a/tests/edge_case_test.go +++ b/tests/edge_case_test.go @@ -23,18 +23,6 @@ func TestSQLInjection(t *testing.T) { }) // 测试组织代码中的 SQL 注入 - t.Run("SQL Injection in org code", func(t *testing.T) { - resp := doRequest(t, "POST", "/api/orgs", map[string]string{ - "code": "test' OR '1'='1", - "name": "SQL Test Org", - }, User1Token) - // 应该正常处理或返回业务错误,而不是 SQL 错误 - if resp.Code == 500 { - t.Errorf("SQL injection in org code caused server error: %s", resp.Body.String()) - } - }) - - // 测试搜索中的 SQL 注入 t.Run("SQL Injection in search", func(t *testing.T) { resp := doRequest(t, "GET", "/api/auth/users?keyword=admin' OR '1'='1", nil, AdminToken) // 应该正常处理 @@ -63,20 +51,6 @@ func TestXSSPrevention(t *testing.T) { } } }) - - // 测试组织名称中的 XSS - t.Run("XSS in org name", func(t *testing.T) { - resp := doRequest(t, "POST", "/api/orgs", map[string]string{ - "code": "xss_test_org", - "name": xssPayload, - }, User1Token) - - if resp.Code == 200 { - if strings.Contains(resp.Body.String(), "