示例#1
0
 def test_get_saved_rules_nilinuxrt(self):
     """
     Test get rules on NILinuxRT system
     """
     data = {
         "/etc/natinst/share/iptables.conf":
         textwrap.dedent("""\
             # Generated by iptables-save v1.6.2 on Thu Oct  8 12:13:44 2020
             *filter
             :INPUT ACCEPT [2958:584773]
             :FORWARD ACCEPT [0:0]
             :OUTPUT ACCEPT [92:23648]
             -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
             COMMIT
             # Completed on Thu Oct  8 12:13:44 2020
             """)
     }
     expected_input_rules = [{
         "protocol": ["tcp"],
         "jump": ["ACCEPT"],
         "match": ["tcp"],
         "destination_port": ["80"],
     }]
     file_mock = mock_open(read_data=data)
     with patch.dict(iptables.__grains__, {
             "os_family": "NILinuxRT",
             "os": "NILinuxRT"
     }):
         with patch.object(iptables.salt.utils.files, "fopen", file_mock):
             rules = iptables.get_saved_rules()
             self.assertEqual(expected_input_rules,
                              rules["filter"]["INPUT"]["rules"])
示例#2
0
 def test_get_saved_rules(self):
     '''
     Test if it return a data structure of the rules in the conf file
     '''
     mock = MagicMock(return_value=False)
     with patch.object(iptables, '_parse_conf', mock):
         self.assertFalse(iptables.get_saved_rules())
         mock.assert_called_with(conf_file=None, family='ipv4')
示例#3
0
 def test_get_saved_rules(self):
     '''
     Test if it return a data structure of the rules in the conf file
     '''
     mock = MagicMock(return_value=False)
     with patch.object(iptables, '_parse_conf', mock):
         self.assertFalse(iptables.get_saved_rules())
         mock.assert_called_with(conf_file=None, family='ipv4')
示例#4
0
 def test_get_saved_rules(self):
     '''
     Test if it return a data structure of the rules in the conf file
     '''
     self.assertFalse(iptables.get_saved_rules())
示例#5
0
 def test_get_saved_rules(self):
     '''
     Test if it return a data structure of the rules in the conf file
     '''
     self.assertFalse(iptables.get_saved_rules())