Ejemplo n.º 1
0
def test_setup_data_dir(temp_data_dir_path, temp_version_file_path):
    data_dir_path = temp_data_dir_path
    setup_data_dir(data_dir_path)
    assert data_dir_path.is_dir()

    version_file_path = temp_version_file_path
    assert version_file_path.read_text() == current_version
Ejemplo n.º 2
0
def test_data_dir_setup_not_needed(temp_data_dir_path, temp_version_file_path):
    temp_data_dir_path.mkdir()
    temp_version_file_path.write_text(current_version)
    bogus_file_path = create_bogus_file(temp_data_dir_path)

    setup_data_dir(temp_data_dir_path)
    assert temp_version_file_path.read_text() == current_version
    assert bogus_file_path.is_file()
Ejemplo n.º 3
0
def test_old_data_dir_docker_no_version(monkeypatch, temp_data_dir_path):
    monkeypatch.setenv(DOCKER_ENV_VAR, "true")

    temp_data_dir_path.mkdir()
    create_bogus_file(temp_data_dir_path)

    with pytest.raises(IncompatibleDataDirectory):
        setup_data_dir(temp_data_dir_path)
Ejemplo n.º 4
0
def test_empty_data_dir_docker(monkeypatch, temp_data_dir_path,
                               temp_version_file_path):
    monkeypatch.setenv(DOCKER_ENV_VAR, "true")

    temp_data_dir_path.mkdir()

    setup_data_dir(temp_data_dir_path)
    assert temp_version_file_path.read_text() == current_version
Ejemplo n.º 5
0
def test_data_dir_docker_old_version(monkeypatch, temp_data_dir_path,
                                     temp_version_file_path):
    monkeypatch.setenv(DOCKER_ENV_VAR, "true")

    temp_data_dir_path.mkdir()
    temp_version_file_path.write_text(old_version)

    with pytest.raises(IncompatibleDataDirectory):
        setup_data_dir(temp_data_dir_path)
Ejemplo n.º 6
0
def test_new_data_dir_docker(monkeypatch, temp_data_dir_path,
                             temp_version_file_path):
    monkeypatch.setenv(DOCKER_ENV_VAR, "true")

    temp_data_dir_path.mkdir()
    bogus_file_path = create_bogus_file(temp_data_dir_path)
    temp_version_file_path.write_text(current_version)

    setup_data_dir(temp_data_dir_path)
    assert temp_version_file_path.read_text() == current_version
    assert bogus_file_path.is_file()
Ejemplo n.º 7
0
def _setup_config_by_cmd_arg(
        server_config_path) -> Tuple[IslandConfigOptions, str]:
    server_config_path = expand_path(server_config_path)
    config = server_config_handler.load_server_config_from_file(
        server_config_path)

    # TODO refactor like in https://github.com/guardicore/monkey/pull/1528 because
    # there's absolutely no reason to be exposed to IslandConfigOptions extraction logic
    # if you want to modify data directory related code.
    setup_data_dir(config.data_dir)

    return config, server_config_path
Ejemplo n.º 8
0
def test_old_version_removed(monkeypatch, temp_data_dir_path,
                             temp_version_file_path):
    monkeypatch.setattr("builtins.input", lambda _: "y")

    temp_data_dir_path.mkdir()
    temp_version_file_path.write_text(old_version)
    bogus_file_path = create_bogus_file(temp_data_dir_path)

    setup_data_dir(temp_data_dir_path)

    assert temp_version_file_path.read_text() == current_version
    assert not bogus_file_path.is_file()
Ejemplo n.º 9
0
def test_old_version_not_removed(monkeypatch, temp_data_dir_path,
                                 temp_version_file_path, input_value):
    monkeypatch.setattr("builtins.input", lambda _: input_value)

    temp_data_dir_path.mkdir()
    temp_version_file_path.write_text(old_version)
    bogus_file_path = create_bogus_file(temp_data_dir_path)

    with pytest.raises(IncompatibleDataDirectory):
        setup_data_dir(temp_data_dir_path)

    assert temp_version_file_path.read_text() == old_version
    assert bogus_file_path.is_file()
Ejemplo n.º 10
0
def _setup_default_config() -> Tuple[IslandConfigOptions, str]:
    default_config = server_config_handler.load_server_config_from_file(
        DEFAULT_SERVER_CONFIG_PATH)
    default_data_dir = default_config.data_dir

    # TODO refactor like in https://github.com/guardicore/monkey/pull/1528 because
    # there's absolutely no reason to be exposed to IslandConfigOptions extraction logic
    # if you want to modify data directory related code.
    setup_data_dir(default_data_dir)

    server_config_path = server_config_handler.create_default_server_config_file(
        default_data_dir)
    config = server_config_handler.load_server_config_from_file(
        server_config_path)

    return config, server_config_path
Ejemplo n.º 11
0
def test_empty_data_dir(temp_data_dir_path, temp_version_file_path):
    temp_data_dir_path.mkdir()

    setup_data_dir(temp_data_dir_path)
    assert temp_version_file_path.read_text() == current_version