MCPcopy
hub / github.com/apache/casbin / TestRoleAPI_Domains

Function TestRoleAPI_Domains

rbac_api_test.go:132–176  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

130}
131
132func TestRoleAPI_Domains(t *testing.T) {
133 e, _ := NewEnforcer("examples/rbac_with_domains_model.conf", "examples/rbac_with_domains_policy.csv")
134
135 testHasRole(t, e, "alice", "admin", true, "domain1")
136 testHasRole(t, e, "alice", "admin", false, "domain2")
137 testGetRoles(t, e, []string{"admin"}, "alice", "domain1")
138 testGetRoles(t, e, []string{}, "bob", "domain1")
139 testGetRoles(t, e, []string{}, "admin", "domain1")
140 testGetRoles(t, e, []string{}, "non_exist", "domain1")
141 testGetRoles(t, e, []string{}, "alice", "domain2")
142 testGetRoles(t, e, []string{"admin"}, "bob", "domain2")
143 testGetRoles(t, e, []string{}, "admin", "domain2")
144 testGetRoles(t, e, []string{}, "non_exist", "domain2")
145
146 _, _ = e.DeleteRoleForUser("alice", "admin", "domain1")
147 _, _ = e.AddRoleForUser("bob", "admin", "domain1")
148
149 testGetRoles(t, e, []string{}, "alice", "domain1")
150 testGetRoles(t, e, []string{"admin"}, "bob", "domain1")
151 testGetRoles(t, e, []string{}, "admin", "domain1")
152 testGetRoles(t, e, []string{}, "non_exist", "domain1")
153 testGetRoles(t, e, []string{}, "alice", "domain2")
154 testGetRoles(t, e, []string{"admin"}, "bob", "domain2")
155 testGetRoles(t, e, []string{}, "admin", "domain2")
156 testGetRoles(t, e, []string{}, "non_exist", "domain2")
157
158 _, _ = e.AddRoleForUser("alice", "admin", "domain1")
159 _, _ = e.DeleteRolesForUser("bob", "domain1")
160
161 testGetRoles(t, e, []string{"admin"}, "alice", "domain1")
162 testGetRoles(t, e, []string{}, "bob", "domain1")
163 testGetRoles(t, e, []string{}, "admin", "domain1")
164 testGetRoles(t, e, []string{}, "non_exist", "domain1")
165 testGetRoles(t, e, []string{}, "alice", "domain2")
166 testGetRoles(t, e, []string{"admin"}, "bob", "domain2")
167 testGetRoles(t, e, []string{}, "admin", "domain2")
168 testGetRoles(t, e, []string{}, "non_exist", "domain2")
169
170 _, _ = e.AddRolesForUser("bob", []string{"admin", "admin1", "admin2"}, "domain1")
171
172 testGetRoles(t, e, []string{"admin", "admin1", "admin2"}, "bob", "domain1")
173
174 testGetPermissions(t, e, "admin", [][]string{{"admin", "domain1", "data1", "read"}, {"admin", "domain1", "data1", "write"}}, "domain1")
175 testGetPermissions(t, e, "admin", [][]string{{"admin", "domain2", "data2", "read"}, {"admin", "domain2", "data2", "write"}}, "domain2")
176}
177
178func TestEnforcer_AddRolesForUser(t *testing.T) {
179 e, _ := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv")

Callers

nothing calls this directly

Calls 8

DeleteRoleForUserMethod · 0.95
AddRoleForUserMethod · 0.95
DeleteRolesForUserMethod · 0.95
AddRolesForUserMethod · 0.95
NewEnforcerFunction · 0.85
testHasRoleFunction · 0.85
testGetRolesFunction · 0.85
testGetPermissionsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…