From 1c07157524c12dfd96f900daeee4d4f5ab753c00 Mon Sep 17 00:00:00 2001 From: Rajasi Rane Date: Thu, 14 Sep 2023 15:29:47 -0700 Subject: [PATCH] Adding EULA acceptance: Accepting boolean values in different formats --- src/core/src/core_logic/ExecutionConfig.py | 2 +- src/core/tests/Test_AptitudePackageManager.py | 120 ++++++++++++++++++ 2 files changed, 121 insertions(+), 1 deletion(-) diff --git a/src/core/src/core_logic/ExecutionConfig.py b/src/core/src/core_logic/ExecutionConfig.py index 5048e99c..48044e67 100644 --- a/src/core/src/core_logic/ExecutionConfig.py +++ b/src/core/src/core_logic/ExecutionConfig.py @@ -192,7 +192,7 @@ def __is_eula_accepted_for_all_patches(self): accept_eula_for_all_patches = self.__fetch_specific_eula_setting(eula_settings, Constants.EulaSettings.ACCEPT_EULA_FOR_ALL_PATCHES) accepted_by = self.__fetch_specific_eula_setting(eula_settings, Constants.EulaSettings.ACCEPTED_BY) last_modified = self.__fetch_specific_eula_setting(eula_settings, Constants.EulaSettings.LAST_MODIFIED) - if accept_eula_for_all_patches is not None and accept_eula_for_all_patches is True: + if accept_eula_for_all_patches is not None and accept_eula_for_all_patches in [True, 'True', 'true', '1', 1]: is_eula_accepted = True self.composite_logger.log_debug("EULA config values from disk: [AcceptEULAForAllPatches={0}] [AcceptedBy={1}] [LastModified={2}]. Computed value of [IsEULAAccepted={3}]" .format(str(accept_eula_for_all_patches), str(accepted_by), str(last_modified), str(is_eula_accepted))) diff --git a/src/core/tests/Test_AptitudePackageManager.py b/src/core/tests/Test_AptitudePackageManager.py index ce1d4794..62992185 100644 --- a/src/core/tests/Test_AptitudePackageManager.py +++ b/src/core/tests/Test_AptitudePackageManager.py @@ -621,6 +621,126 @@ def test_eula_acceptance_file_read_success(self): self.assertEqual(execution_config.accept_package_eula, False) runtime.stop() + # Accept EULA set to true in a string i.e. 'true' + eula_settings = { + "AcceptEULAForAllPatches": 'true', + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, True) + runtime.stop() + + # Accept EULA set to true in a string i.e. 'True' + eula_settings = { + "AcceptEULAForAllPatches": 'True', + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, True) + runtime.stop() + + # Accept EULA set to true in a string i.e. 'False' + eula_settings = { + "AcceptEULAForAllPatches": 'False', + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, False) + runtime.stop() + + # Accept EULA set to true in a string i.e. 'false' + eula_settings = { + "AcceptEULAForAllPatches": 'false', + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, False) + runtime.stop() + + # Accept EULA set as '0' + eula_settings = { + "AcceptEULAForAllPatches": '0', + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, False) + runtime.stop() + + # Accept EULA set as 0 + eula_settings = { + "AcceptEULAForAllPatches": 0, + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, False) + runtime.stop() + + # Accept EULA set as 1 + eula_settings = { + "AcceptEULAForAllPatches": 1, + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, True) + runtime.stop() + + # Accept EULA set as '1' + eula_settings = { + "AcceptEULAForAllPatches": '1', + "AcceptedBy": "TestSetup", + "LastModified": "2023-08-29" + } + f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+") + f.write(json.dumps(eula_settings)) + f.close() + runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT) + container = runtime.container + execution_config = container.get('execution_config') + self.assertEqual(execution_config.accept_package_eula, True) + runtime.stop() + def test_eula_acceptance_file_read_when_no_data_found(self): self.runtime.stop()