优化结构
This commit is contained in:
@@ -2,9 +2,8 @@ package system
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kra/internal/biz/system"
|
||||
"testing"
|
||||
|
||||
"kra/internal/biz"
|
||||
)
|
||||
|
||||
func seedStrictUserTree(t *testing.T, data *Data) (actorID, childID, siblingID uint, users []userPO) {
|
||||
@@ -35,10 +34,10 @@ func seedStrictUserTree(t *testing.T, data *Data) (actorID, childID, siblingID u
|
||||
func TestStrictUserMutationsRejectOutsideTargetAndAllowSelfPassword(t *testing.T) {
|
||||
data := newTransactionTestData(t)
|
||||
actorID, _, _, users := seedStrictUserTree(t, data)
|
||||
ctx := biz.NewActorContext(context.Background(), biz.Actor{UserID: users[0].ID, AuthorityID: actorID})
|
||||
ctx := system.NewActorContext(context.Background(), system.Actor{UserID: users[0].ID, AuthorityID: actorID})
|
||||
repo := &userRepo{data: data}
|
||||
|
||||
if err := repo.UpdateUser(ctx, &biz.User{ID: users[2].ID, NickName: "changed"}); err == nil {
|
||||
if err := repo.UpdateUser(ctx, &system.User{ID: users[2].ID, NickName: "changed"}); err == nil {
|
||||
t.Fatal("UpdateUser() accepted an out-of-scope target")
|
||||
}
|
||||
if err := repo.DeleteUser(ctx, users[2].ID); err == nil {
|
||||
@@ -55,13 +54,13 @@ func TestStrictUserMutationsRejectOutsideTargetAndAllowSelfPassword(t *testing.T
|
||||
func TestStrictUserCreationAndRoleAssignmentRequireManagedAuthorities(t *testing.T) {
|
||||
data := newTransactionTestData(t)
|
||||
actorID, childID, siblingID, users := seedStrictUserTree(t, data)
|
||||
ctx := biz.NewActorContext(context.Background(), biz.Actor{UserID: users[0].ID, AuthorityID: actorID})
|
||||
ctx := system.NewActorContext(context.Background(), system.Actor{UserID: users[0].ID, AuthorityID: actorID})
|
||||
repo := &userRepo{data: data}
|
||||
|
||||
if _, err := repo.CreateUserWithAuthorities(ctx, &biz.User{Username: "outside-create", Password: "hash", AuthorityID: siblingID, Enable: 1}, nil); err == nil {
|
||||
if _, err := repo.CreateUserWithAuthorities(ctx, &system.User{Username: "outside-create", Password: "hash", AuthorityID: siblingID, Enable: 1}, nil); err == nil {
|
||||
t.Fatal("CreateUserWithAuthorities() accepted an out-of-scope primary authority")
|
||||
}
|
||||
if _, err := repo.CreateUserWithAuthorities(ctx, &biz.User{Username: "managed-create", Password: "hash", AuthorityID: childID, Enable: 1}, []uint{childID}); err != nil {
|
||||
if _, err := repo.CreateUserWithAuthorities(ctx, &system.User{Username: "managed-create", Password: "hash", AuthorityID: childID, Enable: 1}, []uint{childID}); err != nil {
|
||||
t.Fatalf("CreateUserWithAuthorities() rejected managed authorities: %v", err)
|
||||
}
|
||||
if err := repo.SetUserAuthorities(ctx, users[1].ID, []uint{siblingID}); err == nil {
|
||||
@@ -75,13 +74,13 @@ func TestStrictUserCreationAndRoleAssignmentRequireManagedAuthorities(t *testing
|
||||
func TestStrictUserUpdateRejectsPrimaryAuthorityOutsideManagedTree(t *testing.T) {
|
||||
data := newTransactionTestData(t)
|
||||
actorID, childID, siblingID, users := seedStrictUserTree(t, data)
|
||||
ctx := biz.NewActorContext(context.Background(), biz.Actor{UserID: users[0].ID, AuthorityID: actorID})
|
||||
ctx := system.NewActorContext(context.Background(), system.Actor{UserID: users[0].ID, AuthorityID: actorID})
|
||||
repo := &userRepo{data: data}
|
||||
|
||||
if err := repo.UpdateUser(ctx, &biz.User{ID: users[1].ID, NickName: "changed", AuthorityID: siblingID}); err == nil {
|
||||
if err := repo.UpdateUser(ctx, &system.User{ID: users[1].ID, NickName: "changed", AuthorityID: siblingID}); err == nil {
|
||||
t.Fatal("UpdateUser() accepted a primary authority outside the managed tree")
|
||||
}
|
||||
if err := repo.UpdateUserWithAuthorities(ctx, &biz.User{ID: users[1].ID, NickName: "changed", AuthorityID: siblingID}, []uint{childID}); err == nil {
|
||||
if err := repo.UpdateUserWithAuthorities(ctx, &system.User{ID: users[1].ID, NickName: "changed", AuthorityID: siblingID}, []uint{childID}); err == nil {
|
||||
t.Fatal("UpdateUserWithAuthorities() accepted a primary authority outside the managed tree")
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user