From 64a852f38f6205719068a25539084bfb7db42133 Mon Sep 17 00:00:00 2001 From: ziajka Date: Fri, 9 Jun 2017 15:28:24 +0200 Subject: [PATCH] Fixes #1068 - handle zipfile encoding issues at project duplication --- gns3server/controller/project.py | 2 +- tests/controller/test_project.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/gns3server/controller/project.py b/gns3server/controller/project.py index 3cf17af8..c185cccd 100644 --- a/gns3server/controller/project.py +++ b/gns3server/controller/project.py @@ -714,7 +714,7 @@ class Project: f.write(data) 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) - except OSError as e: + except (OSError, UnicodeEncodeError) as e: raise aiohttp.web.HTTPConflict(text="Can not duplicate project: {}".format(str(e))) if previous_status == "closed": diff --git a/tests/controller/test_project.py b/tests/controller/test_project.py index 4422c0d1..24d019f5 100644 --- a/tests/controller/test_project.py +++ b/tests/controller/test_project.py @@ -23,6 +23,7 @@ import json import pytest import aiohttp import zipfile +import zipstream from unittest.mock import MagicMock from tests.utils import AsyncioMagicMock, asyncio_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" +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): """ List the snapshots