From c07ff59f4cbf852568b971f67c5b413db6c89117 Mon Sep 17 00:00:00 2001 From: Peter Ondrejka Date: Fri, 19 Jan 2024 15:15:22 +0100 Subject: [PATCH] effective user with non-ascii password --- tests/foreman/cli/test_remoteexecution.py | 38 ++++++++++++++++++++--- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/tests/foreman/cli/test_remoteexecution.py b/tests/foreman/cli/test_remoteexecution.py index d892b4dbb4a..ad73fefc6ae 100644 --- a/tests/foreman/cli/test_remoteexecution.py +++ b/tests/foreman/cli/test_remoteexecution.py @@ -157,26 +157,33 @@ def test_positive_run_default_job_template( @pytest.mark.pit_server @pytest.mark.rhel_ver_list([7, 8, 9]) def test_positive_run_job_effective_user(self, rex_contenthost, module_target_sat): - """Run default job template as effective user on a host + """Run default job template as effective user on a host, test ssh user as well :id: 0cd75cab-f699-47e6-94d3-4477d2a94bb7 - :BZ: 1451675, 1804685 + :BZ: 1451675, 1804685, 2258968 :expectedresults: Verify the job was successfully run under the - effective user identity on host + effective user identity on host, make sure the password is + used :parametrized: yes + + :customerscenario: true """ client = rex_contenthost # create a user on client via remote job + ssh_username = gen_string('alpha') + ssh_password = gen_string('alpha') username = gen_string('alpha') + password = gen_string('cjk') filename = gen_string('alpha') make_user_job = module_target_sat.cli_factory.job_invocation( { 'job-template': 'Run Command - Script Default', - 'inputs': f"command=useradd -m {username}", + 'inputs': f"command=useradd {ssh_username}; echo {ssh_username}:{ssh_password} | chpasswd; useradd {username}; echo {username}:{password} | chpasswd", 'search-query': f"name ~ {client.hostname}", + 'description-format': 'adding users', } ) assert_job_invocation_result(module_target_sat, make_user_job['id'], client.hostname) @@ -186,7 +193,10 @@ def test_positive_run_job_effective_user(self, rex_contenthost, module_target_sa 'job-template': 'Run Command - Script Default', 'inputs': f"command=touch /home/{username}/{filename}", 'search-query': f"name ~ {client.hostname}", + 'ssh-user': f'{ssh_username}', + 'password': f'{ssh_password}', 'effective-user': f'{username}', + 'effective-user-password': f'{password}', } ) assert_job_invocation_result(module_target_sat, invocation_command['id'], client.hostname) @@ -196,6 +206,26 @@ def test_positive_run_job_effective_user(self, rex_contenthost, module_target_sa ) # assert the file is owned by the effective user assert username == result.stdout.strip('\n') + result = client.execute( + f'''stat -c '%G' /home/{username}/{filename}''', + ) + # assert the file is in the effective user's group + assert username == result.stdout.strip('\n') + # negative check for unspecified password + filename = gen_string('alpha') + invocation_command = module_target_sat.cli_factory.job_invocation( + { + 'job-template': 'Run Command - Script Default', + 'inputs': f"command=touch /home/{username}/{filename}", + 'search-query': f"name ~ {client.hostname}", + 'ssh-user': f'{ssh_username}', + 'password': f'{ssh_password}', + 'effective-user': f'{username}', + } + ) + assert_job_invocation_result( + module_target_sat, invocation_command['id'], client.hostname, 'fail' + ) @pytest.mark.tier3 @pytest.mark.e2e