forked from nebari-dev/jhub-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Filter users and groups a user can share an app with based on permiss…
…ions (nebari-dev#295) * temp * fix users and groups filtering * remove unused imports * fix undo user name * add entity filtering test * add test for groups * move has_scope import within function * skip test if not jupyterhub 5 * add note for each test * move expanded scoeps out of loop * update assert 'scopes' in self.token_json
- Loading branch information
Showing
2 changed files
with
88 additions
and
7 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
58 changes: 58 additions & 0 deletions
58
jhub_apps/tests/tests_unit/test_filter_users__groups_based_on_scopes.py
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
|
||
from jhub_apps.hub_client.hub_client import filter_entity_based_on_scopes | ||
from jhub_apps.hub_client.utils import is_jupyterhub_5 | ||
|
||
|
||
@pytest.mark.skipif(not is_jupyterhub_5(), reason="requires jupyterhub>=5") | ||
@pytest.mark.parametrize("name,entity_key,scopes,entities,expected_entities", [ | ||
( | ||
"permissions-for-some-users", "user", | ||
[ | ||
"read:users:name!user=user_b", | ||
"read:users:name!user=user_c", | ||
"read:users:name!user=user_d", | ||
"read:users:name!user=user_f", | ||
], | ||
["user_a", "user_c", "user_d", "user_e"], | ||
["user_c", "user_d"] | ||
), | ||
( | ||
"generic-permission-for-all-users", "user", | ||
[ | ||
"read:users:name", | ||
], | ||
["user_c", "user_a", "user_e", "user_d"], | ||
["user_c", "user_a", "user_e", "user_d"] | ||
), | ||
( | ||
"no-permissions-for-users", "user", | ||
[], | ||
["user_a", "user_b"], | ||
[] | ||
), | ||
( | ||
"permissions-for-some-groups", "group", | ||
[ | ||
"read:groups:name!group=group-x", | ||
"read:groups:name!group=group-b", | ||
"read:groups:name!group=group-c", | ||
"read:groups:name!group=group-y", | ||
], | ||
["group-a", "group-b", "group-c", "group-d"], | ||
["group-b", "group-c"] | ||
), | ||
( | ||
"permissions-for-no-groups", "group", | ||
[], | ||
["group-a", "group-b", "group-c", "group-d"], | ||
[] | ||
), | ||
]) | ||
def test_filter_users_based_on_scopes(name, entity_key, scopes, entities, expected_entities): | ||
filtered_entities = filter_entity_based_on_scopes( | ||
scopes=scopes, | ||
entities=entities, | ||
entity_key=entity_key | ||
) | ||
assert set(filtered_entities) == set(expected_entities) |