From 0dbeefcb02553e4e4a73b056e2c05cf29bb6244d Mon Sep 17 00:00:00 2001 From: Jurriaan Bremer Date: Sat, 21 Apr 2018 11:46:54 +0200 Subject: [PATCH] discourage users from importing cuckoo cwd setups --- cuckoo/apps/import_.py | 4 ++-- cuckoo/main.py | 13 +++++++++++++ tests/test_import.py | 14 +++++++++++++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/cuckoo/apps/import_.py b/cuckoo/apps/import_.py index 01c940335..b8250d0ed 100644 --- a/cuckoo/apps/import_.py +++ b/cuckoo/apps/import_.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2017 Cuckoo Foundation. +# Copyright (C) 2016-2018 Cuckoo Foundation. # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org # See the file 'docs/LICENSE' for copying permission. @@ -127,7 +127,7 @@ def import_cuckoo(username, mode, dirpath): if not version: raise CuckooOperationalError( "The path that you specified is not a proper Cuckoo setup. Please " - "point the path to the root of your older Cuckoo setup, i.e., to " + "point the path to the root of your legacy Cuckoo setup, i.e., to " "the directory containing the cuckoo.py script!" ) diff --git a/cuckoo/main.py b/cuckoo/main.py index e45063e3f..e4cb2f6e7 100644 --- a/cuckoo/main.py +++ b/cuckoo/main.py @@ -627,6 +627,19 @@ def import_(ctx, mode, path): """Imports an older Cuckoo setup into a new CWD. The old setup should be identified by PATH and the new CWD may be specified with the --cwd parameter, e.g., "cuckoo --cwd /tmp/cwd import old-cuckoo".""" + if os.path.exists(os.path.join(path, ".cwd")): + print(yellow( + "The 'cuckoo import' feature is meant to import a legacy Cuckoo, " + "i.e., Cuckoo 1.2, 2.0-dev, 2.0-rc1, or 2.0-rc2 into a new Cuckoo " + "CWD." + )) + print(red( + "You're attempting to import an existing Cuckoo CWD. To upgrade " + "Cuckoo / your CWD, simply run 'pip install -U cuckoo' and re-run " + "the cuckoo commands!" + )) + sys.exit(1) + if mode == "symlink" and is_windows(): sys.exit(red( "You can only use the 'symlink' mode on non-Windows platforms." diff --git a/tests/test_import.py b/tests/test_import.py index 37037059a..1a8486191 100644 --- a/tests/test_import.py +++ b/tests/test_import.py @@ -1,4 +1,4 @@ -# Copyright (C) 2016-2017 Cuckoo Foundation. +# Copyright (C) 2016-2018 Cuckoo Foundation. # This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org # See the file 'docs/LICENSE' for copying permission. @@ -298,6 +298,18 @@ def init_import_legacy(mode): assert not os.path.exists(cwd(analysis="latest")) return dirpath +def test_import_cuckoo_cwd(capsys): + set_cwd(tempfile.mkdtemp()) + cuckoo_create() + + with pytest.raises(SystemExit): + main.main( + ("--cwd", cwd(), "import", cwd()), standalone_mode=False + ) + + out, _ = capsys.readouterr() + assert "import a legacy Cuckoo" in out + def test_import_legacy_analyses_copy(): dirpath = init_import_legacy("copy")