예제 #1
0
    def test_new_chain_variable(self):
        """
        Test if it create new chain to the specified table.
        """
        mock = MagicMock(return_value="")
        with patch.dict(nftables.__salt__, {"cmd.run": mock}), patch(
            "salt.modules.nftables.check_chain",
            MagicMock(return_value={"result": False, "comment": ""}),
        ), patch(
            "salt.modules.nftables.check_table",
            MagicMock(return_value={"result": True, "comment": ""}),
        ):
            self.assertEqual(
                nftables.new_chain(chain="input", table_type="filter"),
                {
                    "result": False,
                    "comment": "Table_type, hook, and priority required.",
                },
            )

            self.assertTrue(
                nftables.new_chain(
                    chain="input", table_type="filter", hook="input", priority=0
                )
            )
예제 #2
0
    def test_new_chain(self):
        '''
        Test if it create new chain to the specified table.
        '''
        self.assertEqual(nftables.new_chain(), {
            'result': False,
            'comment': 'Chain needs to be specified'
        })

        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.new_chain(chain='input'), ret)

        ret = {
            'result': False,
            'comment':
            'Chain input in table filter in family ipv4 already exists'
        }
        mock = MagicMock(return_value='table ip filter chain input {{')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.new_chain(chain='input'), ret)
예제 #3
0
    def test_new_chain(self):
        """
        Test if it create new chain to the specified table.
        """
        self.assertEqual(
            nftables.new_chain(),
            {
                "result": False,
                "comment": "Chain needs to be specified"
            },
        )

        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.new_chain(chain="input"), ret)

        ret = {
            "result": False,
            "comment":
            "Chain input in table filter in family ipv4 already exists",
        }
        mock = MagicMock(return_value="table ip filter chain input {{")
        with patch.dict(nftables.__salt__, {"cmd.run": mock}):
            self.assertEqual(nftables.new_chain(chain="input"), ret)
예제 #4
0
    def test_new_chain_variable(self):
        '''
        Test if it create new chain to the specified table.
        '''
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.new_chain(chain='input',
                                                table_type='filter'),
                             'Error: table_type hook and priority required')

            self.assertTrue(nftables.new_chain(chain='input',
                                               table_type='filter',
                                               hook='input', priority=0))
예제 #5
0
    def test_new_chain_variable(self):
        '''
        Test if it create new chain to the specified table.
        '''
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.new_chain(chain='input',
                                                table_type='filter'),
                             'Error: table_type hook and priority required')

            self.assertTrue(nftables.new_chain(chain='input',
                                               table_type='filter',
                                               hook='input', priority=0))
예제 #6
0
    def test_new_chain(self):
        '''
        Test if it create new chain to the specified table.
        '''
        self.assertEqual(nftables.new_chain(),
                         'Error: Chain needs to be specified')

        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.new_chain(chain='input'), ret)

        ret = 'Error: chain input in table filter in family ipv4 already exists'
        mock = MagicMock(return_value='table filter chain input {{')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.new_chain(chain='input'), ret)
예제 #7
0
    def test_new_chain(self):
        '''
        Test if it create new chain to the specified table.
        '''
        self.assertEqual(nftables.new_chain(),
                         'Error: Chain needs to be specified')

        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.new_chain(chain='input'), ret)

        ret = 'Error: chain input in table filter in family ipv4 already exists'
        mock = MagicMock(return_value='table ip filter chain input {{')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}):
            self.assertEqual(nftables.new_chain(chain='input'), ret)
예제 #8
0
    def test_new_chain_variable(self):
        '''
        Test if it create new chain to the specified table.
        '''
        mock = MagicMock(return_value='')
        with patch.dict(nftables.__salt__, {'cmd.run': mock}), \
                patch('salt.modules.nftables.check_chain',
                      MagicMock(return_value={'result': False,
                                              'comment': ''})), \
                patch('salt.modules.nftables.check_table',
                      MagicMock(return_value={'result': True,
                                              'comment': ''})):
            self.assertEqual(nftables.new_chain(chain='input',
                                                table_type='filter'),
                             {'result': False,
                              'comment': 'Table_type, hook, and priority required.'})

            self.assertTrue(nftables.new_chain(chain='input',
                                               table_type='filter',
                                               hook='input', priority=0))