sys_user_security_test.go 906 B

12345678910111213141516171819202122232425262728293031
  1. package system
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/require"
  5. )
  6. func TestCanRegisterAuthorityRoleHierarchy(t *testing.T) {
  7. cases := []struct {
  8. name string
  9. caller uint
  10. target uint
  11. expected bool
  12. }{
  13. {"超级管理员可创建全部", 9527, 888, true},
  14. {"超级管理员可创建管理员", 9527, 9527, true},
  15. {"管理员可创建操作员", 888, 618, true},
  16. {"管理员可创建同级", 888, 888, true},
  17. {"管理员不可创建超级管理员", 888, 9527, false},
  18. {"操作员只能创建操作员", 618, 618, true},
  19. {"操作员不可创建管理员", 618, 888, false}, // 提权通道必须封堵
  20. {"操作员不可创建超级管理员", 618, 9527, false},
  21. {"未知角色一律拒绝", 0, 618, false},
  22. }
  23. for _, tc := range cases {
  24. t.Run(tc.name, func(t *testing.T) {
  25. require.Equal(t, tc.expected, canRegisterAuthority(tc.caller, tc.target))
  26. })
  27. }
  28. }