Example #1
0
    def test_check(self):
        '''
        Test if it check for the existence of a rule in the table and chain
        '''
        self.assertEqual(nftables.check(),
                         'Error: Chain needs to be specified')

        self.assertEqual(nftables.check(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.check(chain='input', rule=_ru), ret)

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

        mock = MagicMock(return_value='table ip filter chain input {{')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertFalse(nftables.check(chain='input', rule=_ru))

        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.check(chain='input', rule=_ru))
Example #2
0
    def test_check(self):
        '''
        Test if it check for the existence of a rule in the table and chain
        '''
        self.assertEqual(nftables.check(),
                         'Error: Chain needs to be specified')

        self.assertEqual(nftables.check(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.check(chain='input', rule=_ru), ret)

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

        mock = MagicMock(return_value='table ip filter chain input {{')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertFalse(nftables.check(chain='input', rule=_ru))

        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.check(chain='input', rule=_ru))
Example #3
0
    def test_check(self):
        """
        Test if it check for the existence of a rule in the table and chain
        """
        self.assertEqual(
            nftables.check(),
            {
                "result": False,
                "comment": "Chain needs to be specified"
            },
        )

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

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

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

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

        r_val = "table ip filter chain input {{ input tcp dport 22 log accept #"
        mock = MagicMock(return_value=r_val)
        ret = {
            "result":
            True,
            "comment":
            "Rule tcp dport 22 log accept in chain input in table filter in family ipv4 exists",
        }
        with patch.dict(nftables.__salt__, {"cmd.run": mock}):
            self.assertEqual(nftables.check(chain="input", rule=_ru), ret)
Example #4
0
    def test_check(self):
        '''
        Test if it check for the existence of a rule in the table and chain
        '''
        self.assertEqual(nftables.check(), {
            'result': False,
            'comment': 'Chain needs to be specified'
        })

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

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

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

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

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