예제 #1
0
def test_dumpcmd():
    assert dumpcmd(None, "/tmp") == (
        ["sqlite3", os.path.join("/tmp", "db/cuckoo.db"), ".dump"], {}
    )
    assert dumpcmd("sqlite:///db/cuckoo.db", "/tmp") == (
        ["sqlite3", os.path.join("/tmp", "db/cuckoo.db"), ".dump"], {}
    )
    assert dumpcmd("sqlite:////tmp/cuckoo.db", "/tmp") == (
        ["sqlite3", "/tmp/cuckoo.db", ".dump"], {}
    )
    if not is_macosx():
        assert dumpcmd("mysql://*****:*****@localh0st/baz", "/tmp") == (
            ["mysqldump", "-u", "foo", "-pbar", "-h", "localh0st", "baz"], {}
        )
        assert dumpcmd("mysql://*****:*****@localhost/cuckoo", "/tmp") == (
            ["mysqldump", "-u", "cuckoo", "-prandom!", "cuckoo"], {}
        )
    if not is_macosx():
        assert dumpcmd("postgresql://*****:*****@localhost/baz", "/tmp") == (
            ["pg_dump", "-U", "user", "baz"], {"PGPASSWORD": "******"}
        )
        assert dumpcmd("postgresql://u n!:bar@localhost/baz", "/tmp") == (
            ["pg_dump", "-U", "u n!", "baz"], {"PGPASSWORD": "******"}
        )
        assert dumpcmd("postgresql://:b@c/d", "/tmp") == (
            ["pg_dump", "-h", "c", "d"], {"PGPASSWORD": "******"}
        )

    with pytest.raises(CuckooOperationalError) as e:
        dumpcmd("notadatabaseuri", "/tmp")
    e.match("URI wasn't understood")

    with pytest.raises(CuckooOperationalError) as e:
        dumpcmd("notadatabase://*****:*****@c/d", "/tmp")
    e.match("URI wasn't understood")
예제 #2
0
def test_dumpcmd():
    assert dumpcmd(None, "/tmp") == ([
        "sqlite3", os.path.join("/tmp", "db/cuckoo.db"), ".dump"
    ], {})
    assert dumpcmd("sqlite:///db/cuckoo.db", "/tmp") == ([
        "sqlite3", os.path.join("/tmp", "db/cuckoo.db"), ".dump"
    ], {})
    assert dumpcmd("sqlite:////tmp/cuckoo.db",
                   "/tmp") == (["sqlite3", "/tmp/cuckoo.db", ".dump"], {})
    if not is_macosx():
        assert dumpcmd("mysql://*****:*****@localh0st/baz", "/tmp") == ([
            "mysqldump", "-u", "foo", "-pbar", "-h", "localh0st", "baz"
        ], {})
        assert dumpcmd("mysql://*****:*****@localhost/cuckoo", "/tmp") == ([
            "mysqldump", "-u", "cuckoo", "-prandom!", "cuckoo"
        ], {})
    if not is_macosx():
        assert dumpcmd("postgresql://*****:*****@localhost/baz",
                       "/tmp") == (["pg_dump", "-U", "user", "baz"], {
                           "PGPASSWORD": "******"
                       })
        assert dumpcmd("postgresql://u n!:bar@localhost/baz",
                       "/tmp") == (["pg_dump", "-U", "u n!", "baz"], {
                           "PGPASSWORD": "******"
                       })
        assert dumpcmd("postgresql://:b@c/d",
                       "/tmp") == (["pg_dump", "-h", "c", "d"], {
                           "PGPASSWORD": "******"
                       })

    with pytest.raises(CuckooOperationalError) as e:
        dumpcmd("notadatabaseuri", "/tmp")
    e.match("URI wasn't understood")

    with pytest.raises(CuckooOperationalError) as e:
        dumpcmd("notadatabase://*****:*****@c/d", "/tmp")
    e.match("URI wasn't understood")
예제 #3
0
def test_is_macosx():
    assert is_windows() is False
    assert is_linux() is False
    assert is_macosx() is True
예제 #4
0
def test_is_macosx():
    assert is_windows() is False
    assert is_linux() is False
    assert is_macosx() is True
예제 #5
0
from cuckoo.misc import is_windows, is_linux, is_macosx, getuser, mkdir

# Note that collect_ignore is a parameter for pytest so that it knows which
# unit tests to skip etc. In other words, perform platform-specific unit tests
# (in terms of the Cuckoo Analyzer) depending on the current host machine.
collect_ignore = []

if is_windows():
    sys.path.insert(0, "cuckoo/data/analyzer/windows")
    collect_ignore.append("tests/linux")
    collect_ignore.append("tests/darwin")

    # Copy over the monitoring binaries as if we were in a real analysis.
    monitor = open("cuckoo/data/monitor/latest", "rb").read().strip()
    for filename in os.listdir("cuckoo/data/monitor/%s" % monitor):
        shutil.copy("cuckoo/data/monitor/%s/%s" % (monitor, filename),
                    "cuckoo/data/analyzer/windows/bin/%s" % filename)

if is_linux():
    sys.path.insert(0, "cuckoo/data/analyzer/linux")
    collect_ignore.append("tests/windows")
    collect_ignore.append("tests/darwin")

if is_macosx():
    sys.path.insert(0, "cuckoo/data/analyzer/darwin")
    collect_ignore.append("tests/windows")
    collect_ignore.append("tests/linux")

# Ensure the Cuckoo TMP dir exists, as some tests rely on it.
mkdir(os.path.join(tempfile.gettempdir(), "cuckoo-tmp-%s" % getuser()))
예제 #6
0
파일: conftest.py 프로젝트: jgajek/cuckoo
# Copyright (C) 2017 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.

import sys

from cuckoo.misc import is_windows, is_linux, is_macosx

# Note that collect_ignore is a parameter for pytest so that it knows which
# unit tests to skip etc. In other words, perform platform-specific unit tests
# (in terms of the Cuckoo Analyzer) depending on the current host machine.
collect_ignore = []

if is_windows():
    sys.path.insert(0, "cuckoo/data/analyzer/windows")
    collect_ignore.append("tests/linux")
    collect_ignore.append("tests/darwin")

if is_linux():
    sys.path.insert(0, "cuckoo/data/analyzer/linux")
    collect_ignore.append("tests/windows")
    collect_ignore.append("tests/darwin")

if is_macosx():
    sys.path.insert(0, "cuckoo/data/analyzer/darwin")
    collect_ignore.append("tests/windows")
    collect_ignore.append("tests/linux")