net.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # pylint: disable=protected-access
  2. #
  3. # The Qubes OS Project, https://www.qubes-os.org/
  4. #
  5. # Copyright (C) 2014-2016 Joanna Rutkowska <joanna@invisiblethingslab.com>
  6. # Copyright (C) 2014-2016 Wojtek Porczyk <woju@invisiblethingslab.com>
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2 of the License, or
  11. # (at your option) any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License along
  19. # with this program; if not, write to the Free Software Foundation, Inc.,
  20. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. #
  22. import unittest
  23. import qubes
  24. import qubes.vm.qubesvm
  25. import qubes.tests
  26. import qubes.tests.vm.qubesvm
  27. class TC_00_NetVMMixin(
  28. qubes.tests.vm.qubesvm.QubesVMTestsMixin, qubes.tests.QubesTestCase):
  29. def setUp(self):
  30. super(TC_00_NetVMMixin, self).setUp()
  31. self.app = qubes.tests.vm.TestApp()
  32. self.app.vmm.offline_mode = True
  33. def setup_netvms(self, vm):
  34. # usage of QubesVM here means that those tests should be after
  35. # testing properties used here
  36. self.netvm1 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=2,
  37. name=qubes.tests.VMPREFIX + 'netvm1',
  38. provides_network=True)
  39. self.netvm2 = qubes.vm.qubesvm.QubesVM(self.app, None, qid=3,
  40. name=qubes.tests.VMPREFIX + 'netvm2',
  41. provides_network=True)
  42. self.nonetvm = qubes.vm.qubesvm.QubesVM(self.app, None, qid=4,
  43. name=qubes.tests.VMPREFIX + 'nonet')
  44. self.app.domains = qubes.app.VMCollection(self.app)
  45. for domain in (vm, self.netvm1, self.netvm2, self.nonetvm):
  46. self.app.domains._dict[domain.qid] = domain
  47. self.app.default_netvm = self.netvm1
  48. self.app.default_fw_netvm = self.netvm1
  49. @qubes.tests.skipUnlessDom0
  50. def test_140_netvm(self):
  51. vm = self.get_vm()
  52. self.setup_netvms(vm)
  53. self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
  54. self.assertPropertyValue(vm, 'netvm', self.netvm2, self.netvm2,
  55. self.netvm2.name)
  56. del vm.netvm
  57. self.assertPropertyDefaultValue(vm, 'netvm', self.app.default_netvm)
  58. self.assertPropertyValue(vm, 'netvm', self.netvm2.name, self.netvm2,
  59. self.netvm2.name)
  60. self.assertPropertyValue(vm, 'netvm', None, None, '')
  61. def test_141_netvm_invalid(self):
  62. vm = self.get_vm()
  63. self.setup_netvms(vm)
  64. self.assertPropertyInvalidValue(vm, 'netvm', 'invalid')
  65. self.assertPropertyInvalidValue(vm, 'netvm', 123)
  66. def test_142_netvm_netvm(self):
  67. vm = self.get_vm()
  68. self.setup_netvms(vm)
  69. self.assertPropertyInvalidValue(vm, 'netvm', self.nonetvm)
  70. def test_143_netvm_loopback(self):
  71. vm = self.get_vm()
  72. self.app.domains = {1: vm, vm: vm}
  73. self.assertPropertyInvalidValue(vm, 'netvm', vm)
  74. def test_150_ip(self):
  75. vm = self.get_vm()
  76. self.setup_netvms(vm)
  77. self.assertPropertyDefaultValue(vm, 'ip', '10.137.0.' + str(vm.qid))
  78. vm.ip = '192.168.1.1'
  79. self.assertEqual(vm.ip, '192.168.1.1')
  80. def test_151_ip_invalid(self):
  81. vm = self.get_vm()
  82. self.setup_netvms(vm)
  83. self.assertPropertyInvalidValue(vm, 'ip', 'abcd')
  84. self.assertPropertyInvalidValue(vm, 'ip', 'a.b.c.d')
  85. self.assertPropertyInvalidValue(vm, 'ip', '1111.2222.3333.4444')
  86. # TODO: implement and add here: 0.0.0.0, 333.333.333.333