An encrypted password store for use within pytest cases
This pytest plugin was generated with Cookiecutter along with @hackebrot's cookiecutter-pytest-plugin template.
Provide a way to include encrypted data in a test repo so project team members may share test account data (logins, password, keys) while only having to share the decryption password and store filename outside of the repository.
SecureStore makes use of PyAesCrypt by Marco Bellaccini: "pyAesCrypt is a Python 3 file-encryption module and script that uses AES256-CBC to encrypt/decrypt files and binary streams."
Files must be formatted as YAML data (YAML Reference) and will be loaded into a Python dictionary.
You can install "pytest-securestore" via pip from PyPI:
$ pip install pytest-securestore
Generic YAML layout:
---
# a comment
a_general_user:
username: the_username
password: a_password
usertype: some_defined_type
...
Encrypt the YAML file (file encryption):
import os
import pyAesCrypt
buffer_size = 64 * 1024 # 64K
filename = os.getenv('SECURE_STORE_FILE')
password = os.getenv('SECURE_STORE_PASSWORD')
pyAesCrypt.encryptFile("/path/to/yaml/file", filename, password, buffer_size)
Include the encrypted file in the repository.
Within a test:
Note: A password
key triggers an internal class Secret
to obscure
passwords stored in the yaml. Use .value
to get the plain text back.
def test_get_store_values(store):
# one way to get the value
user = store.get('a_general_user')
username = user['username']
# or another
username = store.get('a_general_user').get('username')
# or even another
password = store.get('a_general_user')['password'].value
# or
user_type = store['a_general_user']['usertype']
# ...
some_site.log_in(username, password, user_type)
And to kick it off:
CLI with environment variables:
$ pytest --secure-store-filename=$SECURE_STORE_FILE --secure-store-password=$SECURE_STORE_PASSWORD
Contributions are very welcome. Tests can be run with tox, please ensure the coverage at least stays the same before you submit a pull request.
Distributed under the terms of the MIT license, "pytest-securestore" is free and open source software
If you encounter any problems, please file an issue along with a detailed description.