예제 #1
0
    def test_append(self):
        '''
        Test if it append a rule to the specified table & chain.
        '''
        self.assertEqual(nftables.append(),
                         'Error: Chain needs to be specified')

        self.assertEqual(nftables.append(chain='input'),
                         'Error: Rule needs to be specified')

        _ru = 'input tcp dport 22 log accept'
        ret = 'Error: table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.append(chain='input', rule=_ru), ret)

        ret = 'Error: chain input in table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='table ip filter')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.append(chain='input', rule=_ru), ret)

        r_val = 'table ip filter chain input {{ input tcp dport 22 log accept #'
        mock = MagicMock(return_value=r_val)
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertTrue(nftables.append(chain='input', rule=_ru))
예제 #2
0
 def test_append_rule(self):
     '''
     Test if it append a rule to the specified table & chain.
     '''
     _ru = 'input tcp dport 22 log accept'
     mock = MagicMock(side_effect=['1', ''])
     with patch.dict(nftables.__salt__, {'cmd.run': mock}), \
             patch('salt.modules.nftables.check',
                   MagicMock(return_value={'result': False,
                                           'comment': ''})), \
             patch('salt.modules.nftables.check_chain',
                   MagicMock(return_value={'result': True,
                                           'comment': ''})), \
             patch('salt.modules.nftables.check_table',
                   MagicMock(return_value={'result': True,
                                           'comment': ''})):
         _expected = {
             'comment':
             'Failed to add rule "{0}" chain input in table filter in family ipv4.'
             .format(_ru),
             'result':
             False
         }
         self.assertEqual(nftables.append(chain='input', rule=_ru),
                          _expected)
         _expected = {
             'comment':
             'Added rule "{0}" chain input in table filter in family ipv4.'.
             format(_ru),
             'result':
             True
         }
         self.assertEqual(nftables.append(chain='input', rule=_ru),
                          _expected)
예제 #3
0
 def test_append_rule(self):
     """
     Test if it append a rule to the specified table & chain.
     """
     _ru = "input tcp dport 22 log accept"
     mock = MagicMock(side_effect=["1", ""])
     with patch.dict(nftables.__salt__, {"cmd.run": mock}), patch(
         "salt.modules.nftables.check",
         MagicMock(return_value={"result": False, "comment": ""}),
     ), patch(
         "salt.modules.nftables.check_chain",
         MagicMock(return_value={"result": True, "comment": ""}),
     ), patch(
         "salt.modules.nftables.check_table",
         MagicMock(return_value={"result": True, "comment": ""}),
     ):
         _expected = {
             "comment": 'Failed to add rule "{}" chain input in table filter in family ipv4.'.format(
                 _ru
             ),
             "result": False,
         }
         self.assertEqual(nftables.append(chain="input", rule=_ru), _expected)
         _expected = {
             "comment": 'Added rule "{}" chain input in table filter in family ipv4.'.format(
                 _ru
             ),
             "result": True,
         }
         self.assertEqual(nftables.append(chain="input", rule=_ru), _expected)
예제 #4
0
    def test_append(self):
        '''
        Test if it append a rule to the specified table & chain.
        '''
        self.assertEqual(nftables.append(),
                         'Error: Chain needs to be specified')

        self.assertEqual(nftables.append(chain='input'),
                         'Error: Rule needs to be specified')

        _ru = 'input tcp dport 22 log accept'
        ret = 'Error: table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.append(chain='input', rule=_ru), ret)

        ret = 'Error: chain input in table filter in family ipv4 does not exist'
        mock = MagicMock(return_value='table ip filter')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.append(chain='input', rule=_ru), ret)

        r_val = 'table ip filter chain input {{ input tcp dport 22 log accept #'
        mock = MagicMock(return_value=r_val)
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertTrue(nftables.append(chain='input', rule=_ru))
예제 #5
0
    def test_append(self):
        '''
        Test if it append a rule to the specified table & chain.
        '''
        self.assertEqual(nftables.append(),
                         {'result': False,
                          'comment': 'Chain needs to be specified'})

        self.assertEqual(nftables.append(chain='input'),
                         {'result': False,
                          'comment': 'Rule needs to be specified'})

        _ru = 'input tcp dport 22 log accept'
        ret = {'comment': 'Table filter in family ipv4 does not exist',
               'result': False}
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.append(chain='input', rule=_ru), ret)

        ret = {'comment': 'Chain input in table filter in family ipv4 does not exist',
               'result': False}
        mock = MagicMock(return_value='table ip filter')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.append(chain='input', rule=_ru), ret)

        r_val = 'table ip filter chain input {{ input tcp dport 22 log accept #'
        mock = MagicMock(return_value=r_val)
        _expected = {'comment': 'Rule input tcp dport 22 log accept chain input in table filter in family ipv4 already exists',
                     'result': False}
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.append(chain='input',
                                             rule=_ru),
                             _expected)
