No Description

Fabrizio Furnari 6243bc4c60 Added license file 9 months ago
example_tests d5843a36e7 Added some example tests for reference 9 months ago
.gitignore 32c2035b38 Added gitignore and Makefile 9 months ago
COPYING 6243bc4c60 Added license file 9 months ago
Makefile 32c2035b38 Added gitignore and Makefile 9 months ago
README.md 73849b04ef Initial commit. README 9 months ago

README.md

ProxyTester

A simple Python tool to test reverse proxy configuration

Features

  • Tests defined as Python code
  • Automatic backend spawning (if required)
  • Reverse proxy config generation from template (very simple)
  • Reverse proxy spawning/management
  • Validate status code/headers/boxy received by the client
  • Validate status code/headers/boxy received by the backend
  • Report about passed/failed tests

TODO

  • Additional variables in template generation
  • Better https errors management
  • Addidional checks (regex) for haproxy stdout logs (eg. variables)
  • Tests!

Installation

pip install .

Usage

  1. Write basic tests as Python subclasses (see examples below)
  2. HAProxy binary must be present somewhere on the filesystem
  3. An HAProxy template must be present somewhere, or use the very basic one haproxy.cfg.tpl
proxytester --test-dir example_tests/

Test Configuration Format

Each test is defined as Python class inheriting from BaseProxyTest

from proxytester.main import BaseProxyTest, BackendConfig, ProxyConfig

class BasicGetTest(BaseProxyTest):
    def __init__(self):
        super().__init__()
        self.description = "Basic GET request"
        self.url = "http://localhost:4242/"
        self.method = "GET"
        self.expected_status = 200

        self.proxy_config = ProxyConfig(
            binary_path="/home/fixed/bin/haproxy-bookworm"
        )

        self.backend_config = BackendConfig(
            host="127.0.0.1",
            port=4243,
            response_body="Hello",
            response_headers={"X-Test":"test-backend"},
        )

    async def run_test(self):
        await self.make_request()
        return True

Useful parameters

When writing tests it can be useful to immediately check some common patterns, eg. if headers are received or not by the client or the backend.

For this, the BaseProxyTest and it's children accepts some parameters that are used when response is received. See the BaseProxyTest class docstring for more information on how to use them.

Development

  • Install it as editable python package with pip install -e . and start adding features/fix bugs!