Skip to main content

Pytest plugin to hide sensitive data in test reports

Project description

pytest-mask-secrets

pytest-mask-secrets is a plugin for pytest that removes sensitive data from test reports.

Based on the configuration, it searches for specified secrets, passwords, and tokens in the records and replaces them with asterisks.

While this feature is usually provided by CI tools, it can be insufficient in many situations as it only strips secrets from the captured output. A common case of leaking secrets is through generated JUnit files that are not curated by CI tools. Therefore, it is necessary to have such functionality at the pytest level.

Installation

pip install pytest-mask-secrets

Usage

pytest-mask-secrets needs to know which values to mask. These values are read from environment variables. The list of these variables is passed in the MASK_SECRETS environment variable, which contains a comma-separated list of all environment variables containing secrets. Here is an example:

export PYPI_API_TOKEN=mytoken
export SOME_PASSWORD=mypassword
export MASK_SECRETS=PYPI_API_TOKEN,SOME_PASSWORD

pytest

With pytest-mask-secrets installed, all occurrences of "mytoken" and "mypassword" will be eliminated from the report.

Automagic Identification of Variables with Secrets

If MASK_SECRETS_AUTO is set to anything other than zero ("0"), all environment variables containing the words "TOKEN", "SECRET," "PASSWORD," or "PASSWD" in their names are considered sensitive, and their values are removed from the report.

This discovery mode should be used with caution. CI workflows, in particular, should rely on an explicit list of secret variables. Under certain circumstances, this method can lead to the leakage of other sensitive data (if, by accident, a secret from an environment variable matches text commonly present in the test report). Nevertheless, this method can still be useful for example for local execution to prevent accidental leaks through copy-and-paste.

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

pytest_mask_secrets-0.2.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

pytest_mask_secrets-0.2.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file pytest_mask_secrets-0.2.0.tar.gz.

File metadata

  • Download URL: pytest_mask_secrets-0.2.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.17.3 CPython/3.10.12 Linux/6.5.0-1025-azure

File hashes

Hashes for pytest_mask_secrets-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7b7c9ac28689a8bd5db3becb15f7e8eeab165d18804e90dfaaa92261fc476795
MD5 ced702f350a457257751341829ed236f
BLAKE2b-256 6259c0c6fb1840490df7e40981a7fc57c88bd965563776264a462aafece335cd

See more details on using hashes here.

File details

Details for the file pytest_mask_secrets-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_mask_secrets-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 68a991b0ec2beb47982bf6b28ab0ad3c600a5d888da4d9e8e61ee201743ad4d1
MD5 f06cdd5fc849b4f30b7162f53cf44588
BLAKE2b-256 45cf5929f898e14f4b8d33e468691747e030a5c23846f241e162932d1b0f6084

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page