|
|
@@ -9,7 +9,6 @@ import (
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
|
|
"perms-system-server/internal/consts"
|
|
|
- "perms-system-server/internal/loaders"
|
|
|
memberModel "perms-system-server/internal/model/productmember"
|
|
|
"perms-system-server/internal/response"
|
|
|
"perms-system-server/internal/svc"
|
|
|
@@ -46,7 +45,7 @@ func insertUserPerm(t *testing.T, svcCtx *svc.ServiceContext, userId, permId int
|
|
|
require.NoError(t, err)
|
|
|
}
|
|
|
|
|
|
-// TC-1257: 超管查任意用户权限覆盖
|
|
|
+// TC-1257: 超管查任意用户权限覆盖(必须传 productCode)
|
|
|
func TestGetUserPerms_SuperAdmin(t *testing.T) {
|
|
|
ctx := ctxhelper.SuperAdminCtx()
|
|
|
svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
@@ -66,7 +65,7 @@ func TestGetUserPerms_SuperAdmin(t *testing.T) {
|
|
|
testutil.CleanTable(ctx, conn, "`sys_perm`", permId)
|
|
|
})
|
|
|
|
|
|
- resp, err := NewGetUserPermsLogic(ctx, svcCtx).GetUserPerms(&types.GetUserPermsReq{UserId: userId})
|
|
|
+ resp, err := NewGetUserPermsLogic(ctx, svcCtx).GetUserPerms(&types.GetUserPermsReq{UserId: userId, ProductCode: "test_product"})
|
|
|
require.NoError(t, err)
|
|
|
require.NotNil(t, resp)
|
|
|
require.Len(t, resp.Perms, 1)
|
|
|
@@ -74,40 +73,17 @@ func TestGetUserPerms_SuperAdmin(t *testing.T) {
|
|
|
assert.Equal(t, consts.PermEffectAllow, resp.Perms[0].Effect)
|
|
|
}
|
|
|
|
|
|
-// TC-1258: 用户查询自己的权限覆盖(包含 ALLOW 和 DENY)
|
|
|
-func TestGetUserPerms_SelfQuery(t *testing.T) {
|
|
|
- bootstrapCtx := ctxhelper.SuperAdminCtx()
|
|
|
+// TC-1304: 超管不传 productCode 时必须返回 400
|
|
|
+func TestGetUserPerms_SuperAdmin_MissingProductCode(t *testing.T) {
|
|
|
+ ctx := ctxhelper.SuperAdminCtx()
|
|
|
svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
- conn := testutil.GetTestSqlConn()
|
|
|
-
|
|
|
- username := testutil.UniqueId()
|
|
|
- userId := insertTestUser(t, bootstrapCtx, username, testutil.HashPassword("pass"))
|
|
|
- mId := insertTestMember(t, svcCtx, "test_product", userId)
|
|
|
- permId1 := insertTestPerm(t, svcCtx, "test_product")
|
|
|
- permId2 := insertTestPerm(t, svcCtx, "test_product")
|
|
|
-
|
|
|
- insertUserPerm(t, svcCtx, userId, permId1, consts.PermEffectAllow)
|
|
|
- insertUserPerm(t, svcCtx, userId, permId2, consts.PermEffectDeny)
|
|
|
-
|
|
|
- t.Cleanup(func() {
|
|
|
- testutil.CleanTableByField(bootstrapCtx, conn, "`sys_user_perm`", "userId", userId)
|
|
|
- testutil.CleanTable(bootstrapCtx, conn, "`sys_product_member`", mId)
|
|
|
- testutil.CleanTable(bootstrapCtx, conn, "`sys_user`", userId)
|
|
|
- testutil.CleanTable(bootstrapCtx, conn, "`sys_perm`", permId1, permId2)
|
|
|
- })
|
|
|
|
|
|
- // caller == target(isSelf 分支,跳过 RequireProductAdminFor + CheckManageAccess)
|
|
|
- selfCtx := ctxhelper.CustomCtx(&loaders.UserDetails{
|
|
|
- UserId: userId,
|
|
|
- Username: username,
|
|
|
- MemberType: consts.MemberTypeMember,
|
|
|
- ProductCode: "test_product",
|
|
|
- Status: consts.StatusEnabled,
|
|
|
- })
|
|
|
- resp, err := NewGetUserPermsLogic(selfCtx, svcCtx).GetUserPerms(&types.GetUserPermsReq{UserId: userId})
|
|
|
- require.NoError(t, err)
|
|
|
- require.NotNil(t, resp)
|
|
|
- assert.Len(t, resp.Perms, 2, "应返回 ALLOW 和 DENY 两条记录")
|
|
|
+ _, err := NewGetUserPermsLogic(ctx, svcCtx).GetUserPerms(&types.GetUserPermsReq{UserId: 1})
|
|
|
+ require.Error(t, err)
|
|
|
+ var ce *response.CodeError
|
|
|
+ require.True(t, errors.As(err, &ce))
|
|
|
+ assert.Equal(t, 400, ce.Code())
|
|
|
+ assert.Contains(t, ce.Error(), "必须指定产品编码")
|
|
|
}
|
|
|
|
|
|
// TC-1259: 产品 ADMIN 查同产品 MEMBER 的权限覆盖
|