Use MITM Proxy in autotests with full control from code
Project description
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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
446cda84d3f3be19515eb3c21ff0f7e499208b479a40b053b538509c316cfabb
|
|
| MD5 |
0c1e26d6f6f81b1e28af087098c04d2f
|
|
| BLAKE2b-256 |
71d048ff90f2ad6664ff62ebbdc4d8b38057b14843d701f471a3883f38757a76
|
Provenance
The following attestation bundles were made for pytest_mitmproxy_plugin-0.1.0.tar.gz:
Publisher:
release.yml on IamVladislav/pytest-mitmproxy-plugin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_mitmproxy_plugin-0.1.0.tar.gz -
Subject digest:
446cda84d3f3be19515eb3c21ff0f7e499208b479a40b053b538509c316cfabb - Sigstore transparency entry: 195177084
- Sigstore integration time:
-
Permalink:
IamVladislav/pytest-mitmproxy-plugin@1710e07ad5d0cc3744dfae6239cd8060800c9252 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IamVladislav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1710e07ad5d0cc3744dfae6239cd8060800c9252 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a0414091ad692530d258bfa0a4061e0e179ca97ae3c9a5f452eba012aaed03a
|
|
| MD5 |
82a41019991d14a98abe4c1b2f295c17
|
|
| BLAKE2b-256 |
c079a0e14d7e24218a3e7edb18ea54e5079a0cd422558963aa464ee2ac033fac
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_mitmproxy_plugin-0.1.0-py3-none-any.whl -
Subject digest:
2a0414091ad692530d258bfa0a4061e0e179ca97ae3c9a5f452eba012aaed03a - Sigstore transparency entry: 195177085
- Sigstore integration time:
-
Permalink:
IamVladislav/pytest-mitmproxy-plugin@1710e07ad5d0cc3744dfae6239cd8060800c9252 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/IamVladislav
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@1710e07ad5d0cc3744dfae6239cd8060800c9252 -
Trigger Event:
push
-
Statement type: