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

Adding EULA acceptance based on an inVM approval mechanism #215

Merged
merged 12 commits into from
Sep 14, 2023
Merged
96 changes: 96 additions & 0 deletions src/core/tests/Test_AptitudePackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,102 @@ def test_eula_not_accepted_for_patches(self):
self.assertTrue("ACCEPT_EULA=Y" not in package_manager_for_test.single_package_dependency_resolution_template)
self.assertTrue("ACCEPT_EULA=Y" not in package_manager_for_test.single_package_upgrade_cmd)

def test_eula_acceptance_file_read_success(self):
self.runtime.stop()

# Accept EULA set to 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 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()
rane-rajasi marked this conversation as resolved.
Show resolved Hide resolved

def test_eula_acceptance_file_read_when_no_data_found(self):
self.runtime.stop()

# EULA file does not exist
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)
self.assertFalse(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

# EULA settings set to None
eula_settings = None
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)
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

# AcceptEULAForAllPatches not set in config
eula_settings = {
"AcceptedBy": "TestSetup",
"LastModified": "2023-08-29"
}
f = open(Constants.AzGPSPaths.EULA_SETTINGS, "w+")
f.write(json.dumps(eula_settings))
f.close()
rane-rajasi marked this conversation as resolved.
Show resolved Hide resolved
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)
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

# AcceptEULAForAllPatches not set to a boolean
eula_settings = {
"AcceptEULAForAllPatches": "test",
"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)
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

# EULA not accepted for cases where file read raises an Exception
runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT)
self.backup_read_with_retry = runtime.env_layer.file_system.read_with_retry
runtime.env_layer.file_system.read_with_retry = self.mock_read_with_retry_raise_exception
exec_config = ExecutionConfig(runtime.env_layer, runtime.composite_logger, str(self.argument_composer))
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
self.assertEqual(exec_config.accept_package_eula, False)
runtime.stop()
rane-rajasi marked this conversation as resolved.
Show resolved Hide resolved


if __name__ == '__main__':
unittest.main()
101 changes: 1 addition & 100 deletions src/core/tests/Test_ConfigurationFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
# limitations under the License.
#
# Requires Python 2.7+
import json
import os

import unittest
from core.src.bootstrap.Bootstrapper import Bootstrapper
from core.src.bootstrap.Constants import Constants
Expand All @@ -31,9 +30,6 @@ def setUp(self):
def tearDown(self):
self.runtime.stop()

def mock_read_with_retry_raise_exception(self):
raise Exception

def test_get_prod_config_correctly(self):
bootstrapper = Bootstrapper(self.argument_composer, capture_stdout=False)
config_factory = bootstrapper.configuration_factory
Expand Down Expand Up @@ -63,101 +59,6 @@ def test_get_dev_config_correctly(self):
self.assertEqual(config['package_manager_name'], Constants.APT)
self.assertEqual(config['config_env'], Constants.DEV)

def test_eula_acceptance_file_read_success(self):
self.runtime.stop()

# Accept EULA set to 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 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()

def test_eula_acceptance_file_read_when_no_data_found(self):
self.runtime.stop()

# EULA file does not exist
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)
self.assertFalse(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

# EULA settings set to None
eula_settings = None
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)
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

# AcceptEULAForAllPatches not set in config
eula_settings = {
"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)
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

# AcceptEULAForAllPatches not set to a boolean
eula_settings = {
"AcceptEULAForAllPatches": "test",
"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)
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
runtime.stop()

runtime = RuntimeCompositor(self.argument_composer, True, package_manager_name=Constants.APT)
container = runtime.container
self.backup_read_with_retry = runtime.env_layer.file_system.read_with_retry
runtime.env_layer.file_system.read_with_retry = self.mock_read_with_retry_raise_exception
self.assertTrue(os.path.exists(Constants.AzGPSPaths.EULA_SETTINGS))
self.assertRaises(Exception, container.get('execution_config'))
runtime.stop()


if __name__ == '__main__':
unittest.main()
Loading