mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
Fixes #1068 - handle zipfile encoding issues at project duplication
This commit is contained in:
parent
5c0d955156
commit
64a852f38f
@ -714,7 +714,7 @@ class Project:
|
|||||||
f.write(data)
|
f.write(data)
|
||||||
with open(os.path.join(tmpdir, "project.gns3p"), "rb") as f:
|
with open(os.path.join(tmpdir, "project.gns3p"), "rb") as f:
|
||||||
project = yield from import_project(self._controller, str(uuid.uuid4()), f, location=location, name=name, keep_compute_id=True)
|
project = yield from import_project(self._controller, str(uuid.uuid4()), f, location=location, name=name, keep_compute_id=True)
|
||||||
except OSError as e:
|
except (OSError, UnicodeEncodeError) as e:
|
||||||
raise aiohttp.web.HTTPConflict(text="Can not duplicate project: {}".format(str(e)))
|
raise aiohttp.web.HTTPConflict(text="Can not duplicate project: {}".format(str(e)))
|
||||||
|
|
||||||
if previous_status == "closed":
|
if previous_status == "closed":
|
||||||
|
@ -23,6 +23,7 @@ import json
|
|||||||
import pytest
|
import pytest
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import zipfile
|
import zipfile
|
||||||
|
import zipstream
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
from tests.utils import AsyncioMagicMock, asyncio_patch
|
from tests.utils import AsyncioMagicMock, asyncio_patch
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
@ -439,6 +440,15 @@ def test_duplicate(project, async_run, controller):
|
|||||||
assert list(new_project.nodes.values())[1].compute.id == "remote"
|
assert list(new_project.nodes.values())[1].compute.id == "remote"
|
||||||
|
|
||||||
|
|
||||||
|
def test_duplicate_with_zipfile_encoding_issues(project, async_run, controller):
|
||||||
|
zf = zipstream.ZipFile()
|
||||||
|
zf.writestr('test\udcc3', "data")
|
||||||
|
|
||||||
|
with asyncio_patch('gns3server.controller.project.export_project', return_value=zf):
|
||||||
|
with pytest.raises(aiohttp.web.HTTPConflict):
|
||||||
|
async_run(project.duplicate(name="Hello"))
|
||||||
|
|
||||||
|
|
||||||
def test_snapshots(project):
|
def test_snapshots(project):
|
||||||
"""
|
"""
|
||||||
List the snapshots
|
List the snapshots
|
||||||
|
Loading…
Reference in New Issue
Block a user