mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-18 23:43:48 +02:00
Raise error if server received windows path
This commit is contained in:
parent
58e7fa2f01
commit
5b347fe48f
@ -23,6 +23,7 @@ import asyncio
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import socket
|
import socket
|
||||||
import shutil
|
import shutil
|
||||||
|
import re
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -401,7 +402,14 @@ class BaseManager:
|
|||||||
|
|
||||||
if not path:
|
if not path:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
img_directory = self.get_images_directory()
|
img_directory = self.get_images_directory()
|
||||||
|
|
||||||
|
# Windows path should not be send to a unix server
|
||||||
|
if not sys.platform.startswith("win"):
|
||||||
|
if re.match(r"^[A-Z]:", path) is not None:
|
||||||
|
raise VMError("{} is not allowed on this remote server. Please use only a filename in {}.".format(path, img_directory))
|
||||||
|
|
||||||
if not os.path.isabs(path):
|
if not os.path.isabs(path):
|
||||||
s = os.path.split(path)
|
s = os.path.split(path)
|
||||||
path = os.path.normpath(os.path.join(img_directory, *s))
|
path = os.path.normpath(os.path.join(img_directory, *s))
|
||||||
|
@ -117,8 +117,8 @@ def test_get_abs_image_path_non_local(qemu, tmpdir):
|
|||||||
assert qemu.get_abs_image_path(path1) == path1
|
assert qemu.get_abs_image_path(path1) == path1
|
||||||
with pytest.raises(VMError):
|
with pytest.raises(VMError):
|
||||||
qemu.get_abs_image_path(path2)
|
qemu.get_abs_image_path(path2)
|
||||||
# with pytest.raises(VMError):
|
with pytest.raises(VMError):
|
||||||
# qemu.get_abs_image_path("C:\\test2.bin")
|
qemu.get_abs_image_path("C:\\test2.bin")
|
||||||
|
|
||||||
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": True}):
|
with patch("gns3server.config.Config.get_section_config", return_value={"images_path": str(tmpdir / "images"), "local": True}):
|
||||||
assert qemu.get_abs_image_path(path2) == path2
|
assert qemu.get_abs_image_path(path2) == path2
|
||||||
|
Loading…
Reference in New Issue
Block a user