1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-29 02:08:10 +00:00

Don't allow user to overwrite GNS3 docker environment variables

Fix #1098
This commit is contained in:
Julien Duponchelle 2017-07-20 15:37:56 +02:00
parent 8354beaa86
commit b33ba5f8ea
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
2 changed files with 11 additions and 5 deletions

View File

@ -313,7 +313,10 @@ class DockerVM(BaseNode):
params["Env"].append("GNS3_VOLUMES={}".format(":".join(self._volumes)))
if self._environment:
params["Env"] += [e.strip() for e in self._environment.split("\n")]
for e in self._environment.split("\n"):
e = e.strip()
if not e.startswith("GNS3_"):
params["Env"].append(e)
if self._console_type == "vnc":
yield from self._start_vnc()

View File

@ -30,8 +30,7 @@ from gns3server.compute.docker import Docker
from gns3server.utils.get_resource import get_resource
from unittest.mock import patch, MagicMock, PropertyMock, call
from gns3server.config import Config
from unittest.mock import patch, MagicMock, call
@pytest.fixture()
@ -244,15 +243,19 @@ def test_create_start_cmd(loop, project, manager):
def test_create_environment(loop, project, manager):
"""
Allow user to pass an environnement. User can't override our
internal variables
"""
response = {
"Id": "e90e34656806",
"Warnings": []
}
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]) as mock_list_images:
with asyncio_patch("gns3server.compute.docker.Docker.list_images", return_value=[{"image": "ubuntu"}]):
with asyncio_patch("gns3server.compute.docker.Docker.query", return_value=response) as mock:
vm = DockerVM("test", str(uuid.uuid4()), project, manager, "ubuntu")
vm.environment = "YES=1\nNO=0"
vm.environment = "YES=1\nNO=0\nGNS3_MAX_ETHERNET=eth2"
loop.run_until_complete(asyncio.async(vm.create()))
mock.assert_called_with("POST", "containers/create", data={
"Tty": True,