Nicolas Duchon b5dea1cf50 tests: cleanup test code 9 місяців тому
..
certs 760c891a0c build: bump library/nginx from 1.27.2 to 1.27.3 10 місяців тому
requirements b5dea1cf50 tests: cleanup test code 9 місяців тому
stress_tests fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_acme_http_challenge_location b5dea1cf50 tests: cleanup test code 9 місяців тому
test_custom b5dea1cf50 tests: cleanup test code 9 місяців тому
test_custom-error-page b5dea1cf50 tests: cleanup test code 9 місяців тому
test_debug_endpoint b5dea1cf50 tests: cleanup test code 9 місяців тому
test_dockergen 92eb45f0ec ci: python 3.12+ compatibility 9 місяців тому
test_fallback.data fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_headers fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_host-network-mode b5dea1cf50 tests: cleanup test code 9 місяців тому
test_htpasswd b5dea1cf50 tests: cleanup test code 9 місяців тому
test_http2 b5dea1cf50 tests: cleanup test code 9 місяців тому
test_http3 b5dea1cf50 tests: cleanup test code 9 місяців тому
test_internal b5dea1cf50 tests: cleanup test code 9 місяців тому
test_ipv6 b5dea1cf50 tests: cleanup test code 9 місяців тому
test_location-override.vhost.d 2115974e93 feat: Add ability to completely override location blocks 2 роки тому
test_logs b5dea1cf50 tests: cleanup test code 9 місяців тому
test_multiports b5dea1cf50 tests: cleanup test code 9 місяців тому
test_ports b5dea1cf50 tests: cleanup test code 9 місяців тому
test_server-down b5dea1cf50 tests: cleanup test code 9 місяців тому
test_ssl b5dea1cf50 tests: cleanup test code 9 місяців тому
test_trust-downstream-proxy b5dea1cf50 tests: cleanup test code 9 місяців тому
test_upstream-name b5dea1cf50 tests: cleanup test code 9 місяців тому
test_virtual-path b5dea1cf50 tests: cleanup test code 9 місяців тому
README.md 329b69fe76 Update test readme 1 рік тому
conftest.py b5dea1cf50 tests: cleanup test code 9 місяців тому
pytest.ini c338a7cf22 Color terminal output 1 рік тому
pytest.sh b5cac06305 ci: remove python docker-compose 1 рік тому
test_DOCKER_HOST_unix_socket.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_DOCKER_HOST_unix_socket.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_build.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_default-host.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_default-host.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_enable_http_on_missing_cert.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_enable_http_on_missing_cert.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_events.py c4cf0af373 test: fix failing tests 1 рік тому
test_events.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_fallback.py 993bcc07c0 test: globally untrusted default cert 10 місяців тому
test_http_port.py cb59c24470 tests non standard port Host header 1 рік тому
test_http_port.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_keepalive.py 2aa35aa637 tests: keepalive auto setting 1 рік тому
test_keepalive.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_loadbalancing.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_loadbalancing.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_location-override.py 2115974e93 feat: Add ability to completely override location blocks 2 роки тому
test_location-override.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_multiple-hosts.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_multiple-hosts.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_multiple-networks.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_multiple-networks.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_nominal.py e22ae4a6fd tests: display container version 3 роки тому
test_nominal.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_raw-ip-vhost.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_raw-ip-vhost.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_vhost-empty-string.py 8346b68a28 fix: Ignore `VIRTUAL_HOST` set to the empty string 2 роки тому
test_vhost-empty-string.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_vhost-in-multiple-networks.py b5dea1cf50 tests: cleanup test code 9 місяців тому
test_vhost-in-multiple-networks.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому
test_wildcard_host.py 37e85e6e8d chore(ci): :recycle: convert Python old `%` string to f-strings 4 роки тому
test_wildcard_host.yml fbad3ac3fc chore: docker compose version is obsolete 9 місяців тому

README.md

Nginx proxy test suite

Install requirements

You need Docker Compose v2, python 3.9 and pip installed. Then run the commands:

pip install -r requirements/python-requirements.txt

Prepare the nginx-proxy test image

make build-nginx-proxy-test-debian

or if you want to test the alpine flavor:

make build-nginx-proxy-test-alpine

Run the test suite

pytest

need more verbosity ?

pytest -s

Note: By default this test suite relies on Docker Compose v2 with the command docker compose. It still supports Docker Compose v1 via the DOCKER_COMPOSE environment variable:

DOCKER_COMPOSE=docker-compose pytest

Run one single test module

pytest test_nominal.py

Run the test suite from a Docker container

If you cannot (or don't want to) install pytest and its requirements on your computer. You can use the nginx-proxy-tester docker image to run the test suite from a Docker container.

make test-debian

or if you want to test the alpine flavor:

make test-alpine

Write a test module

This test suite uses pytest. The conftest.py file will be automatically loaded by pytest and will provide you with two useful pytest fixtures:

  • docker_compose
  • nginxproxy

docker_compose fixture

When using the docker_compose fixture in a test, pytest will try to find a yml file named after your test module filename. For instance, if your test module is test_example.py, then the docker_compose fixture will try to load a test_example.yml docker compose file.

Once the docker compose file found, the fixture will remove all containers, run docker compose up, and finally your test will be executed.

The fixture will run the docker compose command with the -f option to load the given compose file. So you can test your docker compose file syntax by running it yourself with:

docker compose -f test_example.yml up -d

In the case you are running pytest from within a docker container, the docker_compose fixture will make sure the container running pytest is attached to all docker networks. That way, your test will be able to reach any of them.

In your tests, you can use the docker_compose variable to query and command the docker daemon as it provides you with a client from the docker python module.

Also this fixture alters the way the python interpreter resolves domain names to IP addresses in the following ways:

Any domain name containing the substring nginx-proxy will resolve to the IP address of the container that was created from the nginxproxy/nginx-proxy:test image. So all the following domain names will resolve to the nginx-proxy container in tests:

  • nginx-proxy
  • nginx-proxy.com
  • www.nginx-proxy.com
  • www.nginx-proxy.test
  • www.nginx-proxy
  • whatever.nginx-proxyooooooo
  • ...

Any domain name ending with XXX.container.docker will resolve to the IP address of the XXX container.

  • web1.container.docker will resolve to the IP address of the web1 container
  • f00.web1.container.docker will resolve to the IP address of the web1 container
  • anything.whatever.web2.container.docker will resolve to the IP address of the web2 container

Otherwise, domain names are resoved as usual using your system DNS resolver.

nginxproxy fixture

The nginxproxy fixture will provide you with a replacement for the python requests module. This replacement will just repeat up to 30 times a requests if it receives the HTTP error 404 or 502. This error occurs when you try to send queries to nginx-proxy too early after the container creation.

Also this requests replacement is preconfigured to use the Certificate Authority root certificate certs/ca-root.crt to validate https connections.

Furthermore, the nginxproxy methods accept an additional keyword parameter: ipv6 which forces requests made against containers to use the containers IPv6 address when set to True. If IPv6 is not supported by the system or docker, that particular test will be skipped.

def test_forwards_to_web1_ipv6(docker_compose, nginxproxy):
    r = nginxproxy.get("http://web1.nginx-proxy.tld/port", ipv6=True)
    assert r.status_code == 200   
    assert r.text == "answer from port 81\n"

The web docker image

When you run the make build-webserver command, you built a web docker image which is convenient for running a small web server in a container. This image can produce containers that listens on multiple ports at the same time.

Testing TLS

If you need to create server certificates, use the certs/create_server_certificate.sh script. Pytest will be able to validate any certificate issued from this script.