예제 #6
0
 def test_append_rule(self):
     '''
     Test if it append a rule to the specified table & chain.
     '''
     _ru = 'input tcp dport 22 log accept'
     mock = MagicMock(side_effect=['1', ''])
     with patch.dict(nftables.__salt__, {'cmd.run': mock}):
         self.assertFalse(nftables.append(chain='input', rule=_ru))
         self.assertTrue(nftables.append(chain='input', rule=_ru))
예제 #7
0
 def test_append_rule(self):
     '''
     Test if it append a rule to the specified table & chain.
     '''
     _ru = 'input tcp dport 22 log accept'
     mock = MagicMock(side_effect=['1', ''])
     with patch.dict(nftables.__salt__, {'cmd.run': mock}):
         self.assertFalse(nftables.append(chain='input', rule=_ru))
         self.assertTrue(nftables.append(chain='input', rule=_ru))
예제 #8
0
 def test_append_rule(self):
     '''
     Test if it append a rule to the specified table & chain.
     '''
     _ru = 'input tcp dport 22 log accept'
     mock = MagicMock(side_effect=['1', ''])
     with patch.dict(nftables.__salt__, {'cmd.run': mock}), \
             patch('salt.modules.nftables.check', MagicMock(return_value=False)), \
             patch('salt.modules.nftables.check_chain', MagicMock(return_value=True)), \
             patch('salt.modules.nftables.check_table', MagicMock(return_value=True)):
         self.assertFalse(nftables.append(chain='input', rule=_ru))
         self.assertTrue(nftables.append(chain='input', rule=_ru))
예제 #9
0
    def test_append(self):
        """
        Test if it append a rule to the specified table & chain.
        """
        self.assertEqual(
            nftables.append(),
            {
                "result": False,
                "comment": "Chain needs to be specified"
            },
        )

        self.assertEqual(
            nftables.append(chain="input"),
            {
                "result": False,
                "comment": "Rule needs to be specified"
            },
        )

        _ru = "input tcp dport 22 log accept"
        ret = {
            "comment": "Table filter in family ipv4 does not exist",
            "result": False
        }
        mock = MagicMock(return_value="")
        with patch.dict(nftables.__salt__, {"cmd.run": mock}):
            self.assertEqual(nftables.append(chain="input", rule=_ru), ret)

        ret = {
            "comment":
            "Chain input in table filter in family ipv4 does not exist",
            "result": False,
        }
        mock = MagicMock(return_value="table ip filter")
        with patch.dict(nftables.__salt__, {"cmd.run": mock}):
            self.assertEqual(nftables.append(chain="input", rule=_ru), ret)

        r_val = "table ip filter chain input {{ input tcp dport 22 log accept #"
        mock = MagicMock(return_value=r_val)
        _expected = {
            "comment":
            "Rule input tcp dport 22 log accept chain input in table filter in family ipv4 already exists",
            "result": False,
        }
        with patch.dict(nftables.__salt__, {"cmd.run": mock}):
            self.assertEqual(nftables.append(chain="input", rule=_ru),
                             _expected)