Skip to main content

Use MITM Proxy in autotests with full control from code

Project description

PyPI version Python versions See Build Status on GitHub Actions

Use MITM Proxy in autotests with full control from code


This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Features

  • You can control the traffic flow dynamically: add or remove addons during the test, modify content on a fly

  • Proxy thread is starting only once per session, but only if test requested the proxy - you can save extra time in both ways - no extra creating proxies, no extra recreating as well

  • Don’t think about addons after the test - by default, all addons ill be removed right after test ending

  • Use default 0-port to avoid port allocating conflict or set an exact one in the settings

Requirements

  • There is no extra requirements to use this package. But you still need to install/provide path to MITMProxy certificates to work with HTTPS

Installation

You can install “pytest-mitmproxy-plugin” via pip from PyPI:

$ pip install pytest-mitmproxy-plugin

Usage

All communication is based on MitmManager wrapper - mitm_manager fixture provides such wrapper right into the test. The MitmManager is designed to creating on-demand once per test session, but after each test all added addon are flushed.

Each interaction with traffic require creating a MITMProxy addon - you can read more about addons on the official page - https://docs.mitmproxy.org/stable/addons-overview/ You may add several addons at once using .add_addon method or remove exact or all addons by .delete_addon or .delete_all_addons. Each addon should inherit the AbstractAddon, although it will work without it, it makes code more clear.

You can configure plugin params by using CLI arguments or pyproject.toml. CLI arguments always have a priority. Next options are configurable:

–proxy-mode ( or mode in .toml ) - string, take a look onto MitmMode enum or CLI help, you may choose, which mode is better for you. By default plugin use SOCKS5, but you may find HTTP ( regular ) more convenient in your case

–proxy-host ( or host in .toml ) - string, usually just 127.0.0.1 ( default ) or 0.0.0.0

–proxy-port ( or port in .toml ) - number, zero by default ( which means “take an empty port” ) or any other port on machine

–proxy-log-level ( or log_level in .toml ) - string, log level according logging, by default - INFO

–proxy-log-dir-path ( or log_dir_path in .toml ) - by default, MITMProxy send info data right into stdout, but sometimes in is better to capture in separately, log files will be created in directory

The toml configuration should be under “mitmproxy-plugin” label, full configration example:

[mitmproxy-plugin]
mode = "socks5"
host = "127.0.0.1"
port = 0
log_level = "INFO"

Version convention

The major version define significant changes, which may not have the backward compatibility. The patch version define changes, which modify plugin code, but have the backward compatibility. The minor version changes define internal changes like workflow/linters etc.

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-mitmproxy-plugin” 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.

Source Distribution

pytest_mitmproxy_plugin-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file pytest_mitmproxy_plugin-0.1.0.tar.gz.

File metadata

  • Download URL: pytest_mitmproxy_plugin-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for pytest_mitmproxy_plugin-0.1.0.tar.gz
Algorithm Hash digest
SHA256 446cda84d3f3be19515eb3c21ff0f7e499208b479a40b053b538509c316cfabb
MD5 0c1e26d6f6f81b1e28af087098c04d2f
BLAKE2b-256 71d048ff90f2ad6664ff62ebbdc4d8b38057b14843d701f471a3883f38757a76

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_mitmproxy_plugin-0.1.0.tar.gz:

Publisher: release.yml on IamVladislav/pytest-mitmproxy-plugin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2a0414091ad692530d258bfa0a4061e0e179ca97ae3c9a5f452eba012aaed03a
MD5 82a41019991d14a98abe4c1b2f295c17
BLAKE2b-256 c079a0e14d7e24218a3e7edb18ea54e5079a0cd422558963aa464ee2ac033fac

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl:

Publisher: release.yml on IamVladislav/pytest-mitmproxy-plugin

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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