功能:增加平台账号管理与管理员保护
This commit is contained in:
@@ -202,3 +202,25 @@ func TestAuthServiceChangePasswordVerifiesCurrentPassword(t *testing.T) {
|
||||
t.Fatal("old password should no longer match")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserServiceCannotDeleteOrDisableLastAdmin(t *testing.T) {
|
||||
db := newServiceTestDB(t)
|
||||
svc := NewUserService(db, nil)
|
||||
admin, err := svc.Create("only-admin", "password123", "唯一管理员", model.RoleAdmin, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("create admin: %v", err)
|
||||
}
|
||||
if err := svc.UpdateStatus(admin.ID, 0); err == nil {
|
||||
t.Fatal("should not disable the last enabled admin")
|
||||
}
|
||||
other, err := svc.Create("other-admin", "password123", "另一管理员", model.RoleAdmin, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("create second admin: %v", err)
|
||||
}
|
||||
if err := svc.Delete(other.ID, admin.ID); err != nil {
|
||||
t.Fatalf("delete non-current admin: %v", err)
|
||||
}
|
||||
if err := svc.Delete(admin.ID, other.ID); err == nil {
|
||||
t.Fatal("should not delete the last enabled admin")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user