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

Add support for invalidating users JWTs #17465

Merged
merged 1 commit into from
Feb 6, 2025

Conversation

shweta83
Copy link
Contributor

Problem Statement

Add support for Invalidate JWT feature : SAT-27385

Solution

Added support for it.

Related Issues

SatelliteQE/airgun#1721

@shweta83 shweta83 added No-CherryPick PR doesnt need CherryPick to previous branches Stream Introduced in or relating directly to Satellite Stream/Master labels Jan 30, 2025
@shweta83 shweta83 requested a review from a team January 30, 2025 11:18
@shweta83 shweta83 requested a review from a team as a code owner January 30, 2025 11:18
tests/foreman/ui/test_user.py Outdated Show resolved Hide resolved
tests/foreman/ui/test_user.py Outdated Show resolved Hide resolved
tests/foreman/ui/test_user.py Outdated Show resolved Hide resolved
tests/foreman/ui/test_user.py Show resolved Hide resolved
@@ -307,6 +308,88 @@ def test_positive_create_product_with_limited_user_permission(
assert newsession.product.search(product_name)[0]['Name'] == product_name


@pytest.mark.rhel_ver_match('8')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tier decorator

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need tier decorator now? What is the purpose to use it. I thought it has become obsolete now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frankly, I don't know. At least for consistency, I would expect it to be there. Best to ask CI team what is expected regarding tier decorators.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember a discussion over it and I think it is not required but would like to have some thoughts on it.
@devendra104 wdyt?

:id: be328fd7-b640-4080-9373-25f96ba2aef6

:steps:
1. Create an admin user and an non-admin user with "edit_users" and "view_users" permissions.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be a test for a user without edit_users and view_users permissions invalidating their own JWT token?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't work with UI as Administer -> Settings -> User tab won't be visible without these permissions so I left that out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the ticket, Scope part:

A user can invalidate self's token

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that too needs same permissions for UI.

'password': password,
}
role = module_target_sat.cli.Role.info({'name': 'Register hosts'})
module_target_sat.cli.User.add_role({'id': non_admin_user.id, 'role-id': role['id']})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add the role while creating the user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally done . There are 2 roles in it.

result = session.login.logout()

session.login.login(login_details)
session.user.invalidate_jwt(admin_user.login)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't assert anything after invalidating admin's token.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I missed that. Updated.

activation_keys=[ak.name],
force=True,
)
assert result.status == 1, f'Failed to register host: {result.stderr}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is probably a wrong error message when this fails. Also, it may be worth it checking more than just status.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. Updated

session.organization.select(org.name)
session.location.select(module_location.name)
user_cfg = user_nailgun_config(non_admin_user, password)
result = rhel_contenthost.api_register(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may be missing something here. Where do you generate the JWT? Does api_register do it? How come it doesn't do the same, i.e. generate a new JWT, when you use it the second time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The token generated by registration command is the one. But, I have missed one point earlier which I have updated in the code. Please check.

@shweta83
Copy link
Contributor Author

shweta83 commented Feb 4, 2025

trigger: test-robottelo
pytest: tests/foreman/ui/test_user.py -k test_positive_invalidate_jwt

@Satellite-QE
Copy link
Collaborator

PRT Result

Build Number: 10040
Build Status: UNSTABLE
PRT Comment: pytest tests/foreman/ui/test_user.py -k test_positive_invalidate_jwt --external-logging
Test Result : ========== 1 failed, 11 deselected, 21 warnings in 711.80s (0:11:51) ===========

@Satellite-QE Satellite-QE added the PRT-Failed Indicates that latest PRT run is failed for the PR label Feb 4, 2025
@shweta83 shweta83 force-pushed the jwt_invalidate branch 3 times, most recently from 61314c6 to a71c6af Compare February 4, 2025 08:30
@shweta83
Copy link
Contributor Author

shweta83 commented Feb 4, 2025

trigger: test-robottelo
pytest: tests/foreman/ui/test_user.py -k test_positive_invalidate_jwt
airgun: 1721

@Satellite-QE
Copy link
Collaborator

PRT Result

Build Number: 10041
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_user.py -k test_positive_invalidate_jwt --external-logging
Test Result : ========== 1 passed, 11 deselected, 22 warnings in 726.32s (0:12:06) ===========

@Satellite-QE Satellite-QE added PRT-Passed Indicates that latest PRT run is passed for the PR and removed PRT-Failed Indicates that latest PRT run is failed for the PR labels Feb 4, 2025
@shweta83 shweta83 requested a review from girijaasoni February 4, 2025 12:17
Copy link
Contributor

@shubhamsg199 shubhamsg199 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, one suggestion

tests/foreman/ui/test_user.py Show resolved Hide resolved
@Satellite-QE Satellite-QE removed the PRT-Passed Indicates that latest PRT run is passed for the PR label Feb 6, 2025
@shweta83
Copy link
Contributor Author

shweta83 commented Feb 6, 2025

trigger: test-robottelo
pytest: tests/foreman/ui/test_user.py -k test_positive_invalidate_jwt
airgun: 1721

@Satellite-QE
Copy link
Collaborator

PRT Result

Build Number: 10087
Build Status: SUCCESS
PRT Comment: pytest tests/foreman/ui/test_user.py -k test_positive_invalidate_jwt --external-logging
Test Result : ========== 1 passed, 11 deselected, 24 warnings in 2272.02s (0:37:52) ==========

@Satellite-QE Satellite-QE added the PRT-Passed Indicates that latest PRT run is passed for the PR label Feb 6, 2025
@shubhamsg199 shubhamsg199 merged commit 2586247 into SatelliteQE:master Feb 6, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
No-CherryPick PR doesnt need CherryPick to previous branches PRT-Passed Indicates that latest PRT run is passed for the PR Stream Introduced in or relating directly to Satellite Stream/Master
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants