def test_extract_symlink(tmp_path):
    FOLDER_NAME = "symlink-folder"

    # access existing archive dir
    archive_path = helpers.get_directory_with_name("symlink-archive")
    folder_path = helpers.get_directory_with_name(FOLDER_NAME)
    extraction_path = tmp_path / "extraction-folder"

    # wait until this aciton has completed
    extract_archive(archive_path, extraction_path)

    dir_listing = os.listdir(extraction_path)

    # assert listing of extracted folder
    assert dir_listing == [FOLDER_NAME]

    # check if symlink exists
    assert extraction_path.joinpath(FOLDER_NAME, "folder-in-archive",
                                    "link.txt").is_symlink()

    # assert content of extracted file
    assert filecmp.cmp(folder_path.joinpath("file1.txt"),
                       extraction_path.joinpath(FOLDER_NAME + "/file1.txt"))
    assert filecmp.cmp(
        folder_path.joinpath("folder-in-archive/file2.txt"),
        extraction_path.joinpath(FOLDER_NAME + "/folder-in-archive/file2.txt"))
Exemplo n.º 2
0
def test_create_archive(tmp_path):
    folder_name = "test-folder"

    folder_path = helpers.get_directory_with_name(folder_name)
    archive_path = helpers.get_directory_with_name("normal-archive")
    destination_path = tmp_path / "name-of-destination-folder"

    create_archive(folder_path, destination_path, compression=5)
    assert_successful_archive_creation(destination_path,
                                       archive_path,
                                       folder_name,
                                       unencrypted="all")
Exemplo n.º 3
0
def test_create_symlink_archive(tmp_path, caplog):
    folder_name = "symlink-folder"

    folder_path = helpers.get_directory_with_name(folder_name)
    archive_path = helpers.get_directory_with_name("symlink-archive")
    destination_path = tmp_path / "name-of-destination-folder"

    create_archive(folder_path, destination_path, compression=5)
    assert_successful_archive_creation(destination_path,
                                       archive_path,
                                       folder_name,
                                       unencrypted="all")

    assert "Broken symlink symlink-folder/invalid_link found pointing to a non-existing file " in caplog.text
    assert "Symlink with outside target symlink-folder/invalid_link_abs found pointing to /not/existing which is outside the archiving directory" in caplog.text
def test_integrity_check_corrupted(caplog):
    archive_dir = get_directory_with_name("normal-archive-corrupted")
    archive_file = archive_dir.joinpath("test-folder.tar.lz")

    expected_string = f"Basic integrity check unsuccessful. Archive has been changed since creation."

    assert_integrity_check_with_output(archive_file, expected_string, False, caplog)
def test_list_archive_content_subpath_split(capsys):
    archive_dir = get_directory_with_name("split-archive")
    expected_listing = get_listing_with_name("listing-split-partial.lst")

    create_file_listing_and_assert_output_equals(archive_dir, expected_listing,
                                                 capsys,
                                                 "large-folder/subfolder")
def test_integrity_check_deep_corrupted_encrypted(caplog, setup_gpg):
    archive_dir = get_directory_with_name("encrypted-archive-corrupted-deep")

    expected_messages = ["Hash of test-folder/folder-in-archive/file2.txt has changed: Expected 5762a5694bf3cb3dp59bf864ed71a4a8 but got 5762a5694bf3cb3df59bf864ed71a4a8",
                         "Deep integrity check unsuccessful. Archive has been changed since creation."]

    check_integrity_and_validate_output_contains(archive_dir, caplog, expected_messages, False, DEEP)
def test_list_archive_content_on_encrypted_archive(capsys, setup_gpg):
    archive_file = get_directory_with_name(
        "encrypted-archive") / "test-folder.tar.lz.gpg"
    expected_listing = get_listing_with_name("listing-full.lst")

    create_file_listing_and_assert_output_equals(archive_file,
                                                 expected_listing, capsys)
def test_list_archive_content_deep_on_split_encrypted_directory(
        capsys, setup_gpg):
    archive_dir = get_directory_with_name("split-encrypted-archive")
    expected_listing = get_listing_with_name("listing-split-deep.lst")

    create_file_listing_and_assert_output_equals(archive_dir, expected_listing,
                                                 capsys, None, DEEP)
def test_list_archive_content_on_archive(capsys):
    archive_file = get_directory_with_name(
        "normal-archive") / "test-folder.tar.lz"
    expected_listing = get_listing_with_name("listing-full.lst")

    create_file_listing_and_assert_output_equals(archive_file,
                                                 expected_listing, capsys)
Exemplo n.º 10
0
def test_create_archive_split_granular(tmp_path, generate_splitting_directory):
    """
    end-to-end test for granular splitting workflow
    """
    max_size = 1000 * 1000 * 50
    folder_name = "large-test-folder"
    source_path = generate_splitting_directory

    archive_path = helpers.get_directory_with_name("split-archive-ressources")
    destination_path = tmp_path / "name-of-destination-folder"

    run_archiver_tool([
        'create', 'filelist', '--part', f"{max_size}B", source_path,
        destination_path
    ])

    run_archiver_tool(
        ['create', 'tar', '--threads',
         str(2), source_path, destination_path])

    run_archiver_tool(
        ['create', 'compressed-tar', '--threads',
         str(2), destination_path])

    assert_successful_archive_creation(destination_path,
                                       archive_path,
                                       folder_name,
                                       split=2,
                                       unencrypted="all")

    assert run_archiver_tool(['check', '--deep',
                              destination_path]).returncode == 0
