diff --git a/secScanner/tests/enhance/euler/check/TestC0303_startFirewalld.py b/secScanner/tests/enhance/euler/check/TestC0303_startFirewalld.py index fc415b6e5c5640a71a99a4d5726b2dbf9fc3acfb..a17f089ba05bde6af617340e56691671d0851600 100644 --- a/secScanner/tests/enhance/euler/check/TestC0303_startFirewalld.py +++ b/secScanner/tests/enhance/euler/check/TestC0303_startFirewalld.py @@ -53,6 +53,25 @@ class TestC0303_startFirewalld(unittest.TestCase): mock_InsertSection.assert_any_call("Check if firewalld is launched") mock_logger.info.assert_any_call("Checking Firewalld is active and iptables&nftables is inactive") mock_display.assert_any_call("- Checking Firewalld is active", "OK") + + @patch('secScanner.enhance.euler.check.C0303_startFirewalld.InsertSection') + @patch('secScanner.enhance.euler.check.C0303_startFirewalld.logger') + @patch('secScanner.enhance.euler.check.C0303_startFirewalld.Display') + @patch('builtins.open', new_callable=mock_open) + @patch('subprocess.getstatusoutput') + def test_firewalld_and_iptables_active(self, mock_getstatusoutput, mock_open, mock_display, mock_logger, mock_InsertSection): + + mock_getstatusoutput.side_effect = [ + (0, "active"), + (0, "active"), + (3, "inactive") + ] + secScanner.enhance.euler.check.C0303_startFirewalld.RESULT_FILE = "result_file_path" # 假设的结果文件路径 + C0303_startFirewalld() + mock_InsertSection.assert_any_call("Check if firewalld is launched") + mock_logger.warning.assert_any_call("WRN_C0303_01: %s", WRN_C0303_01) + mock_logger.warning.assert_any_call("SUG_C0303_01: %s", SUG_C0303_01) + mock_display.assert_any_call("- Checking Firewalld is active, iptables or nftables actice too...", "WARNING") if __name__ == '__main__': unittest.main() \ No newline at end of file