(t *testing.T)
| 572 | } |
| 573 | |
| 574 | func TestGetAllowedObjectConditions(t *testing.T) { |
| 575 | e, _ := NewEnforcer("examples/object_conditions_model.conf", "examples/object_conditions_policy.csv") |
| 576 | testGetAllowedObjectConditions(t, e, "alice", "read", "r.obj.", []string{"price < 25", "category_id = 2"}, nil) |
| 577 | testGetAllowedObjectConditions(t, e, "admin", "read", "r.obj.", []string{"category_id = 2"}, nil) |
| 578 | testGetAllowedObjectConditions(t, e, "bob", "write", "r.obj.", []string{"author = bob"}, nil) |
| 579 | |
| 580 | // test ErrEmptyCondition |
| 581 | testGetAllowedObjectConditions(t, e, "alice", "write", "r.obj.", []string{}, errors.ErrEmptyCondition) |
| 582 | testGetAllowedObjectConditions(t, e, "bob", "read", "r.obj.", []string{}, errors.ErrEmptyCondition) |
| 583 | |
| 584 | // test ErrObjCondition |
| 585 | // should : e.AddPolicy("alice", "r.obj.price > 50", "read") |
| 586 | ok, _ := e.AddPolicy("alice", "price > 50", "read") |
| 587 | if ok { |
| 588 | testGetAllowedObjectConditions(t, e, "alice", "read", "r.obj.", []string{}, errors.ErrObjCondition) |
| 589 | } |
| 590 | |
| 591 | // test prefix |
| 592 | e.ClearPolicy() |
| 593 | err := e.GetRoleManager().DeleteLink("alice", "admin") |
| 594 | if err != nil { |
| 595 | panic(err) |
| 596 | } |
| 597 | ok, _ = e.AddPolicies([][]string{ |
| 598 | {"alice", "r.book.price < 25", "read"}, |
| 599 | {"admin", "r.book.category_id = 2", "read"}, |
| 600 | {"bob", "r.book.author = bob", "write"}, |
| 601 | }) |
| 602 | if ok { |
| 603 | testGetAllowedObjectConditions(t, e, "alice", "read", "r.book.", []string{"price < 25"}, nil) |
| 604 | testGetAllowedObjectConditions(t, e, "admin", "read", "r.book.", []string{"category_id = 2"}, nil) |
| 605 | testGetAllowedObjectConditions(t, e, "bob", "write", "r.book.", []string{"author = bob"}, nil) |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | func testGetImplicitUsersForResource(t *testing.T, e *Enforcer, res [][]string, resource string, domain ...string) { |
| 610 | t.Helper() |
nothing calls this directly
no test coverage detected