An encrypted password store for use within pytest cases
Project description
An encrypted password store for use within pytest cases
This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.
Features
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.
Requirements
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.
Installation
You can install “pytest-securestore” via pip from PyPI:
$ pip install pytest-securestore
Usage
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:
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']
# 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
Contributing
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.
License
Distributed under the terms of the MIT license, “pytest-securestore” is free and open source software
Issues
If you encounter any problems, please file an issue along with a detailed description.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.