|
18 | 18 |
|
19 | 19 | from fauxfactory import gen_mac, gen_string |
20 | 20 | import pytest |
| 21 | +from wait_for import wait_for |
21 | 22 |
|
22 | 23 | from robottelo.config import settings |
23 | 24 | from robottelo.constants import CLIENT_PORT |
@@ -400,3 +401,84 @@ def test_positive_verify_default_location_for_registered_host( |
400 | 401 | query={"search": f'name={rhel_contenthost.hostname}'} |
401 | 402 | )[0] |
402 | 403 | assert host.location.read().name == module_location.name |
| 404 | + |
| 405 | + |
| 406 | +@pytest.mark.no_containers |
| 407 | +@pytest.mark.rhel_ver_list([settings.content_host.default_rhel_version]) |
| 408 | +def test_positive_invalidating_users_tokens( |
| 409 | + module_target_sat, rhel_contenthost, module_activation_key, module_org, request |
| 410 | +): |
| 411 | + """Verify invalidating single and multiple users tokens. |
| 412 | +
|
| 413 | + :id: 5db602d4-9c57-4b70-8d46-5323044824e0 |
| 414 | +
|
| 415 | + :steps: |
| 416 | + 1. Create an admin user and a non-admin user with "edit_users" and "register_hosts" permission. |
| 417 | + 2. Generate a token with admin user and register a host with it, it should be successful. |
| 418 | + 3. Invalidate the token and try to use the generated token again to register the host, it should fail. |
| 419 | + 4. Invalidate tokens for multiple users with "invalidate-multiple" command, it should invalidate all the tokens for provided users. |
| 420 | + 5. Repeat Steps 2,3 and 4 with non-admin user and it should work the same way. |
| 421 | +
|
| 422 | + :expectedresults: Host registration will not be possible after/with invalidated tokens. |
| 423 | +
|
| 424 | + :CaseImportance: Critical |
| 425 | +
|
| 426 | + :Verifies: SAT-30385 |
| 427 | + """ |
| 428 | + password = settings.server.admin_password |
| 429 | + admin_user = module_target_sat.api.User().search( |
| 430 | + query={'search': f'login={settings.server.admin_username}'} |
| 431 | + )[0] |
| 432 | + |
| 433 | + # Non-Admin user with "edit_users" permission and "Register hosts" role |
| 434 | + non_admin_user = module_target_sat.api.User( |
| 435 | + login=gen_string('alpha'), password=password, organization=[module_org] |
| 436 | + ).create() |
| 437 | + role = module_target_sat.cli_factory.make_role({'organization-id': module_org.id}) |
| 438 | + module_target_sat.cli_factory.add_role_permissions( |
| 439 | + role.id, |
| 440 | + resource_permissions={'User': {'permissions': ['edit_users']}}, |
| 441 | + ) |
| 442 | + module_target_sat.cli.User.add_role({'id': non_admin_user.id, 'role-id': role.id}) |
| 443 | + module_target_sat.cli.User.add_role({'id': non_admin_user.id, 'role': 'Register hosts'}) |
| 444 | + |
| 445 | + # delete the host and the user |
| 446 | + @request.addfinalizer |
| 447 | + def _finalize(): |
| 448 | + wait_for(lambda: module_target_sat.cli.Host.delete({'name': rhel_contenthost.hostname})) |
| 449 | + module_target_sat.cli.User.delete({'login': non_admin_user.login}) |
| 450 | + |
| 451 | + # Generate token and verify token invalidation |
| 452 | + for usertype in (admin_user, non_admin_user): |
| 453 | + user = admin_user if usertype.admin else non_admin_user |
| 454 | + cmd = module_target_sat.cli.HostRegistration.with_user( |
| 455 | + user.login, password |
| 456 | + ).generate_command( |
| 457 | + options={ |
| 458 | + 'activation-keys': module_activation_key.name, |
| 459 | + 'insecure': 'true', |
| 460 | + 'organization-id': module_org.id, |
| 461 | + } |
| 462 | + ) |
| 463 | + result = rhel_contenthost.execute(cmd.strip('\n')) |
| 464 | + assert result.status == 0, f'Failed to register host: {result.stderr}' |
| 465 | + |
| 466 | + # Invalidate JWTs for a single user |
| 467 | + result = module_target_sat.cli.User.with_user(user.login, password).invalidate( |
| 468 | + options={ |
| 469 | + 'user-id': user.id, |
| 470 | + } |
| 471 | + ) |
| 472 | + assert f'Successfully invalidated registration tokens for {user.login}' in result |
| 473 | + |
| 474 | + rhel_contenthost.unregister() |
| 475 | + # Re-register the host with invalidated token |
| 476 | + result = rhel_contenthost.execute(cmd.strip('\n')) |
| 477 | + assert result.status == 1 |
| 478 | + assert 'ERROR: unauthorized' in result.stdout |
| 479 | + |
| 480 | + # Invalidate JWTs for multiple users |
| 481 | + result = module_target_sat.cli.User.with_user(user.login, password).invalidate_multiple( |
| 482 | + options={'search': f"id ^ ({admin_user.id}, {non_admin_user.id})"} |
| 483 | + ) |
| 484 | + assert 'Successfully invalidated registration tokens' in result |
0 commit comments