mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Use Pydantic to validate the server config file.
This commit is contained in:
1 parent
478119b40d
commit
30ebae207f
61 files changed
+871
-695
No files matched your search
+41
-43
@@ -25,7 +25,7 @@ from gns3server.utils import force_unix_path
|
||||
from gns3server.utils.images import md5sum, remove_checksum, images_directories, list_images
|
||||
|
||||
|
||||
def test_images_directories(tmpdir):
|
||||
def test_images_directories(tmpdir, config):
|
||||
|
||||
path1 = tmpdir / "images1" / "QEMU" / "test1.bin"
|
||||
path1.write("1", ensure=True)
|
||||
@@ -35,17 +35,16 @@ def test_images_directories(tmpdir):
|
||||
path2.write("1", ensure=True)
|
||||
path2 = force_unix_path(str(path2))
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
||||
"images_path": str(tmpdir / "images1"),
|
||||
"additional_images_path": "/tmp/null24564;{}".format(tmpdir / "images2"),
|
||||
"local": False}):
|
||||
config.settings.Server.images_path = str(tmpdir / "images1")
|
||||
config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2")
|
||||
config.settings.Server.local = False
|
||||
|
||||
# /tmp/null24564 is ignored because doesn't exists
|
||||
res = images_directories("qemu")
|
||||
assert res[0] == force_unix_path(str(tmpdir / "images1" / "QEMU"))
|
||||
assert res[1] == force_unix_path(str(tmpdir / "images2"))
|
||||
assert res[2] == force_unix_path(str(tmpdir / "images1"))
|
||||
assert len(res) == 3
|
||||
# /tmp/null24564 is ignored because doesn't exists
|
||||
res = images_directories("qemu")
|
||||
assert res[0] == force_unix_path(str(tmpdir / "images1" / "QEMU"))
|
||||
assert res[1] == force_unix_path(str(tmpdir / "images2"))
|
||||
assert res[2] == force_unix_path(str(tmpdir / "images1"))
|
||||
assert len(res) == 3
|
||||
|
||||
|
||||
def test_md5sum(tmpdir):
|
||||
@@ -112,7 +111,7 @@ def test_remove_checksum(tmpdir):
|
||||
remove_checksum(str(tmpdir / 'not_exists'))
|
||||
|
||||
|
||||
def test_list_images(tmpdir):
|
||||
def test_list_images(tmpdir, config):
|
||||
|
||||
path1 = tmpdir / "images1" / "IOS" / "test1.image"
|
||||
path1.write(b'\x7fELF\x01\x02\x01', ensure=True)
|
||||
@@ -139,41 +138,40 @@ def test_list_images(tmpdir):
|
||||
path5.write("1", ensure=True)
|
||||
path5 = force_unix_path(str(path5))
|
||||
|
||||
with patch("gns3server.config.Config.get_section_config", return_value={
|
||||
"images_path": str(tmpdir / "images1"),
|
||||
"additional_images_path": "/tmp/null24564;{}".format(str(tmpdir / "images2")),
|
||||
"local": False}):
|
||||
config.settings.Server.images_path = str(tmpdir / "images1")
|
||||
config.settings.Server.additional_images_paths = "/tmp/null24564;" + str(tmpdir / "images2")
|
||||
config.settings.Server.local = False
|
||||
|
||||
assert list_images("dynamips") == [
|
||||
assert list_images("dynamips") == [
|
||||
{
|
||||
'filename': 'test1.image',
|
||||
'filesize': 7,
|
||||
'md5sum': 'b0d5aa897d937aced5a6b1046e8f7e2e',
|
||||
'path': 'test1.image'
|
||||
},
|
||||
{
|
||||
'filename': 'test2.image',
|
||||
'filesize': 7,
|
||||
'md5sum': 'b0d5aa897d937aced5a6b1046e8f7e2e',
|
||||
'path': str(path2)
|
||||
}
|
||||
]
|
||||
|
||||
if sys.platform.startswith("linux"):
|
||||
assert list_images("iou") == [
|
||||
{
|
||||
'filename': 'test1.image',
|
||||
'filename': 'test3.bin',
|
||||
'filesize': 7,
|
||||
'md5sum': 'b0d5aa897d937aced5a6b1046e8f7e2e',
|
||||
'path': 'test1.image'
|
||||
},
|
||||
{
|
||||
'filename': 'test2.image',
|
||||
'filesize': 7,
|
||||
'md5sum': 'b0d5aa897d937aced5a6b1046e8f7e2e',
|
||||
'path': str(path2)
|
||||
'path': 'test3.bin'
|
||||
}
|
||||
]
|
||||
|
||||
if sys.platform.startswith("linux"):
|
||||
assert list_images("iou") == [
|
||||
{
|
||||
'filename': 'test3.bin',
|
||||
'filesize': 7,
|
||||
'md5sum': 'b0d5aa897d937aced5a6b1046e8f7e2e',
|
||||
'path': 'test3.bin'
|
||||
}
|
||||
]
|
||||
|
||||
assert list_images("qemu") == [
|
||||
{
|
||||
'filename': 'test4.qcow2',
|
||||
'filesize': 1,
|
||||
'md5sum': 'c4ca4238a0b923820dcc509a6f75849b',
|
||||
'path': 'test4.qcow2'
|
||||
}
|
||||
]
|
||||
assert list_images("qemu") == [
|
||||
{
|
||||
'filename': 'test4.qcow2',
|
||||
'filesize': 1,
|
||||
'md5sum': 'c4ca4238a0b923820dcc509a6f75849b',
|
||||
'path': 'test4.qcow2'
|
||||
}
|
||||
]
|
||||
@@ -39,8 +39,9 @@ def test_interfaces():
|
||||
assert "netmask" in interface
|
||||
|
||||
|
||||
def test_has_netmask():
|
||||
def test_has_netmask(config):
|
||||
|
||||
config.settings.Server.allowed_interfaces = "lo0,lo"
|
||||
if sys.platform.startswith("win"):
|
||||
# No loopback
|
||||
pass
|
||||
|
||||
@@ -25,12 +25,12 @@ from gns3server.utils.path import check_path_allowed, get_default_project_direct
|
||||
|
||||
def test_check_path_allowed(config, tmpdir):
|
||||
|
||||
config.set("Server", "local", False)
|
||||
config.set("Server", "projects_path", str(tmpdir))
|
||||
config.settings.Server.local = False
|
||||
config.settings.Server.projects_path = str(tmpdir)
|
||||
with pytest.raises(HTTPException):
|
||||
check_path_allowed("/private")
|
||||
|
||||
config.set("Server", "local", True)
|
||||
config.settings.Server.local = True
|
||||
check_path_allowed(str(tmpdir / "hello" / "world"))
|
||||
check_path_allowed("/private")
|
||||
|
||||
|
||||
Reference in new issue
Block a user