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': '' })
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(), '')
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": ""} )
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": "" })