Nicolas Duchon c4cb1c3797 test: tests for HTTP/3 преди 1 година
..
certs 3f764a5f84 build: bump nginx from 1.25.2-alpine to 1.25.3-alpine преди 1 година
requirements 94259dd22c ci: bump pytest from 7.4.1 to 7.4.3 in /test/requirements преди 1 година
stress_tests 8fbc8514ef feat: Unconditionally produce debug comments преди 2 години
test_custom 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_dockergen 92e1a6567e tests: Remove extraction of `nginx.tmpl` (now unnecessary) преди 2 години
test_fallback.data 035bd2b5ac fix: Remove `default_server` listen option from fallback server преди 2 години
test_headers af877cf784 feat: Add proxy header `X-Forwarded-Host` преди 2 години
test_host-network-mode 35b1493e16 feat: support proxy + container in host network mode преди 2 години
test_http2 c4cb1c3797 test: tests for HTTP/3 преди 1 година
test_http3 c4cb1c3797 test: tests for HTTP/3 преди 1 година
test_internal 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_location-override.vhost.d 2115974e93 feat: Add ability to completely override location blocks преди 2 години
test_multiple-ports 9299a2801e tests: Remove dhparam volume преди 3 години
test_server-down 9299a2801e tests: Remove dhparam volume преди 3 години
test_ssl c4cb1c3797 test: tests for HTTP/3 преди 1 година
test_trust-downstream-proxy af877cf784 feat: Add proxy header `X-Forwarded-Host` преди 2 години
test_upstream-name 9299a2801e tests: Remove dhparam volume преди 3 години
test_virtual-path 0185a2971c tests: fix virtual path tests for new dhparam преди 3 години
README.md a9cfdc843e docs: fix broken link преди 4 години
conftest.py c1a2b31f35 Merge pull request #2222 from rot169/support-hostnet-containers преди 2 години
pytest.ini 6fd3cfb38f fix(ci): :wrench: add markers on pytest.ini to fix warnings преди 4 години
pytest.sh 912a065406 chore: Pass `--pull` to `docker build` to get fresh images преди 2 години
test_DOCKER_HOST_unix_socket.py 6069bc53cd TESTS: replace old test suite with the new one преди 8 години
test_DOCKER_HOST_unix_socket.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_composev2.py 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_composev2.yml 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_default-host.py 6069bc53cd TESTS: replace old test suite with the new one преди 8 години
test_default-host.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_default-root-none.py f8ae0a4b00 feat: `DEFAULT_ROOT=none` disables the default `location /` block преди 2 години
test_default-root-none.yml f8ae0a4b00 feat: `DEFAULT_ROOT=none` disables the default `location /` block преди 2 години
test_events.py fc4c4e17ca ci: Add tests for the virtual-path routing преди 3 години
test_events.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_fallback.py 035bd2b5ac fix: Remove `default_server` listen option from fallback server преди 2 години
test_http_port.py 6bb7c37605 test: custom HTTP port преди 4 години
test_http_port.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_ipv6.py 6069bc53cd TESTS: replace old test suite with the new one преди 8 години
test_ipv6.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_keepalive.py 49bb37dfdb feat: Add support for HTTP keep-alive between the proxy and upstream преди 2 години
test_keepalive.yml 49bb37dfdb feat: Add support for HTTP keep-alive between the proxy and upstream преди 2 години
test_loadbalancing.py 7ca1da8358 feat: Add support for HTTP load balancing between the proxy and upstream server groups (#2173) преди 2 години
test_loadbalancing.yml 7ca1da8358 feat: Add support for HTTP load balancing between the proxy and upstream server groups (#2173) преди 2 години
test_location-override.py 2115974e93 feat: Add ability to completely override location blocks преди 2 години
test_location-override.yml 2115974e93 feat: Add ability to completely override location blocks преди 2 години
test_log_format.py 07cc80ac6b feat: Support LOG_FORMAT env variable (#2151) преди 2 години
test_log_format.yml 07cc80ac6b feat: Support LOG_FORMAT env variable (#2151) преди 2 години
test_multiple-hosts.py 6069bc53cd TESTS: replace old test suite with the new one преди 8 години
test_multiple-hosts.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_multiple-networks.py 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_multiple-networks.yml 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_nominal.py e22ae4a6fd tests: display container version преди 3 години
test_nominal.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_raw-ip-vhost.py ba86bc04f6 tests: check for raw IPv4/6 used as VIRTUAL_HOST преди 3 години
test_raw-ip-vhost.yml 9299a2801e tests: Remove dhparam volume преди 3 години
test_vhost-empty-string.py 8346b68a28 fix: Ignore `VIRTUAL_HOST` set to the empty string преди 2 години
test_vhost-empty-string.yml 8346b68a28 fix: Ignore `VIRTUAL_HOST` set to the empty string преди 2 години
test_vhost-in-multiple-networks.py 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_vhost-in-multiple-networks.yml 13eb61a639 fix: Replace mDNS .local domain with .example domain преди 2 години
test_wildcard_host.py 37e85e6e8d chore(ci): :recycle: convert Python old `%` string to f-strings преди 4 години
test_wildcard_host.yml 9299a2801e tests: Remove dhparam volume преди 3 години

README.md

Nginx proxy test suite

Install requirements

You need 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

Run one single test module

pytest test_nominal.py

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.