1 package utils
2
3 import (
4 "testing"
5
6 "github.com/stretchr/testify/assert"
7 )
8
9 func TestFilterEdgeRoles(t *testing.T) {
10 testCases := []struct {
11 name string
12 testcase []string
13 expected []string
14 }{
15 {
16 name: "Test Case 1 - empty",
17 testcase: []string{""},
18 expected: []string{},
19 },
20 {
21 name: "Test Case 2 - non matching string",
22 testcase: []string{"hello"},
23 expected: []string{},
24 },
25 {
26 name: "Test Case 3 - mixture of BSL and Edge roles",
27 testcase: []string{
28 "NEP_IDENTITY_VIEWER",
29 "CORE_INVITE_CREATE",
30 "IDENTITY_IT_ADMIN",
31 "CORE_INVITE_VIEWER",
32 "NEP_ENTERPRISE_VIEWER",
33 "NEP_ENTERPRISE_GRANT_REVOKE_ENTERPRISE_UNIT",
34 "NEP_ENTERPRISE_SUPER_ADMINISTRATOR",
35 "NEP_IDENTITY_GROUP_REMOVE_MEMBERS",
36 "NEP_ENTERPRISE_GRANT_ENTERPRISE_UNIT_GROUP",
37 "NEP_ENTERPRISE_GRANT_REVOKE_ENTERPRISE_UNIT_GROUP",
38 "NEP_IDENTITY_GROUP_ADD_MEMBERS",
39 "CORE_INVITE_DELETE",
40 "NEP_ENTERPRISE_SUPER_VIEWER",
41 "CORE_INVITE_ADMIN",
42 "NEP_ENTERPRISE_GRANT_ENTERPRISE_UNIT",
43 "NEP_ENTERPRISE_GROUP_REMOVE_ENTERPRISE_UNITS",
44 "IDENTITY_SITE_ADMIN",
45 "NEP_ENTERPRISE_GROUP_VIEWER",
46 "CORE_INVITE_RESCIND",
47 "NEP_ENTERPRISE_GROUP_ADD_ENTERPRISE_UNITS",
48 "NEP_IDENTITY_UPDATE",
49 "NEP_ENTERPRISE_GRANT_VIEWER",
50 "SITE_READ",
51 "NEP_ORGANIZATION_VIEWER",
52 "EDGE_ORG_ADMIN",
53 },
54 expected: []string{"EDGE_ORG_ADMIN"},
55 },
56 {
57 name: "Test Case 4 - only BSL roles",
58 testcase: []string{
59 "NEP_IDENTITY_VIEWER",
60 "CORE_INVITE_CREATE",
61 "IDENTITY_IT_ADMIN",
62 "CORE_INVITE_VIEWER",
63 "NEP_ENTERPRISE_VIEWER",
64 "NEP_ENTERPRISE_GRANT_REVOKE_ENTERPRISE_UNIT",
65 "NEP_ENTERPRISE_SUPER_ADMINISTRATOR",
66 "NEP_IDENTITY_GROUP_REMOVE_MEMBERS",
67 "NEP_ENTERPRISE_GRANT_ENTERPRISE_UNIT_GROUP",
68 "NEP_ENTERPRISE_GRANT_REVOKE_ENTERPRISE_UNIT_GROUP",
69 "NEP_IDENTITY_GROUP_ADD_MEMBERS",
70 "CORE_INVITE_DELETE",
71 "NEP_ENTERPRISE_SUPER_VIEWER",
72 "CORE_INVITE_ADMIN",
73 "NEP_ENTERPRISE_GRANT_ENTERPRISE_UNIT",
74 "NEP_ENTERPRISE_GROUP_REMOVE_ENTERPRISE_UNITS",
75 "IDENTITY_SITE_ADMIN",
76 "NEP_ENTERPRISE_GROUP_VIEWER",
77 "CORE_INVITE_RESCIND",
78 "NEP_ENTERPRISE_GROUP_ADD_ENTERPRISE_UNITS",
79 "NEP_IDENTITY_UPDATE",
80 "NEP_ENTERPRISE_GRANT_VIEWER",
81 "SITE_READ",
82 "NEP_ORGANIZATION_VIEWER",
83 },
84 expected: []string{},
85 },
86 }
87 for _, tc := range testCases {
88 t.Run(tc.name, func(t *testing.T) {
89 actual := FilterEdgeRoles(tc.testcase)
90 assert.EqualValues(t, tc.expected, actual)
91 })
92 }
93 }
94
View as plain text