Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

YDA-6113: Prevent returning incomplete groups in group_data #548

Merged
merged 1 commit into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,11 @@ def internal_api_group_data(ctx: rule.Context) -> Dict:

categories = getDatamanagerCategories(ctx)

# Filter groups (only return groups user is part of), convert to json and write to stdout.
groups = list(filter(lambda group: full_name in group['read'] + group['members'] or group['category'] in categories, groups))
# Filter groups (only return groups user is part of)
groups = list(filter(
lambda group:
full_name in group['read'] + group['members']
or ('category' in group and group['category'] in categories), groups))

# Only process group types managed via group manager
managed_prefixes = ("priv-", "deposit-", "research-", "grp-", "datamanager-", "datarequests-", "intake-")
Expand Down
37 changes: 25 additions & 12 deletions integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,26 +248,30 @@ def _test_folder_set_get_last_run(ctx):
return result, found, last_run


def _test_groups_data(ctx):
test_vaultgroup = "vault-default-3"
ctx.msi_add_avu('-u', test_vaultgroup, "schema_id", "default-3", "")
groups_data = groups.internal_api_group_data(ctx)
avu.rmw_from_group(ctx, test_vaultgroup, "schema_id", "default-3", "")
def _test_groups_data(ctx, test_group, attribute, value):
ctx.msi_add_avu('-u', test_group, attribute, value, "")
try:
groups_data = groups.internal_api_group_data(ctx)
except KeyError:
avu.rmw_from_group(ctx, test_group, attribute, value, "")
raise

avu.rmw_from_group(ctx, test_group, attribute, value, "")
group_names = [group
for catdata in groups_data['group_hierarchy'].values()
for subcatdata in catdata.values()
for group in subcatdata]
# We are checking here that the function still works if we have a
# vault group with a group attribute, that the vault group is not
# returned (since vault groups are not managed via the group manager
# module), and that data is returned for group manager managed groups.
# We check here that the function still works if the test user has a
# group attribute, but doesn't have all the attributes needed to be
# a research group. Also check that data is still returned for valid
# group manager managed groups.
return ("research-default-3" in group_names
and "datarequests-research-datamanagers" in group_names
and "grp-vault-test" in group_names
and "intake-test2" in group_names
and "deposit-pilot" in group_names
and "datamanager-test-automation" in group_names
and "vault-default-3" not in group_names)
and test_group not in group_names)


def _test_schema_active_schema_deposit_from_default(ctx):
Expand Down Expand Up @@ -564,8 +568,17 @@ def _test_folder_secure_func(ctx, func):
{"name": "folder.determine_new_vault_target.invalid",
"test": lambda ctx: folder.determine_new_vault_target(ctx, "/tempZone/home/not-research-group-not-exist/folder-not-exist"),
"check": lambda x: x == ""},
{"name": "groups.getGroupsData",
"test": lambda ctx: _test_groups_data(ctx),
{"name": "groups.getGroupsData.vault",
"test": lambda ctx: _test_groups_data(ctx, "vault-default-3", "schema_id", "default-3"),
"check": lambda x: x},
{"name": "groups.getGroupsData.public.category",
"test": lambda ctx: _test_groups_data(ctx, "public", "category", "integration-test-cat"),
"check": lambda x: x},
{"name": "groups.getGroupsData.public.subcategory",
"test": lambda ctx: _test_groups_data(ctx, "public", "subcategory", "integration-test-subcat"),
"check": lambda x: x},
{"name": "groups.getGroupsData.public.schema_id",
"test": lambda ctx: _test_groups_data(ctx, "public", "schema_id", "default-3"),
"check": lambda x: x},
{"name": "groups.rule_group_expiration_date_validate.1",
"test": lambda ctx: ctx.rule_group_expiration_date_validate("", ""),
Expand Down
Loading