def test_list_archive_content_on_split_encrypted_archive(capsys, setup_gpg):
    archive_file = get_directory_with_name(
        "split-encrypted-archive") / "large-folder.part3.tar.lz.gpg"
    expected_listing = get_listing_with_name("listing-split-part3.lst")

    create_file_listing_and_assert_output_equals(archive_file,
                                                 expected_listing, capsys)
Exemplo n.º 12
0
def test_encrypt_regular_archive_to_destination(tmp_path):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("normal-archive")
    destination_path = tmp_path / folder_name
    keys = get_public_key_paths()

    encrypt_existing_archive(archive_path, keys, destination_path)
    assert_successful_action_to_destination(destination_path, archive_path, folder_name, encrypted=True)
def test_list_archive_content_deep_subpath_encrypted_split(capsys, setup_gpg):
    archive_dir = get_directory_with_name("split-encrypted-archive")
    expected_listing = get_listing_with_name("listing-split-partial-deep.lst")

    create_file_listing_and_assert_output_equals(archive_dir, expected_listing,
                                                 capsys,
                                                 "large-folder/subfolder",
                                                 DEEP)
def test_list_archive_content_deep_encrypted_subpath(capsys, setup_gpg):
    archive_file = get_directory_with_name(
        "encrypted-archive") / "test-folder.tar.lz.gpg"
    expected_listing = get_listing_with_name("listing-partial-deep.lst")

    create_file_listing_and_assert_output_equals(
        archive_file, expected_listing, capsys,
        "test-folder/folder-in-archive", DEEP)
def test_integrity_check_deep_symlink(caplog):
    archive_dir = get_directory_with_name("symlink-archive")
    archive_file = archive_dir.joinpath("symlink-folder.tar.lz")

    assert_successful_deep_check(archive_file, caplog)

    assert "Symlink symlink-folder/invalid_link_abs found pointing to /not/existing . The archive contains the link itself, but possibly not the file it points to." in caplog.messages
    assert "Symlink symlink-folder/invalid_link pointing to not_existing is broken in archive" in caplog.messages
Exemplo n.º 16
0
def test_create_encrypted_archive(tmp_path):
    folder_name = "test-folder"

    folder_path = helpers.get_directory_with_name(folder_name)
    archive_path = helpers.get_directory_with_name("encrypted-archive")
    destination_path = tmp_path / "name-of-destination-folder"
    keys = get_public_key_paths()

    create_archive(folder_path,
                   destination_path,
                   encryption_keys=keys,
                   compression=5,
                   remove_unencrypted=True)
    assert_successful_archive_creation(destination_path,
                                       archive_path,
                                       folder_name,
                                       encrypted="all")
Exemplo n.º 17
0
def test_encrypt_archive_split(tmp_path):
    folder_name = "large-folder"
    archive_path = helpers.get_directory_with_name("split-archive")
    copied_archive_path = tmp_path / folder_name
    shutil.copytree(archive_path, copied_archive_path)

    keys = get_public_key_paths()
    encrypt_existing_archive(copied_archive_path, keys)
    assert_successful_archive_creation(copied_archive_path, archive_path, folder_name, split=3, encrypted="all", unencrypted="all")
def test_verify_relative_symbolic_links():
    archive_dir = get_directory_with_name("symlink-archive")

    archives_with_hashes = get_archives_with_hashes_from_path(archive_dir)
    missing = verify_relative_symbolic_links(archives_with_hashes)

    link_key = 'symlink-folder/invalid_link'
    assert link_key in missing and missing[link_key] == 'not_existing'
    assert len(missing) == 1
Exemplo n.º 19
0
def test_encrypt_regular_archive_remove_unencrypted(tmp_path):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("normal-archive")
    copied_archive_path = tmp_path / folder_name
    shutil.copytree(archive_path, copied_archive_path)

    keys = get_public_key_paths()
    encrypt_existing_archive(copied_archive_path, keys, remove_unencrypted=True)

    assert_successful_archive_creation(copied_archive_path, archive_path, folder_name, encrypted="all")
def test_decrypt_regular_archive_error_existing(tmp_path, setup_gpg):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("encrypted-archive")
    destination_path = tmp_path / folder_name
    destination_path.mkdir()

    with pytest.raises(SystemExit) as error:
        decrypt_existing_archive(archive_path, destination_path)

        assert error.type == SystemExit
