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_gnupgfixtures import GnuPGKeypair # Optional, for typing
def test_custom_signer(gnupg_keypair: GnuPGKeypair):
custom_signer = CustomSigner(
keyid=gnupg_keypair.fingerprints[1],
passphrase="testing",
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_gen_key_conf
Provides the path to a 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 is copied to temporary location and returned. This fixture is used by the gnupg_keypair fixture.
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:
- fingerprints - A list of key fingerprints. Typically pubkey, subkey...
- gen_key_conf - from gnupg_gen_key_conf
- gnupg_home - from gnupg_trust_store
- keyid - The public key id of the temporary keypair.
Typing is provided by pytest_gnupg_fixtures.GnuPGKeypair
.
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.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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59aecff27e04680137ecd5bd62a12368aac4b0f37e4ab314e6f048d5333d83cd |
|
MD5 | 3f846280bedd203dd03817400b7ba39a |
|
BLAKE2b-256 | f5bb41933098dc7d287279d924e9d2e391b957ddbde7bb4f570156b4cc6d30e7 |
Hashes for pytest_gnupg_fixtures-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83876fe8c94f2511e4425cb26fc7da29c4e8cf0cb8941de4a975b39f20f10842 |
|
MD5 | e116c1371b8bb42cd0fb646abe78f5de |
|
BLAKE2b-256 | d879382fe4da9d75aea363f36975e724a987707ec0e18d394f62a484c35fc92d |