diff --git a/insights/specs/datasources/httpd.py b/insights/specs/datasources/httpd.py index 1c8adde76d..7192cad9e5 100644 --- a/insights/specs/datasources/httpd.py +++ b/insights/specs/datasources/httpd.py @@ -71,8 +71,14 @@ def _get_all_include_conf(root, glob_path): _paths.add(conf) with open(conf) as cfp: _includes = None + section_number = 0 for line in cfp.readlines(): - if line.strip().startswith("Include"): + line = line.strip() + if line.startswith(" + # ModSecurity Core Rules Set and Local configuration + IncludeOptional modsecurity.d/*.conf + +""".strip() + +data_lines_httpd_conf_section_test = """ +ServerRoot "/etc/httpd" + + # ModSecurity Core Rules Set and Local configuration + IncludeOptional modsecurity.d/*.conf + +""".strip() + +data_lines_crs_setup_conf = """ +SecAction \ + "id:900990,\ """.strip() @@ -103,6 +148,39 @@ def test_httpd_conf_files(m_open, m_glob, m_isdir, m_isfile): assert result == set(['/etc/httpd/conf.d/ssl.conf', '/etc/httpd/conf/httpd.conf']) +@patch("os.path.isfile", return_value=True) +@patch("os.path.isdir", return_value=True) +@patch("glob.glob", return_value=["/etc/httpd/modsecurity.d/crs-setup.conf"]) +@patch(builtin_open, new_callable=mock_open, read_data=data_lines_httpd_conf_section_test) +def test_httpd_conf_files_section(m_open, m_glob, m_isdir, m_isfile): + handlers = (m_open.return_value, mock_open(read_data=data_lines_crs_setup_conf).return_value) + m_open.side_effect = handlers + broker = {HostContext: None} + result = httpd_configuration_files(broker) + assert result == set(['/etc/httpd/conf/httpd.conf']) + + +@patch("os.path.isfile", return_value=False) +@patch("os.path.isdir", return_value=False) +@patch("glob.glob", return_value=["/etc/httpd/conf.d/ssl.conf"]) +@patch(builtin_open, new_callable=mock_open, read_data=data_lines_httpd_conf) +def test_httpd_conf_files_ssl_miss(m_open, m_glob, m_isdir, m_isfile): + handlers = (m_open.return_value, mock_open(read_data=data_lines_ssl_conf).return_value) + m_open.side_effect = handlers + broker = {HostContext: None} + result = httpd_configuration_files(broker) + assert result == set(['/etc/httpd/conf/httpd.conf']) + + +@patch("os.path.isfile", return_value=True) +@patch("os.path.isdir", return_value=True) +@patch("glob.glob", return_value=["/etc/httpd/conf.d/ssl.conf"]) +def test_httpd_conf_files_main_miss(m_glob, m_isdir, m_isfile): + broker = {HostContext: None} + with pytest.raises(SkipComponent): + httpd_configuration_files(broker) + + @patch("os.path.isfile", return_value=True) @patch("os.path.isdir", return_value=True) @patch("glob.glob", return_value=["/opt/rh/httpd24/root/etc/httpd/conf.d/ssl.conf"])