def test_delete_rule(self): """ Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule's position in the chain. """ mock = MagicMock(side_effect=["1", ""]) with patch.dict(nftables.__salt__, {"cmd.run": mock}), patch( "salt.modules.nftables.check", MagicMock(return_value={"result": True, "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 = { "result": False, "comment": 'Failed to delete rule "None" in chain input table filter in family ipv4', } self.assertEqual( nftables.delete(table="filter", chain="input", position="3"), _expected ) _expected = { "result": True, "comment": 'Deleted rule "None" in chain input in table filter in family ipv4.', } self.assertEqual( nftables.delete(table="filter", chain="input", position="3"), _expected )
def test_delete(self): ''' Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule's position in the chain. ''' _ru = 'input tcp dport 22 log accept' self.assertEqual( nftables.delete(table='filter', chain='input', position='3', rule=_ru), 'Error: Only specify a position or a rule, not both') 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.delete(table='filter', 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.delete(table='filter', chain='input', rule=_ru), ret) mock = MagicMock(return_value='table ip filter chain input {{') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertTrue( nftables.delete(table='filter', chain='input', rule=_ru))
def test_delete(self): """ Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule's position in the chain. """ _ru = "input tcp dport 22 log accept" ret = { "result": False, "comment": "Only specify a position or a rule, not both", } self.assertEqual( nftables.delete(table="filter", chain="input", position="3", rule=_ru), ret ) 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.delete(table="filter", chain="input", rule=_ru), ret ) ret = { "result": False, "comment": "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.delete(table="filter", chain="input", rule=_ru), ret ) mock = MagicMock(return_value="table ip filter chain input {{") with patch.dict(nftables.__salt__, {"cmd.run": mock}): self.assertTrue(nftables.delete(table="filter", chain="input", rule=_ru))
def test_delete_rule(self): ''' Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule's position in the chain. ''' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}), \ patch('salt.modules.nftables.check', MagicMock(return_value={'result': True, '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 = { 'result': False, 'comment': 'Failed to delete rule "None" in chain input table filter in family ipv4' } self.assertEqual( nftables.delete(table='filter', chain='input', position='3'), _expected) _expected = { 'result': True, 'comment': 'Deleted rule "None" in chain input in table filter in family ipv4.' } self.assertEqual( nftables.delete(table='filter', chain='input', position='3'), _expected)
def test_delete(self): ''' Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule's position in the chain. ''' _ru = 'input tcp dport 22 log accept' self.assertEqual(nftables.delete(table='filter', chain='input', position='3', rule=_ru), 'Error: Only specify a position or a rule, not both') 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.delete(table='filter', 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.delete(table='filter', chain='input', rule=_ru), ret) mock = MagicMock(return_value='table ip filter chain input {{') with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertTrue(nftables.delete(table='filter', chain='input', rule=_ru))
def test_delete_rule(self): ''' Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule's position in the chain. ''' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertFalse( nftables.delete(table='filter', chain='input', position='3')) self.assertTrue( nftables.delete(table='filter', chain='input', position='3'))
def test_delete_rule(self): ''' Test if it delete a rule from the specified table & chain, specifying either the rule in its entirety, or the rule's position in the chain. ''' mock = MagicMock(side_effect=['1', '']) with patch.dict(nftables.__salt__, {'cmd.run': mock}): self.assertFalse(nftables.delete(table='filter', chain='input', position='3')) self.assertTrue(nftables.delete(table='filter', chain='input', position='3'))