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

Sync to 2 different DAB team member roles #2241

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

AlanCoding
Copy link
Member

@AlanCoding AlanCoding commented Aug 22, 2024

What is this PR doing:

Testing for this is problematic. I will share my hacked tests for this. The first blurb is the one that really can't be tested by other means.

from uuid import uuid4

from galaxy_ng.app.models import Team, Organization, User

from ansible_base.rbac.models import RoleDefinition


test_string = f'gateway_member_{str(uuid4())}'


member_rd = RoleDefinition.objects.filter(name='Team Member').first()

assert member_rd

org = Organization.objects.create(name=test_string)
team = Team.objects.create(name=test_string, organization=org)

user = User.objects.create(username=test_string)

member_rd.give_permission(user, team)

assert user in team.group.user_set.all()

This test could maybe be an integration test.

from uuid import uuid4

from galaxy_ng.app.models import Team, Organization, User

from ansible_base.rbac.models import RoleDefinition, RoleUserAssignment


test_string = f'gateway_member_{str(uuid4())}'


local_member_rd = RoleDefinition.objects.filter(name='Galaxy Team Member').first()
shared_member_rd = RoleDefinition.objects.filter(name='Team Member').first()

assert local_member_rd, -1
assert shared_member_rd, 0

org = Organization.objects.create(name=test_string)
team = Team.objects.create(name=test_string, organization=org)

user = User.objects.create(username=test_string)


team.group.user_set.add(user)
# team.users.add(user)  # did not connect signals for this

assert user.has_obj_perm(team, 'member'), 0.5

assert not RoleUserAssignment.objects.filter(role_definition=shared_member_rd, object_id=team.id, user=user).exists(), 1
assert RoleUserAssignment.objects.filter(role_definition=local_member_rd, object_id=team.id, user=user).exists(), 2

assert user in team.group.user_set.all(), 3
# assert user in team.users.all(), 4  # TODO: not sure if this should be a thing?

Issue: AAH-3358

requires ansible/django-ansible-base#562

Reviewers must know:

To run this I had to install from:

pip install git+https://github.com/alancoding/django-ansible-base.git@local_management

Then I commented out the skip on test_team_member_sync_from_dab_to_pulp, and that was passing. So more of the testing from this could/should be absorbed into that.

The "Team Member" role, however, will be set by jwt_consumer, and there is no way to test that other than hacking.

@github-actions github-actions bot added backport-4.2 This PR should be backported to stable-4.2 (1.2) backport-4.4 This PR should be backported to stable-4.4 (2.1) backport-4.5 This PR should be backported to stable-4.5 (2.2) backport-4.6 This PR should be backported to stable-4.6 (2.3) backport-4.7 This PR should be backported to stable-4.7 (2.4) backport-4.8 This PR should be backported to stable-4.8 (2.4) backport-4.9 This PR should be backported to stable-4.9 (2.4) labels Aug 22, 2024
@jctanner jctanner removed backport-4.2 This PR should be backported to stable-4.2 (1.2) backport-4.4 This PR should be backported to stable-4.4 (2.1) backport-4.5 This PR should be backported to stable-4.5 (2.2) backport-4.6 This PR should be backported to stable-4.6 (2.3) backport-4.7 This PR should be backported to stable-4.7 (2.4) backport-4.8 This PR should be backported to stable-4.8 (2.4) backport-4.9 This PR should be backported to stable-4.9 (2.4) labels Aug 22, 2024
@AlanCoding
Copy link
Member Author

I got 1 failure from this check

galaxy_ng/tests/integration/api/test_artifact_upload.py::test_api_publish_ignore_files_logged �[31mFAILED�[0m�[31m [ 35%]�[0m
2024-08-22T15:58:22.0104355Z             # Make the request on the HTTPConnection object
2024-08-22T15:58:22.0104905Z >           response = self._make_request(
2024-08-22T15:58:22.0105235Z                 conn,
2024-08-22T15:58:22.0105468Z                 method,
2024-08-22T15:58:22.0105708Z                 url,
2024-08-22T15:58:22.0105954Z                 timeout=timeout_obj,
2024-08-22T15:58:22.0106251Z                 body=body,
2024-08-22T15:58:22.0106517Z                 headers=headers,
2024-08-22T15:58:22.0106805Z                 chunked=chunked,
2024-08-22T15:58:22.0107083Z                 retries=retries,
2024-08-22T15:58:22.0107395Z                 response_conn=response_conn,
2024-08-22T15:58:22.0107762Z                 preload_content=preload_content,
2024-08-22T15:58:22.0108121Z                 decode_content=decode_content,
2024-08-22T15:58:22.0108454Z                 **response_kw,
2024-08-22T15:58:22.0108717Z             )
2024-08-22T15:58:22.0123003Z         if not version.startswith("HTTP/"):
2024-08-22T15:58:22.0123340Z             self._close_conn()
2024-08-22T15:58:22.0123641Z >           raise BadStatusLine(line)
2024-08-22T15:58:22.0124710Z �[1m�[31mE           http.client.BadStatusLine: GET /api/automation-hub/content/staging/v3/plugin/ansible/imports/collections/01917ac7-cbe4-768a-b075-ac454f437a3e/ HTTP/1.1�[0m
2024-08-22T15:58:22.0125562Z 
2024-08-22T15:58:22.0125836Z �[1m�[31m/usr/lib64/python3.11/http/client.py�[0m:307: BadStatusLine
2024-08-22T15:58:22.0126234Z 

@AlanCoding
Copy link
Member Author

now I'm getting this

ERROR: Missing change log entry for issue AAH-3358.

Log and ignore removing users that can not be removed
Issue: AAH-3358
@AlanCoding AlanCoding marked this pull request as ready for review August 22, 2024 17:23
@jctanner jctanner merged commit d216f60 into ansible:master Aug 22, 2024
20 of 22 checks passed
@AlanCoding
Copy link
Member Author

Documenting a hypothetical test for the 2nd script mentioned above:

def test_group_sync_from_pulp_to_dab_via_group(galaxy_client, assert_user_in_group, user_and_group):
    "The group users relationship is the reverse of the user groups relationship"
    gc = galaxy_client("admin")
    user, group = user_and_group

    assert_user_in_group(user["id"], group["id"], expected=False)
    old_users = group["users"].copy()
    group["users"].append(user)

    gc.patch(f"_ui/v2/groups/{group['id']}/", body={"users": group["users"]})
    assert_user_in_group(user["id"], group["id"], expected=True)

    gc.patch(f"_ui/v2/groups/{group['id']}/", body={"users": old_users})
    assert_user_in_group(user["id"], group["id"], expected=False)

This does not work because the group-detail endpoint does not actually take in users as a field. So this can not be done via the API in integration tests. And current tests are taken as sufficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants