qvm_firewall.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #
  2. # The Qubes OS Project, http://www.qubes-os.org
  3. #
  4. # Copyright (C) 2016 Marek Marczykowski-Górecki
  5. # <marmarek@invisiblethingslab.com>
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. import argparse
  22. import qubes.firewall
  23. import qubes.tests
  24. import qubes.tests.firewall
  25. import qubes.tools.qvm_firewall
  26. class TC_00_RuleAction(qubes.tests.QubesTestCase):
  27. def setUp(self):
  28. super(TC_00_RuleAction, self).setUp()
  29. self.action = qubes.tools.qvm_firewall.RuleAction(None, dest='rule')
  30. def test_000_named_opts(self):
  31. ns = argparse.Namespace()
  32. self.action(None, ns, ['dsthost=127.0.0.1', 'action=accept'])
  33. self.assertEqual(ns.rule,
  34. qubes.firewall.Rule(None, action='accept', dsthost='127.0.0.1/32'))
  35. def test_001_unnamed_opts(self):
  36. ns = argparse.Namespace()
  37. self.action(None, ns, ['accept', '127.0.0.1', 'tcp', '80'])
  38. self.assertEqual(ns.rule,
  39. qubes.firewall.Rule(None, action='accept', dsthost='127.0.0.1/32',
  40. proto='tcp', dstports=80))
  41. def test_002_unnamed_opts(self):
  42. ns = argparse.Namespace()
  43. self.action(None, ns, ['accept', '127.0.0.1', 'icmp', '8'])
  44. self.assertEqual(ns.rule,
  45. qubes.firewall.Rule(None, action='accept', dsthost='127.0.0.1/32',
  46. proto='icmp', icmptype=8))
  47. def test_003_mixed_opts(self):
  48. ns = argparse.Namespace()
  49. self.action(None, ns, ['dsthost=127.0.0.1', 'accept',
  50. 'dstports=443', 'tcp'])
  51. self.assertEqual(ns.rule,
  52. qubes.firewall.Rule(None, action='accept', dsthost='127.0.0.1/32',
  53. proto='tcp', dstports=443))