|
|
@@ -81,7 +81,6 @@ func TestCreateUser_Success(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
resp, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Nickname: "测试用户",
|
|
|
Email: username + "@test.com",
|
|
|
Phone: "13800138000",
|
|
|
@@ -116,7 +115,6 @@ func TestCreateUser_UsernameExists(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass456789",
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
|
|
|
@@ -134,7 +132,6 @@ func TestCreateUser_InvalidEmail(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
Email: "not-an-email",
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -155,7 +152,6 @@ func TestCreateUser_ValidEmail(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
resp, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Email: username + "@example.com",
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -178,7 +174,6 @@ func TestCreateUser_EmptyEmailSkipsValidation(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
resp, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Email: "",
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -199,7 +194,6 @@ func TestCreateUser_InvalidPhone(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
Phone: "abc",
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -220,7 +214,6 @@ func TestCreateUser_ValidPhone(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
resp, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Phone: "13900139000",
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -243,7 +236,6 @@ func TestCreateUser_EmptyPhoneSkipsValidation(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
resp, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Phone: "",
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -276,7 +268,6 @@ func TestCreateUser_ConcurrentSameUsername(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Nickname: "并发测试用户",
|
|
|
})
|
|
|
results <- err
|
|
|
@@ -318,7 +309,6 @@ func TestCreateUser_ValidInternationalPhone(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
resp, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Phone: "+8613800138000",
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -331,105 +321,12 @@ func TestCreateUser_ValidInternationalPhone(t *testing.T) {
|
|
|
assert.Equal(t, "+8613800138000", user.Phone)
|
|
|
}
|
|
|
|
|
|
-// TC-0145: 密码少于8字符
|
|
|
-func TestCreateUser_PasswordTooShort(t *testing.T) {
|
|
|
- ctx := ctxhelper.SuperAdminCtx()
|
|
|
- svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
-
|
|
|
- logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
- _, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
- Username: testutil.UniqueId(),
|
|
|
- Password: "Pas1234",
|
|
|
- })
|
|
|
- require.Error(t, err)
|
|
|
-
|
|
|
- var codeErr *response.CodeError
|
|
|
- require.True(t, errors.As(err, &codeErr))
|
|
|
- assert.Equal(t, 400, codeErr.Code())
|
|
|
- assert.Equal(t, "密码长度不能少于8个字符", codeErr.Error())
|
|
|
-}
|
|
|
-
|
|
|
-// TC-0146: 密码缺少大写字母
|
|
|
-func TestCreateUser_PasswordNoUppercase(t *testing.T) {
|
|
|
- ctx := ctxhelper.SuperAdminCtx()
|
|
|
- svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
-
|
|
|
- logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
-
|
|
|
- longPwd := "A" + strings.Repeat("a", 71) + "1"
|
|
|
- _, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
- Username: testutil.UniqueId(),
|
|
|
- Password: longPwd,
|
|
|
- })
|
|
|
- require.Error(t, err)
|
|
|
-
|
|
|
- var codeErr *response.CodeError
|
|
|
- require.True(t, errors.As(err, &codeErr))
|
|
|
- assert.Equal(t, 400, codeErr.Code())
|
|
|
- assert.Equal(t, "密码长度不能超过72个字符", codeErr.Error())
|
|
|
-}
|
|
|
-
|
|
|
-// TC-0147: 密码缺少小写字母
|
|
|
-func TestCreateUser_PasswordNoLowercase(t *testing.T) {
|
|
|
- ctx := ctxhelper.SuperAdminCtx()
|
|
|
- svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
-
|
|
|
- logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
- _, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
- Username: testutil.UniqueId(),
|
|
|
- Password: "PASS123456",
|
|
|
- })
|
|
|
- require.Error(t, err)
|
|
|
-
|
|
|
- var codeErr *response.CodeError
|
|
|
- require.True(t, errors.As(err, &codeErr))
|
|
|
- assert.Equal(t, 400, codeErr.Code())
|
|
|
- assert.Equal(t, "密码必须包含大写字母、小写字母和数字", codeErr.Error())
|
|
|
-}
|
|
|
-
|
|
|
-// TC-0148: 密码缺少数字
|
|
|
-func TestCreateUser_PasswordNoDigit(t *testing.T) {
|
|
|
- ctx := ctxhelper.SuperAdminCtx()
|
|
|
- svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
-
|
|
|
- logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
- _, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
- Username: testutil.UniqueId(),
|
|
|
- Password: "Passpasspass",
|
|
|
- })
|
|
|
- require.Error(t, err)
|
|
|
-
|
|
|
- var codeErr *response.CodeError
|
|
|
- require.True(t, errors.As(err, &codeErr))
|
|
|
- assert.Equal(t, 400, codeErr.Code())
|
|
|
- assert.Equal(t, "密码必须包含大写字母、小写字母和数字", codeErr.Error())
|
|
|
-}
|
|
|
-
|
|
|
-// TC-0149: 密码超过72字符
|
|
|
-func TestCreateUser_PasswordTooLong(t *testing.T) {
|
|
|
- ctx := ctxhelper.SuperAdminCtx()
|
|
|
- svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
-
|
|
|
- longPwd := strings.Repeat("a", 73)
|
|
|
- logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
- _, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
- Username: testutil.UniqueId(),
|
|
|
- Password: longPwd,
|
|
|
- })
|
|
|
- require.Error(t, err)
|
|
|
-
|
|
|
- var codeErr *response.CodeError
|
|
|
- require.True(t, errors.As(err, &codeErr))
|
|
|
- assert.Equal(t, 400, codeErr.Code())
|
|
|
- assert.Equal(t, "密码长度不能超过72个字符", codeErr.Error())
|
|
|
-}
|
|
|
-
|
|
|
// TC-0537: createUser非管理员拒绝
|
|
|
func TestCreateUser_MemberRejected(t *testing.T) {
|
|
|
ctx := ctxhelper.MemberCtx("test_product")
|
|
|
svcCtx := svc.NewServiceContext(testutil.GetTestConfig())
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
- _, err := logic.CreateUser(&types.CreateUserReq{Username: "test", Password: "Pass123456"})
|
|
|
+ _, err := logic.CreateUser(&types.CreateUserReq{Username: "test"})
|
|
|
require.Error(t, err)
|
|
|
var ce *response.CodeError
|
|
|
require.True(t, errors.As(err, &ce))
|
|
|
@@ -444,7 +341,6 @@ func TestCreateUser_UsernameInvalidChars(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: "user@name!",
|
|
|
- Password: "Pass123456",
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
|
|
|
@@ -462,7 +358,6 @@ func TestCreateUser_UsernameTooShort(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: "a",
|
|
|
- Password: "Pass123456",
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
|
|
|
@@ -480,7 +375,6 @@ func TestCreateUser_UsernameTooLong(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: strings.Repeat("a", 65),
|
|
|
- Password: "Pass123456",
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
|
|
|
@@ -498,7 +392,6 @@ func TestCreateUser_DeptNotExists(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: 999999999,
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -520,7 +413,6 @@ func TestCreateUser_NicknameTooLong(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
Nickname: strings.Repeat("n", 65),
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -539,7 +431,6 @@ func TestCreateUser_RemarkTooLong(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
_, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
Remark: strings.Repeat("r", 256),
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -577,7 +468,6 @@ func TestCreateUser_AllOptionalFields(t *testing.T) {
|
|
|
logic := NewCreateUserLogic(ctx, svcCtx)
|
|
|
resp, err := logic.CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
Nickname: "全字段用户",
|
|
|
Email: username + "@example.com",
|
|
|
Phone: "13900001111",
|
|
|
@@ -631,7 +521,6 @@ func TestCreateUser_MN4_AdminCannotCreateOutsideDeptSubtree(t *testing.T) {
|
|
|
adminCtx := callerAdminCtx(777771, callerDeptId, "/100/")
|
|
|
_, err := NewCreateUserLogic(adminCtx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "mn4_seed_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: outsideDeptId,
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -659,7 +548,6 @@ func TestCreateUser_MN4_AdminCanCreateInsideDeptSubtree(t *testing.T) {
|
|
|
username := "mn4ok_" + testutil.UniqueId()
|
|
|
resp, err := NewCreateUserLogic(adminCtx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: childDeptId,
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -687,7 +575,6 @@ func TestCreateUser_MN4_SuperAdminCanCreateAnywhere(t *testing.T) {
|
|
|
usernameDept := "mn4sa_dept_" + testutil.UniqueId()
|
|
|
resp, err := NewCreateUserLogic(ctxhelper.SuperAdminCtx(), svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: usernameDept,
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: randomDeptId,
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -698,7 +585,6 @@ func TestCreateUser_MN4_SuperAdminCanCreateAnywhere(t *testing.T) {
|
|
|
usernameZero := "mn4sa_zero_" + testutil.UniqueId()
|
|
|
respZero, err := NewCreateUserLogic(ctxhelper.SuperAdminCtx(), svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: usernameZero,
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: 0,
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -721,7 +607,6 @@ func TestCreateUser_MN4_EmptyCallerDeptPathRejected(t *testing.T) {
|
|
|
adminCtx := callerAdminCtx(777773, 0, "")
|
|
|
_, err := NewCreateUserLogic(adminCtx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "mn4empty_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: dstDeptId,
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -746,7 +631,6 @@ func TestCreateUser_MN4_NonSuperAdminMustSpecifyDept(t *testing.T) {
|
|
|
adminCtx := callerAdminCtx(777774, callerDeptId, "/300/")
|
|
|
_, err := NewCreateUserLogic(adminCtx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "mn4must_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: 0,
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -777,7 +661,6 @@ func TestCreateUser_LN2_TargetDeptDisabled(t *testing.T) {
|
|
|
// 超管也必须被拒绝: 的规则针对"所有调用方",防止 disabled 部门被意外重新填人
|
|
|
_, err = NewCreateUserLogic(ctxhelper.SuperAdminCtx(), svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "ln2_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: disabledId,
|
|
|
})
|
|
|
require.Error(t, err)
|
|
|
@@ -808,7 +691,6 @@ func TestCreateUser_NegativeDeptIdRejected(t *testing.T) {
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
_, err := NewCreateUserLogic(tc.ctx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "neg_dept_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: tc.deptId,
|
|
|
})
|
|
|
require.Error(t, err, "负值 DeptId 必须被拒绝")
|
|
|
@@ -830,7 +712,6 @@ func TestCreateUser_DefaultsMustChangePasswordToYes(t *testing.T) {
|
|
|
username := "lcp_" + testutil.UniqueId()
|
|
|
resp, err := NewCreateUserLogic(ctx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "InitPass@123",
|
|
|
Nickname: "初始口令校验",
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -865,7 +746,6 @@ func TestCreateUser_H_R14_1_AdminCannotCreateInDevDept(t *testing.T) {
|
|
|
adminCtx := callerAdminCtx(888881, adminDeptId, "/9100/")
|
|
|
_, err := NewCreateUserLogic(adminCtx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "h_r14_1_c_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: devDeptId,
|
|
|
})
|
|
|
require.Error(t, err, "ADMIN 在 DEV 部门创建用户必须被拒绝")
|
|
|
@@ -898,7 +778,6 @@ func TestCreateUser_H_R14_1_SuperAdminCanCreateInDevDept(t *testing.T) {
|
|
|
username := "h_r14_1_c_su_" + testutil.UniqueId()
|
|
|
resp, err := NewCreateUserLogic(superCtx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: devDeptId,
|
|
|
})
|
|
|
require.NoError(t, err, "SuperAdmin 在 DEV 部门创建用户必须允许")
|
|
|
@@ -949,7 +828,6 @@ func TestCreateUser_L_R17_1_ReservedUsernamePrefix_NonSuperAdmin(t *testing.T) {
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
_, err := NewCreateUserLogic(adminCtx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: tc.username,
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: callerDeptId,
|
|
|
})
|
|
|
require.Error(t, err, "非超管以保留前缀创建用户必须被拒绝")
|
|
|
@@ -978,7 +856,6 @@ func TestCreateUser_L_R17_1_ReservedUsernamePrefix_SuperAdminAllowed(t *testing.
|
|
|
username := "svc_" + testutil.UniqueId()
|
|
|
resp, err := NewCreateUserLogic(ctx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: 0,
|
|
|
})
|
|
|
require.NoError(t, err, "SuperAdmin 不受保留前缀约束")
|
|
|
@@ -1004,7 +881,6 @@ func TestCreateUser_L_R17_2_AvatarExplicitNull(t *testing.T) {
|
|
|
username := "l_r17_2_" + testutil.UniqueId()
|
|
|
resp, err := NewCreateUserLogic(ctx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: username,
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: 0,
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -1095,7 +971,6 @@ func TestCreateUser_H_R17_1_InsertRunsInsideTxWithSharedDeptLock(t *testing.T) {
|
|
|
|
|
|
resp, err := NewCreateUserLogic(ctx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "h_r17_1_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: targetDeptId,
|
|
|
})
|
|
|
require.NoError(t, err)
|
|
|
@@ -1148,7 +1023,6 @@ func TestCreateUser_H_R17_1_DeptConcurrentlyDeletedRejected(t *testing.T) {
|
|
|
|
|
|
_, err := NewCreateUserLogic(ctx, svcCtx).CreateUser(&types.CreateUserReq{
|
|
|
Username: "h_r17_1_del_" + testutil.UniqueId(),
|
|
|
- Password: "Pass123456",
|
|
|
DeptId: targetDeptId,
|
|
|
})
|
|
|
require.Error(t, err)
|