(t *testing.T)
| 342 | } |
| 343 | |
| 344 | func TestRBACModelWithCustomData(t *testing.T) { |
| 345 | e, _ := NewEnforcer("examples/rbac_model.conf", "examples/rbac_policy.csv") |
| 346 | |
| 347 | // You can add custom data to a grouping policy, Casbin will ignore it. It is only meaningful to the caller. |
| 348 | // This feature can be used to store information like whether "bob" is an end user (so no subject will inherit "bob") |
| 349 | // For Casbin, it is equivalent to: e.AddGroupingPolicy("bob", "data2_admin") |
| 350 | _, _ = e.AddGroupingPolicy("bob", "data2_admin", "custom_data") |
| 351 | |
| 352 | testEnforce(t, e, "alice", "data1", "read", true) |
| 353 | testEnforce(t, e, "alice", "data1", "write", false) |
| 354 | testEnforce(t, e, "alice", "data2", "read", true) |
| 355 | testEnforce(t, e, "alice", "data2", "write", true) |
| 356 | testEnforce(t, e, "bob", "data1", "read", false) |
| 357 | testEnforce(t, e, "bob", "data1", "write", false) |
| 358 | testEnforce(t, e, "bob", "data2", "read", true) |
| 359 | testEnforce(t, e, "bob", "data2", "write", true) |
| 360 | |
| 361 | // You should also take the custom data as a parameter when deleting a grouping policy. |
| 362 | // e.RemoveGroupingPolicy("bob", "data2_admin") won't work. |
| 363 | // Or you can remove it by using RemoveFilteredGroupingPolicy(). |
| 364 | _, _ = e.RemoveGroupingPolicy("bob", "data2_admin", "custom_data") |
| 365 | |
| 366 | testEnforce(t, e, "alice", "data1", "read", true) |
| 367 | testEnforce(t, e, "alice", "data1", "write", false) |
| 368 | testEnforce(t, e, "alice", "data2", "read", true) |
| 369 | testEnforce(t, e, "alice", "data2", "write", true) |
| 370 | testEnforce(t, e, "bob", "data1", "read", false) |
| 371 | testEnforce(t, e, "bob", "data1", "write", false) |
| 372 | testEnforce(t, e, "bob", "data2", "read", false) |
| 373 | testEnforce(t, e, "bob", "data2", "write", true) |
| 374 | } |
| 375 | |
| 376 | func TestRBACModelWithPattern(t *testing.T) { |
| 377 | e, _ := NewEnforcer("examples/rbac_with_pattern_model.conf", "examples/rbac_with_pattern_policy.csv") |
nothing calls this directly
no test coverage detected
searching dependent graphs…