Pytest fixtures for testing with gnupg.
Project description
pytest-gnupg-fixtures
Overview
Pytest fixtures to dynamically create GnuPG instances for testing.
Getting Started
Update setup.py to include:
setup(
tests_require=["pytest-gnupg-fixtures"]
)
All fixtures should be automatically included via the pytest11 entry point.
import pytest
from pytest_gnupg_fixtures import GnuPGKeypair # Optional, for typing
def test_custom_signer(gnupg_keypair: GnuPGKeypair):
custom_signer = CustomSigner(
keyid=gnupg_keypair.fingerprints[1],
passphrase=gnupg_keypair.passphrase,
homedir=gnupg_keypair.gnupg_home,
)
assert "PGP SIGNATURE" in custom_signer.sign("my data")
- Tested with python 3.8
Installation
From pypi.org
$ pip install pytest_gnupg_fixtures
From source code
$ git clone https://github.com/crashvb/pytest-gnupg-fixtures
$ cd pytest-gnupg-fixtures
$ virtualenv env
$ source env/bin/activate
$ python -m pip install --editable .[dev]
Fixtures
gnupg_email
Provides a generated email to use as pair of the uid for the keypair.
gnupg_gen_key_conf
Provides the path to a templated GnuPG script file that is used to generate a temporary keypair. If a user-defined script (tests/gnupg_gen_key.conf) can be located, it is used. Otherwise, an embedded script template is copied to temporary location and returned. This fixture is used by the gnupg_keypair fixture.
The$GNUGP_EMAIL
and $GNUPG_PASSPHRASE
variables will be populated within the template during generation of the keypair.
gnupg_keypair
Provides a keypair within a temporary GnuPG trust store.
NamedTuple Fields
The following fields are defined in the tuple provided by this fixture:
- email - from gnupg_email
- fingerprints - A list of key fingerprints. Typically pubkey, subkey...
- gnupg_home - from gnupg_trust_store
- keyid - The public key id of the temporary keypair.
- gen_key_conf - from gnupg_gen_key_conf
- passphrase - from gnupg_passphrase
- script - The path to the instantiated script from gnupg_gen_key_conf
- uids A list of uids existing within the trust store.
Typing is provided by pytest_gnupg_fixtures.GnuPGKeypair
.
gnupg_passphrase
Provides a generated passphrase to use for the keypair.
gnupg_trust_store
Provides a temporary, initialized, GnuPG trust store that is contains no keys. This fixture is used by the gnupg_keypair fixture.
NamedTuple Fields
The following fields are defined in the tuple provided by this fixture:
- gnupg_home - The path to the temporary trust store.
Typing is provided by pytest_gnupg_fixtures.GnuPGTrustStore
.
Limitations
- This has been coded to work with gpg2.
- The generated keypair is very simple. TBD if this will be expanded to support a more realistic configuration.
Changelog
0.1.3 (2021-01-12)
- Add uid parsing to fixture.
- Add gpg-wrapper.
- Update travis configuration to show gpg information.
- Update to dynamically generate passphrase.
- Update to dynamically generate email.
- Update readme.
- Update makefile.
- Remove deprecated pytest-runner integration.
- Remove unused conftest.
- Remove unneeded test dependency.
- Remove comment from template.
- Tweak gnupg trust store temporary path.
0.1.2 (2021-01-06)
- Bug Fix: Correct package_data.
0.1.1 (2021-01-06)
- Initial release.
Development
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for pytest_gnupg_fixtures-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38a98bd77c00adbe39d1652ce0d87c468be8c37859de5fe03d832d15aafcc998 |
|
MD5 | 305b99df51ed4faea037db10bcf1d599 |
|
BLAKE2b-256 | 5ed144f220899bfe22c2ccfc02f6801166d1727ea95612b156b671bc607a8ebb |
Hashes for pytest_gnupg_fixtures-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dab0740c3c1bfc2d4c6ca01849a84ecf47a74db1816eaf7850d0e4bb18e80e5 |
|
MD5 | e0f5c971b4670f3eb7573a4a1d772f1f |
|
BLAKE2b-256 | a643ca3b44ec5b8c68cfc0cba8e94ca5c333f9e3962d99ff381d69341aedbc00 |