def test_cancel_tasks(service: OSCAPService): data = PolicyData() data.content_type = "scap-security-guide" data.profile_id = "Web Server" service.policy_enabled = True service.policy_data = data # Collect all tasks. tasks = service.configure_with_tasks() + service.install_with_tasks() # No task is canceled by default. for task in tasks: assert task.check_cancel() is False callback = Mock() service.installation_canceled.connect(callback) # The first task should fail with the given data. with pytest.raises(Exception): tasks[0].run_with_signals() # That should cancel all tasks. callback.assert_called_once() for task in tasks: assert task.check_cancel() is True
def test_configure_with_tasks(service: OSCAPService, interface: OSCAPInterface): data = PolicyData() data.content_type = "scap-security-guide" data.profile_id = "Web Server" service.policy_enabled = True service.policy_data = data object_paths = interface.ConfigureWithTasks() assert len(object_paths) == 2 tasks = TaskContainer.from_object_path_list(object_paths) assert isinstance(tasks[0], installation.PrepareValidContent) assert isinstance(tasks[1], installation.EvaluateRulesTask)
def test_install_with_tasks(service: OSCAPService, interface: OSCAPInterface): data = PolicyData() data.content_type = "scap-security-guide" data.profile_id = "Web Server" data.remediate = "both" service.policy_enabled = True service.policy_data = data object_paths = interface.InstallWithTasks() assert len(object_paths) == 3 tasks = TaskContainer.from_object_path_list(object_paths) assert isinstance(tasks[0], installation.InstallContentTask) assert isinstance(tasks[1], installation.RemediateSystemTask) assert isinstance(tasks[2], installation.ScheduleFirstbootRemediationTask)
def test_datastream_requirements(service: OSCAPService, interface: OSCAPInterface): data = PolicyData() data.content_type = "datastream" data.profile_id = "Web Server" service.policy_enabled = True service.policy_data = data requirements = Requirement.from_structure_list( interface.CollectRequirements()) assert len(requirements) == 2 assert requirements[0].type == REQUIREMENT_TYPE_PACKAGE assert requirements[0].name == "openscap" assert requirements[1].type == REQUIREMENT_TYPE_PACKAGE assert requirements[1].name == "openscap-scanner"
def test_no_requirements(service: OSCAPService, interface: OSCAPInterface): service.policy_enabled = True service.policy_data = PolicyData() assert interface.CollectRequirements() == []
def service(): return OSCAPService()
# # Copyright (C) 2020 Red Hat, Inc. # # This copyrighted material is made available to anyone wishing to use, # modify, copy, or redistribute it subject to the terms and conditions of # the GNU General Public License v.2, or (at your option) any later version. # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY expressed or implied, including the implied warranties of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General # Public License for more details. You should have received a copy of the # GNU General Public License along with this program; if not, write to the # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA # 02110-1301, USA. Any Red Hat trademarks that are incorporated in the # source code or documentation are not subject to the GNU General Public # License and may only be used or replicated with the express permission of # Red Hat, Inc. # # Initialize the service. from pyanaconda.modules.common import init init() # Start the service. from org_fedora_oscap.service.oscap import OSCAPService service = OSCAPService() service.run()