def test_apache_conf_and_check(self, mock_write, mock_ensure_permissions, mock_subprocess): mock_subprocess.call.return_value = 0 apache_version = b"""Server version: Apache/2.4.7 (Ubuntu) Server built: Jan 14 2016 17:45:23 """ mock_subprocess.check_output.return_value = apache_version audits = apache_config_check.get_audits() contentcheckers = self.get_contentcheckers(audits) renderers = self.get_renderers(audits) def write(path, data): if path in self.pathindex: raise Exception("File already rendered '%s'" % path) with tempfile.NamedTemporaryFile(delete=False) as ftmp: self.pathindex[path] = ftmp.name with open(ftmp.name, 'wb') as fd: fd.write(data) mock_write.side_effect = write self.render(renderers) self.checkcontents(contentcheckers) self.assertTrue(mock_write.called) args_list = mock_write.call_args_list self.assertEqual('/tmp/foo/mods-available/alias.conf', args_list[0][0][0]) self.assertEqual(mock_write.call_count, 2)
def test_file_permission_audit(self): audits = config.get_audits() settings = config.utils.get_settings('apache') conf_file_name = 'apache2.conf' conf_file_path = os.path.join(settings['common']['apache_dir'], conf_file_name) self.assertEqual(audits[0].paths[0], conf_file_path)
def run_apache_checks(): log("Starting Apache hardening checks.", level=DEBUG) checks = config.get_audits() for check in checks: log("Running '%s' check" % (check.__class__.__name__), level=DEBUG) check.ensure_compliance() log("Apache hardening checks complete.", level=DEBUG)
def run_apache_checks(): log("Starting Apache hardening checks.", level=DEBUG) checks = config.get_audits() for check in checks: log("Running '%s' check" % (check.__class__.__name__), level=DEBUG) check.ensure_compliance() log("Apache hardening checks complete.", level=DEBUG)
def test_get_audits_apache_is_installed(self): audits = config.get_audits() self.assertEqual(7, len(audits))
def test_get_audits_apache_not_installed(self): audits = config.get_audits() self.assertEqual([], audits)