From be5b2780c3524456df6615ff910884dd911b2c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adria=CC=80=20Sala?= Date: Mon, 20 Jan 2025 09:52:44 +0100 Subject: [PATCH] feat: add tests for project update service acc credentials --- awx/main/tests/unit/test_tasks.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/awx/main/tests/unit/test_tasks.py b/awx/main/tests/unit/test_tasks.py index 9ac278b5689b..79b77fa359e5 100644 --- a/awx/main/tests/unit/test_tasks.py +++ b/awx/main/tests/unit/test_tasks.py @@ -1104,6 +1104,37 @@ def test_awx_task_env(self, project_update, settings, private_data_dir, scm_type assert env['FOO'] == 'BAR' +class TestProjectUpdateServiceAccountCredentials(TestJobExecution): + @pytest.fixture + def project_update(self): + project_update = ProjectUpdate( + pk=1, + project=Project(pk=1, organization=Organization(pk=1)), + ) + project_update.websocket_emit_status = mock.Mock() + return project_update + + def test_service_account_credentials(self, project_update, mock_me): + expected_id = '4ns1bl3' + expected_secret = 'w0rks-rul3s' + + task = jobs.RunProjectUpdate() + insights = CredentialType.defaults['insights']() + project_update.credential = Credential(pk=1, credential_type=insights, inputs={'client_id': expected_id, 'client_secret': expected_secret}) + project_update.credential.inputs['client_secret'] = encrypt_field(project_update.credential, 'client_secret') + + passwords = task.build_passwords(project_update, {}) + password_prompts = task.get_password_prompts(passwords) + expect_passwords = task.create_expect_passwords_data_struct(password_prompts, passwords) + cred_list = task.build_credentials_list(project_update) + + assert expected_id in expect_passwords.values() + assert expected_secret in expect_passwords.values() + + assert len(cred_list) == 1 + assert 'client_id' in cred_list[0].inputs + + class TestInventoryUpdateCredentials(TestJobExecution): @pytest.fixture def inventory_update(self, execution_environment):