コード例 #1
0
ファイル: test_nftables.py プロジェクト: wicked-wei/salt
    def test_build_rule(self):
        '''
        Test if it build a well-formatted nftables rule based on kwargs.
        '''
        self.assertEqual(nftables.build_rule(full='True'), {
            'result': False,
            'rule': '',
            'comment': 'Table needs to be specified'
        })

        self.assertEqual(nftables.build_rule(table='filter', full='True'), {
            'result': False,
            'rule': '',
            'comment': 'Chain needs to be specified'
        })

        self.assertEqual(
            nftables.build_rule(table='filter', chain='input', full='True'), {
                'result': False,
                'rule': '',
                'comment': 'Command needs to be specified'
            })

        self.assertEqual(
            nftables.build_rule(table='filter',
                                chain='input',
                                command='insert',
                                position='3',
                                full='True'),
            {
                'result': True,
                'rule': 'nft insert rule ip filter input position 3 ',
                'comment': 'Successfully built rule'
            })

        self.assertEqual(
            nftables.build_rule(table='filter',
                                chain='input',
                                command='insert',
                                full='True'), {
                                    'result': True,
                                    'rule': 'nft insert rule ip filter input ',
                                    'comment': 'Successfully built rule'
                                })

        self.assertEqual(
            nftables.build_rule(table='filter',
                                chain='input',
                                command='halt',
                                full='True'), {
                                    'result': True,
                                    'rule': 'nft halt rule ip filter input ',
                                    'comment': 'Successfully built rule'
                                })

        self.assertEqual(nftables.build_rule(), {
            'result': True,
            'rule': '',
            'comment': ''
        })
コード例 #2
0
ファイル: nftables_test.py プロジェクト: bryson/salt
    def test_build_rule(self):
        '''
        Test if it build a well-formatted nftables rule based on kwargs.
        '''
        self.assertEqual(nftables.build_rule(full='True'),
                         'Error: Table needs to be specified')

        self.assertEqual(nftables.build_rule(table='filter', full='True'),
                         'Error: Chain needs to be specified')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             full='True'),
                         'Error: Command needs to be specified')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             command='insert', position='3',
                                             full='True'),
                         'nft insert rule ip filter input position 3 ')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             command='insert', full='True'),
                         'nft insert rule ip filter input ')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             command='halt', full='True'),
                         'nft halt rule ip filter input ')

        self.assertEqual(nftables.build_rule(), '')
コード例 #3
0
    def test_build_rule(self):
        '''
        Test if it build a well-formatted nftables rule based on kwargs.
        '''
        self.assertEqual(nftables.build_rule(full='True'),
                         'Error: Table needs to be specified')

        self.assertEqual(nftables.build_rule(table='filter', full='True'),
                         'Error: Chain needs to be specified')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             full='True'),
                         'Error: Command needs to be specified')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             command='insert', position='3',
                                             full='True'),
                         'nft insert rule ip filter input position 3 ')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             command='insert', full='True'),
                         'nft insert rule ip filter input ')

        self.assertEqual(nftables.build_rule(table='filter', chain='input',
                                             command='halt', full='True'),
                         'nft halt rule ip filter input ')

        self.assertEqual(nftables.build_rule(), '')
コード例 #4
0
ファイル: test_nftables.py プロジェクト: steverweber/salt
    def test_build_rule(self):
        """
        Test if it build a well-formatted nftables rule based on kwargs.
        """
        self.assertEqual(
            nftables.build_rule(full="True"),
            {"result": False, "rule": "", "comment": "Table needs to be specified"},
        )

        self.assertEqual(
            nftables.build_rule(table="filter", full="True"),
            {"result": False, "rule": "", "comment": "Chain needs to be specified"},
        )

        self.assertEqual(
            nftables.build_rule(table="filter", chain="input", full="True"),
            {"result": False, "rule": "", "comment": "Command needs to be specified"},
        )

        self.assertEqual(
            nftables.build_rule(
                table="filter",
                chain="input",
                command="insert",
                position="3",
                full="True",
            ),
            {
                "result": True,
                "rule": "nft insert rule ip filter input position 3 ",
                "comment": "Successfully built rule",
            },
        )

        self.assertEqual(
            nftables.build_rule(
                table="filter", chain="input", command="insert", full="True"
            ),
            {
                "result": True,
                "rule": "nft insert rule ip filter input ",
                "comment": "Successfully built rule",
            },
        )

        self.assertEqual(
            nftables.build_rule(
                table="filter", chain="input", command="halt", full="True"
            ),
            {
                "result": True,
                "rule": "nft halt rule ip filter input ",
                "comment": "Successfully built rule",
            },
        )

        self.assertEqual(
            nftables.build_rule(
                table="filter",
                chain="input",
                command="insert",
                position="3",
                full="True",
                connstate="related,established",
                saddr="10.0.0.1",
                daddr="10.0.0.2",
                jump="accept",
            ),
            {
                "result": True,
                "rule": "nft insert rule ip filter input position 3 ct state { related,established } ip saddr 10.0.0.1 ip daddr 10.0.0.2 accept",
                "comment": "Successfully built rule",
            },
        )

        self.assertEqual(
            nftables.build_rule(), {"result": True, "rule": "", "comment": ""}
        )
コード例 #5
0
    def test_build_rule(self):
        """
        Test if it build a well-formatted nftables rule based on kwargs.
        """
        self.assertEqual(
            nftables.build_rule(full="True"),
            {
                "result": False,
                "rule": "",
                "comment": "Table needs to be specified"
            },
        )

        self.assertEqual(
            nftables.build_rule(table="filter", full="True"),
            {
                "result": False,
                "rule": "",
                "comment": "Chain needs to be specified"
            },
        )

        self.assertEqual(
            nftables.build_rule(table="filter", chain="input", full="True"),
            {
                "result": False,
                "rule": "",
                "comment": "Command needs to be specified"
            },
        )

        self.assertEqual(
            nftables.build_rule(
                table="filter",
                chain="input",
                command="insert",
                position="3",
                full="True",
            ),
            {
                "result": True,
                "rule": "nft insert rule ip filter input position 3 ",
                "comment": "Successfully built rule",
            },
        )

        self.assertEqual(
            nftables.build_rule(table="filter",
                                chain="input",
                                command="insert",
                                full="True"),
            {
                "result": True,
                "rule": "nft insert rule ip filter input ",
                "comment": "Successfully built rule",
            },
        )

        self.assertEqual(
            nftables.build_rule(table="filter",
                                chain="input",
                                command="halt",
                                full="True"),
            {
                "result": True,
                "rule": "nft halt rule ip filter input ",
                "comment": "Successfully built rule",
            },
        )

        self.assertEqual(nftables.build_rule(), {
            "result": True,
            "rule": "",
            "comment": ""
        })