def test_list_gpg_keys_on_ro_gpg_home(
        gpg_ctx_w_secret_id_ro: GpgContextWGenInfo) -> None:
    gpg_ctx = gpg_ctx_w_secret_id_ro
    # This is a known gpg bug.
    # See [gnupg - gpg list keys error trustdb is not writable - Stack
    # Overflow](https://stackoverflow.com/questions/41916857/gpg-list-keys-error-trustdb-is-not-writable)
    list_gpg_keys(proc=gpg_ctx.proc)
Beispiel #2
0
def test_export_and_import_public_id(
        gpg_ctx_w_2_distinct_secret_ids: GpgContextWGenInfo,
        tmp_export_dir: Path,
        gpg_ctx_empty_minimal_dirs: GpgContextWGenInfo) -> None:

    exp_ctx = gpg_ctx_w_2_distinct_secret_ids
    imp_ctx = gpg_ctx_empty_minimal_dirs

    assert 2 == len(exp_ctx.gen_info.secret_keys)
    exp_email = exp_ctx.gen_info.secret_keys[1].email

    public_keys_path = tmp_export_dir.joinpath("public.gpg-keys")
    export_gpg_public_key_to_file(public_keys_path,
                                  exp_ctx.gen_info.secret_keys[1].email,
                                  auth=exp_ctx.auth,
                                  proc=exp_ctx.proc)

    import_gpg_key_file(public_keys_path, proc=imp_ctx.proc)

    imp_skeys = list_gpg_secret_keys(auth=imp_ctx.auth, proc=imp_ctx.proc)
    assert 0 == len(imp_skeys)

    imp_keys = list_gpg_keys(proc=imp_ctx.proc)
    assert 1 == len(imp_keys)
    assert exp_email == imp_keys[0].email
def _check_expected_keys(gpg_ctx: GpgContextWGenInfo) -> None:
    keys = list_gpg_keys(proc=gpg_ctx.proc)
    LOGGER.info(f"keys: {keys}")

    found_emails = {k.email for k in keys}
    LOGGER.info(f"found_emails: {found_emails}")

    expected_emails = {k.email for k in gpg_ctx.gen_info.secret_keys}
    assert len(found_emails) >= len(expected_emails)

    for ski in gpg_ctx.gen_info.secret_keys:
        assert ski.email in found_emails
Beispiel #4
0
def test_export_and_import_otrust(
        gpg_ctx_w_2_distinct_secret_ids: GpgContextWGenInfo,
        tmp_export_dir: Path,
        gpg_ctx_empty_minimal_dirs: GpgContextWGenInfo) -> None:

    exp_ctx = gpg_ctx_w_2_distinct_secret_ids
    imp_ctx = gpg_ctx_empty_minimal_dirs

    exp_otrust = list_gpg_ownertrust(proc=exp_ctx.proc)
    assert 2 == len(exp_otrust)

    assert 2 == len(exp_ctx.gen_info.secret_keys)

    subkeys_path = tmp_export_dir.joinpath("subkeys.gpg-keys")
    LOGGER.info(f"export_gpg_secret_subkeys_to_file(\"{subkeys_path}\", ..)")
    export_gpg_secret_subkeys_to_file(subkeys_path,
                                      exp_ctx.gen_info.secret_keys[1].email,
                                      auth=exp_ctx.auth,
                                      proc=exp_ctx.proc)

    otrust_path = tmp_export_dir.joinpath("exported.gpg-otrust")
    LOGGER.info(f"export_gpg_otrust_to_file(\"{otrust_path}\", ..)")
    export_gpg_otrust_to_file(otrust_path,
                              auth=exp_ctx.auth,
                              proc=exp_ctx.proc)

    file_otrust = list_gpg_ownertrust_from_file(otrust_path)
    assert 2 == len(file_otrust)
    assert exp_otrust == file_otrust

    import_gpg_key_file(subkeys_path, proc=imp_ctx.proc)
    import_gpg_otrust_file(otrust_path, proc=imp_ctx.proc)

    imp_skeys = list_gpg_secret_keys(auth=imp_ctx.auth, proc=imp_ctx.proc)
    assert 1 == len(imp_skeys)

    imp_keys = list_gpg_keys(proc=imp_ctx.proc)
    assert 1 == len(imp_keys)

    imp_otrust = list_gpg_ownertrust(proc=imp_ctx.proc)
    assert 2 == len(imp_otrust)
    assert file_otrust == imp_otrust
Beispiel #5
0
def test_export_and_import_public_id_in_memory(
        gpg_ctx_w_2_distinct_secret_ids: GpgContextWGenInfo,
        gpg_ctx_empty_minimal_dirs: GpgContextWGenInfo) -> None:

    exp_ctx = gpg_ctx_w_2_distinct_secret_ids
    imp_ctx = gpg_ctx_empty_minimal_dirs

    assert 2 == len(exp_ctx.gen_info.secret_keys)
    exp_email = exp_ctx.gen_info.secret_keys[1].email

    exp_text = export_gpg_public_key_to_text(
        exp_ctx.gen_info.secret_keys[1].email,
        auth=exp_ctx.auth,
        proc=exp_ctx.proc)

    import_gpg_key_text(exp_text, proc=imp_ctx.proc)

    imp_skeys = list_gpg_secret_keys(auth=imp_ctx.auth, proc=imp_ctx.proc)
    assert 0 == len(imp_skeys)

    imp_keys = list_gpg_keys(proc=imp_ctx.proc)
    assert 1 == len(imp_keys)
    assert exp_email == imp_keys[0].email
def _get_gpg_email_set(gpg_ctx: GpgContextWGenInfo) -> Set[str]:
    keys = list_gpg_keys(proc=gpg_ctx.proc)
    return {k.email for k in keys}