Fix tests about images paths security

This commit is contained in:
Julien Duponchelle committed 2015-11-10 15:21:10 +01:00
1 parent 390c88d7cd
commit caade47e16
5 files changed
+33 -31

No files matched your search

+18 -16
View File
@@ -58,7 +58,7 @@ def vm(project, manager, tmpdir, fake_iou_bin, iourc_file):
config["iourc_path"] = iourc_file
manager.config.set_section_config("IOU", config)
vm.path = fake_iou_bin
vm.path = "iou.bin"
return vm
@@ -101,7 +101,7 @@ def test_vm_startup_config_content(project, manager):
def test_vm_invalid_iouyap_path(project, manager, loop, fake_iou_bin):
with pytest.raises(IOUError):
vm = IOUVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0e", project, manager)
vm.path = fake_iou_bin
vm.path = "iou.bin"
loop.run_until_complete(asyncio.async(vm.start()))
@@ -207,9 +207,9 @@ def test_close(vm, port_manager, loop):
def test_path(vm, fake_iou_bin):
vm.path = fake_iou_bin
assert vm.path == fake_iou_bin
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
vm.path = fake_iou_bin
assert vm.path == fake_iou_bin
def test_path_12_location(vm, fake_iou_bin):
@@ -217,8 +217,9 @@ def test_path_12_location(vm, fake_iou_bin):
# In 1.2 users uploaded images to the images roots
# after the migration their images are inside images/IOU
# but old topologies use old path
vm.path = fake_iou_bin.replace("/IOU", "")
assert vm.path == fake_iou_bin
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
vm.path = fake_iou_bin.replace("/IOU", "")
assert vm.path == fake_iou_bin
def test_path_relative(vm, fake_iou_bin, tmpdir):
@@ -231,17 +232,18 @@ def test_path_relative(vm, fake_iou_bin, tmpdir):
def test_path_invalid_bin(vm, tmpdir):
path = str(tmpdir / "test.bin")
with pytest.raises(IOUError):
vm.path = path
vm._check_requirements()
with patch("gns3server.config.Config.get_section_config", return_value={"local": True}):
path = str(tmpdir / "test.bin")
with pytest.raises(IOUError):
vm.path = path
vm._check_requirements()
with open(path, "w+") as f:
f.write("BUG")
with open(path, "w+") as f:
f.write("BUG")
with pytest.raises(IOUError):
vm.path = path
vm._check_requirements()
with pytest.raises(IOUError):
vm.path = path
vm._check_requirements()
def test_create_netmap_config(vm):
+8 -8
View File
@@ -387,8 +387,8 @@ def test_hda_disk_image(vm, tmpdir):
vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hda_disk_image = "/tmp/test"
assert vm.hda_disk_image == "/tmp/test"
vm.hda_disk_image = str(tmpdir / "test")
assert vm.hda_disk_image == str(tmpdir / "test")
vm.hda_disk_image = "test"
assert vm.hda_disk_image == str(tmpdir / "QEMU" / "test")
@@ -405,8 +405,8 @@ def test_hdb_disk_image(vm, tmpdir):
vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hdb_disk_image = "/tmp/test"
assert vm.hdb_disk_image == "/tmp/test"
vm.hdb_disk_image = str(tmpdir / "test")
assert vm.hdb_disk_image == str(tmpdir / "test")
vm.hdb_disk_image = "test"
assert vm.hdb_disk_image == str(tmpdir / "QEMU" / "test")
@@ -415,8 +415,8 @@ def test_hdc_disk_image(vm, tmpdir):
vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hdc_disk_image = "/tmp/test"
assert vm.hdc_disk_image == "/tmp/test"
vm.hdc_disk_image = str(tmpdir / "test")
assert vm.hdc_disk_image == str(tmpdir / "test")
vm.hdc_disk_image = "test"
assert vm.hdc_disk_image == str(tmpdir / "QEMU" / "test")
@@ -425,8 +425,8 @@ def test_hdd_disk_image(vm, tmpdir):
vm.manager.config.set("Server", "images_path", str(tmpdir))
vm.hdd_disk_image = "/tmp/test"
assert vm.hdd_disk_image == "/tmp/test"
vm.hdd_disk_image = str(tmpdir / "test")
assert vm.hdd_disk_image == str(tmpdir / "test")
vm.hdd_disk_image = "test"
assert vm.hdd_disk_image == str(tmpdir / "QEMU" / "test")