def test_extract_split_partial(tmp_path):
    FOLDER_NAME = "large-folder"

    # access existing archive dir
    archive_path = helpers.get_directory_with_name("split-archive")
    folder_path = helpers.get_directory_with_name(FOLDER_NAME)
    extraction_path = tmp_path / "extraction-folder"

    extracted_file_path = Path(FOLDER_NAME) / "file_b.txt"

    extract_archive(archive_path, extraction_path, extracted_file_path)

    # assert listing of extracted folder
    assert [e[2] for e in os.walk(extraction_path)
            if e[2]] == [[extracted_file_path.name]]

    # assert content of extracted file
    assert filecmp.cmp(folder_path.joinpath("file_b.txt"),
                       extraction_path.joinpath(FOLDER_NAME + "/file_b.txt"))
def test_decrypt_regular_archive_to_destination(tmp_path, setup_gpg):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("encrypted-archive")
    destination_path = tmp_path / folder_name

    decrypt_existing_archive(archive_path, destination_path)
    assert_successful_action_to_destination(destination_path,
                                            archive_path,
                                            folder_name,
                                            encrypted=False)
def test_integrity_check_deep_corrupted(caplog):
    archive_dir = get_directory_with_name("normal-archive-corrupted-deep")

    expected_messages = [
        "Missing file test-folder/folder-in-archive/big file3.txt in archive!",
        'File test-folder/folder-in-archive/file2.txt in archive does not appear in list of md5sums!',
        "Hash of test-folder/file1.txt has changed: Expected 49dbcfb5e7ae8ca55cab5b0e4674d9fd but got 49dbcfb5e7ae8ca55cab6b0e4674d9fd",
        "Deep integrity check unsuccessful. Archive has been changed since creation."]

    check_integrity_and_validate_output_contains(archive_dir, caplog, expected_messages, False, DEEP)
def test_decrypt_archive_split_to_destination(tmp_path):
    folder_name = "large-folder"
    archive_path = helpers.get_directory_with_name("split-encrypted-archive")
    destination_path = tmp_path / folder_name

    decrypt_existing_archive(archive_path, destination_path)
    assert_successful_action_to_destination(destination_path,
                                            archive_path,
                                            folder_name,
                                            encrypted=False,
                                            split=3)
def test_extract_archive_partial(tmp_path):
    FOLDER_NAME = "test-folder"
    extraction_path = tmp_path / "extraction-folder"

    # access existing archive dir
    archive_path = helpers.get_directory_with_name("normal-archive")
    folder_path = helpers.get_directory_with_name(FOLDER_NAME)

    extracted_file_path = Path(FOLDER_NAME) / "folder-in-archive" / "file2.txt"

    extract_archive(archive_path, extraction_path, extracted_file_path)

    # assert listing of extracted folder
    assert [e[2] for e in os.walk(extraction_path)
            if e[2]] == [[extracted_file_path.name]]

    # assert content of extracted file
    assert filecmp.cmp(
        folder_path.joinpath(extracted_file_path.relative_to(
            Path(FOLDER_NAME))), extraction_path.joinpath(extracted_file_path))
Exemplo n.º 26
0
def test_encrypt_regular_file(tmp_path):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("normal-archive")
    copied_archive_path = tmp_path / folder_name
    archive_file = copied_archive_path / f"{folder_name}.tar.lz"

    shutil.copytree(archive_path, copied_archive_path)
    keys = get_public_key_paths()

    encrypt_existing_archive(archive_file, keys)
    assert_successful_archive_creation(copied_archive_path, archive_path, folder_name, encrypted="all", unencrypted="all")
def test_decrypt_regular_archive_remove_unencrypted(tmp_path, setup_gpg):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("encrypted-archive")
    copied_archive_path = tmp_path / folder_name
    shutil.copytree(archive_path, copied_archive_path)

    decrypt_existing_archive(copied_archive_path, remove_unencrypted=True)
    assert_successful_archive_creation(copied_archive_path,
                                       archive_path,
                                       folder_name,
                                       encrypted="hash",
                                       unencrypted="all")
Exemplo n.º 28
0
def test_encrypt_regular_archive_error_existing(tmp_path):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("normal-archive")
    destination_path = tmp_path / folder_name
    destination_path.mkdir()

    keys = get_public_key_paths()

    with pytest.raises(SystemExit) as error:
        encrypt_existing_archive(archive_path, keys, destination_path)

        assert error.type == SystemExit
def test_decrypt_archive_split(tmp_path, setup_gpg):
    folder_name = "large-folder"
    archive_path = helpers.get_directory_with_name("split-encrypted-archive")
    copied_archive_path = tmp_path / folder_name
    shutil.copytree(archive_path, copied_archive_path)

    decrypt_existing_archive(copied_archive_path)
    assert_successful_archive_creation(copied_archive_path,
                                       archive_path,
                                       folder_name,
                                       encrypted="all",
                                       unencrypted="all",
                                       split=3)
def test_decrypt_regular_file(tmp_path, setup_gpg):
    folder_name = "test-folder"
    archive_path = helpers.get_directory_with_name("encrypted-archive")
    copied_archive_path = tmp_path / folder_name
    archive_file = copied_archive_path / f"{folder_name}.tar.lz.gpg"
    shutil.copytree(archive_path, copied_archive_path)

    decrypt_existing_archive(archive_file)
    assert_successful_archive_creation(copied_archive_path,
                                       archive_path,
                                       folder_name,
                                       encrypted="all",
                                       unencrypted="all")