-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We must use a union because when we retrieve roles with a query, we check against: 1) role name 2) email of associated user for private roles We factor out this select into a helper method, which we then test extensively.
- Loading branch information
Showing
2 changed files
with
141 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
get_private_user_role, | ||
get_roles_by_ids, | ||
) | ||
from galaxy.model.security import _get_valid_roles_case1 | ||
from . import have_same_elements | ||
|
||
|
||
|
@@ -42,3 +43,99 @@ def test_get_roles_by_ids(session, make_role): | |
roles2 = get_roles_by_ids(session, ids) | ||
expected = [r1, r2, r3] | ||
have_same_elements(roles2, expected) | ||
|
||
|
||
def test_get_falid_roles_case1(session, make_user_and_role, make_user, make_role, make_user_role_association): | ||
# Make 3 users with private roles | ||
( | ||
u1, | ||
rp1, | ||
) = make_user_and_role(email="[email protected]") | ||
( | ||
u2, | ||
rp2, | ||
) = make_user_and_role(email="[email protected]") | ||
( | ||
u3, | ||
rp3, | ||
) = make_user_and_role(email="[email protected]") | ||
|
||
# Make 2 sharing roles | ||
rs1 = make_role(type="sharing", name="sharing role for u1") | ||
make_user_role_association(user=u1, role=rs1) | ||
rs2 = make_role(type="sharing", name="sharing role for u2") | ||
make_user_role_association(user=u2, role=rs2) | ||
|
||
# Make 4 admin roles | ||
ra1 = make_role(type="admin", name="admin role1") | ||
make_user_role_association(user=u1, role=ra1) | ||
make_user_role_association(user=u2, role=ra1) | ||
ra2 = make_role(type="admin", name="admin role2") | ||
make_user_role_association(user=u1, role=ra2) | ||
make_user_role_association(user=u2, role=ra2) | ||
|
||
limit, page, page_limit = 1000, 1, 1000 | ||
|
||
is_admin = True | ||
|
||
search_query = None | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 7 # all roles returned | ||
|
||
search_query = "foo%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 2 | ||
assert rp1 in roles | ||
assert rp2 in roles | ||
|
||
search_query = "foo1%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 1 | ||
assert roles[0] == rp1 | ||
|
||
search_query = "sharing%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 2 | ||
assert rs1 in roles | ||
assert rs2 in roles | ||
|
||
search_query = "sharing role for u1%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 1 | ||
assert roles[0] == rs1 | ||
|
||
search_query = "admin role%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 2 | ||
assert ra1 in roles | ||
assert ra2 in roles | ||
|
||
search_query = "admin role1%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 1 | ||
assert roles[0] == ra1 | ||
|
||
is_admin = False # non admins should see only private roles | ||
|
||
search_query = None | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 3 | ||
|
||
search_query = "foo%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 2 | ||
assert rp1 in roles | ||
assert rp2 in roles | ||
|
||
search_query = "foo1%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 1 | ||
assert roles[0] == rp1 | ||
|
||
search_query = "sharing%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 0 | ||
|
||
search_query = "admin role%" | ||
roles = _get_valid_roles_case1(session, search_query, is_admin, limit, page, page_limit) | ||
assert len(roles) == 0 |