package system import ( "testing" "github.com/stretchr/testify/require" ) func TestCanRegisterAuthorityRoleHierarchy(t *testing.T) { cases := []struct { name string caller uint target uint expected bool }{ {"超级管理员可创建全部", 9527, 888, true}, {"超级管理员可创建管理员", 9527, 9527, true}, {"管理员可创建操作员", 888, 618, true}, {"管理员可创建同级", 888, 888, true}, {"管理员不可创建超级管理员", 888, 9527, false}, {"操作员只能创建操作员", 618, 618, true}, {"操作员不可创建管理员", 618, 888, false}, // 提权通道必须封堵 {"操作员不可创建超级管理员", 618, 9527, false}, {"未知角色一律拒绝", 0, 618, false}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { require.Equal(t, tc.expected, canRegisterAuthority(tc.caller, tc.target)) }) } }