1
0
Fork 0
mirror of https://github.com/nginx-proxy/nginx-proxy synced 2024-05-09 09:06:16 +02:00
nginx-proxy/test
Richard Hansen dfd4f54c61 fix: Don't downgrade from https to http if certificate is missing
Before, if a site's certificate was not found, the site was served
over http rather than https.  Failing open like this is problematic
for sites where security is important.  Presumably the user set
`HTTPS_METHOD` to a non-`noredirect` value (or left it unset) for a
good reason; we should honor it even if it means serving error
messages.

WARNING: This change breaks compatibility.  Any vhost where all of the
following are true will fail after this change:

  * `HTTPS_METHOD` is either unset or set to a value other than
    `nohttps`.
  * The vhost does not have its own certificate (`default.crt` doesn't
    count).
  * Clients expect to be able to access the vhost by using plain http
    to nginx-proxy.

To get the previous behavior, set `HTTPS_METHOD` to `nohttps` for the
vhost.
2023-05-14 14:56:43 -04:00
..
certs Fix create_server_certificate.sh 2021-05-11 10:29:22 +01:00
requirements ci: bump requests from 2.29.0 to 2.30.0 in /test/requirements 2023-05-08 10:48:18 +00:00
stress_tests fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_custom fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_dockergen fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_fallback.data fix: Remove `default_server` listen option from fallback server 2023-04-13 01:16:54 -04:00
test_headers fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_internal fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_location-override.vhost.d feat: Add ability to completely override location blocks 2023-01-31 04:53:12 -05:00
test_multiple-ports fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_server-down fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_ssl test: fix wildcard_certs_and_nohttps test 2023-05-08 21:20:47 +02:00
test_trust-downstream-proxy feat: Add proxy header `X-Forwarded-Host` 2022-12-26 17:59:50 -05:00
test_upstream-name fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_virtual-path fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
README.md docs: fix broken link 2021-05-01 22:30:57 +02:00
conftest.py tests: Reduce scope of `docker_compose` fixture (and friends) 2023-02-17 02:34:08 -05:00
pytest.ini fix(ci): 🔧 add markers on pytest.ini to fix warnings 2021-04-27 00:35:20 +02:00
pytest.sh chore: Pass `--pull` to `docker build` to get fresh images 2023-01-28 18:17:40 -05:00
test_DOCKER_HOST_unix_socket.py TESTS: replace old test suite with the new one 2017-02-17 00:29:30 +01:00
test_DOCKER_HOST_unix_socket.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_composev2.py TESTS: replace old test suite with the new one 2017-02-17 00:29:30 +01:00
test_composev2.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_default-host.py TESTS: replace old test suite with the new one 2017-02-17 00:29:30 +01:00
test_default-host.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_default-root-none.py feat: `DEFAULT_ROOT=none` disables the default `location /` block 2023-01-23 20:47:00 -05:00
test_default-root-none.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_events.py ci: Add tests for the virtual-path routing 2022-02-24 15:07:02 +01:00
test_events.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_fallback.py fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_http_port.py test: custom HTTP port 2021-06-15 00:13:06 +02:00
test_http_port.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_ipv6.py TESTS: replace old test suite with the new one 2017-02-17 00:29:30 +01:00
test_ipv6.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_keepalive.py feat: Add support for HTTP keep-alive between the proxy and upstream 2023-03-14 04:20:17 -04:00
test_keepalive.yml feat: Add support for HTTP keep-alive between the proxy and upstream 2023-03-14 04:20:17 -04:00
test_loadbalancing.py feat: Add support for HTTP load balancing between the proxy and upstream server groups (#2173) 2023-03-21 07:49:27 +01:00
test_loadbalancing.yml feat: Add support for HTTP load balancing between the proxy and upstream server groups (#2173) 2023-03-21 07:49:27 +01:00
test_location-override.py feat: Add ability to completely override location blocks 2023-01-31 04:53:12 -05:00
test_location-override.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_log_format.py feat: Support LOG_FORMAT env variable (#2151) 2023-01-27 12:28:40 -05:00
test_log_format.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_multiple-hosts.py TESTS: replace old test suite with the new one 2017-02-17 00:29:30 +01:00
test_multiple-hosts.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_multiple-networks.py fix: Generate at most one `server` directive per container 2023-01-28 18:01:19 -05:00
test_multiple-networks.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_nominal.py tests: display container version 2022-01-12 10:17:49 +01:00
test_nominal.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_raw-ip-vhost.py tests: check for raw IPv4/6 used as VIRTUAL_HOST 2021-08-04 22:25:55 +02:00
test_raw-ip-vhost.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_vhost-empty-string.py fix: Ignore `VIRTUAL_HOST` set to the empty string 2023-01-23 20:48:16 -05:00
test_vhost-empty-string.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_vhost-in-multiple-networks.py Make sure networks order is the same 2022-05-11 12:56:18 +00:00
test_vhost-in-multiple-networks.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00
test_wildcard_host.py chore(ci): ♻️ convert Python old `%` string to f-strings 2021-04-27 00:35:20 +02:00
test_wildcard_host.yml fix: Don't downgrade from https to http if certificate is missing 2023-05-14 14:56:43 -04:00

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.