mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-15 12:59:06 +00:00
parent
b2d8a8d810
commit
4cd5ec5613
@ -73,6 +73,8 @@ class VirtualBox(BaseManager):
|
|||||||
raise VirtualBoxError("VBoxManage {} is not accessible".format(vboxmanage_path))
|
raise VirtualBoxError("VBoxManage {} is not accessible".format(vboxmanage_path))
|
||||||
if not os.access(vboxmanage_path, os.X_OK):
|
if not os.access(vboxmanage_path, os.X_OK):
|
||||||
raise VirtualBoxError("VBoxManage is not executable")
|
raise VirtualBoxError("VBoxManage is not executable")
|
||||||
|
if os.path.basename(vboxmanage_path) not in ["VBoxManage", "VBoxManage.exe", "vboxmanage"]:
|
||||||
|
raise VirtualBoxError("Invalid VBoxManage executable name {}".format(os.path.basename(vboxmanage_path)))
|
||||||
|
|
||||||
self._vboxmanage_path = vboxmanage_path
|
self._vboxmanage_path = vboxmanage_path
|
||||||
return vboxmanage_path
|
return vboxmanage_path
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import os
|
||||||
|
import stat
|
||||||
|
|
||||||
from gns3server.modules.virtualbox import VirtualBox
|
from gns3server.modules.virtualbox import VirtualBox
|
||||||
from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError
|
from gns3server.modules.virtualbox.virtualbox_error import VirtualBoxError
|
||||||
@ -36,9 +38,28 @@ def test_vm_invalid_vboxmanage_path(manager):
|
|||||||
with pytest.raises(VirtualBoxError):
|
with pytest.raises(VirtualBoxError):
|
||||||
manager.find_vboxmanage()
|
manager.find_vboxmanage()
|
||||||
|
|
||||||
|
|
||||||
def test_vm_non_executable_vboxmanage_path(manager):
|
def test_vm_non_executable_vboxmanage_path(manager):
|
||||||
tmpfile = tempfile.NamedTemporaryFile()
|
tmpfile = tempfile.NamedTemporaryFile()
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": tmpfile.name}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": tmpfile.name}):
|
||||||
with pytest.raises(VirtualBoxError):
|
with pytest.raises(VirtualBoxError):
|
||||||
manager.find_vboxmanage()
|
manager.find_vboxmanage()
|
||||||
|
|
||||||
|
def test_vm_invalid_executable_name_vboxmanage_path(manager, tmpdir):
|
||||||
|
path = str(tmpdir / "vpcs")
|
||||||
|
with open(path, "w+") as f:
|
||||||
|
f.write(path)
|
||||||
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
|
tmpfile = tempfile.NamedTemporaryFile()
|
||||||
|
with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": path}):
|
||||||
|
with pytest.raises(VirtualBoxError):
|
||||||
|
manager.find_vboxmanage()
|
||||||
|
|
||||||
|
def test_vboxmanage_path(manager, tmpdir):
|
||||||
|
path = str(tmpdir / "VBoxManage")
|
||||||
|
with open(path, "w+") as f:
|
||||||
|
f.write(path)
|
||||||
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
|
||||||
|
tmpfile = tempfile.NamedTemporaryFile()
|
||||||
|
with patch("gns3server.config.Config.get_section_config", return_value={"vboxmanage_path": path}):
|
||||||
|
assert manager.find_vboxmanage() == path
|
||||||
|
|
||||||
|
@ -54,3 +54,4 @@ def test_vm_invalid_virtualbox_api_version(loop, project, manager):
|
|||||||
with pytest.raises(VirtualBoxError):
|
with pytest.raises(VirtualBoxError):
|
||||||
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
vm = VirtualBoxVM("test", "00010203-0405-0607-0809-0a0b0c0d0e0f", project, manager, "test", False)
|
||||||
loop.run_until_complete(asyncio.async(vm.create()))
|
loop.run_until_complete(asyncio.async(vm.create()))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user