2
0

test_virtual-path.py 1.0 KB

12345678910111213141516171819202122232425
  1. import pytest
  2. from requests import ConnectionError
  3. @pytest.mark.parametrize("path", ["web1", "web2"])
  4. def test_web1_http_redirects_to_https(docker_compose, nginxproxy, path):
  5. r = nginxproxy.get("http://www.nginx-proxy.tld/%s/port" % path, allow_redirects=False)
  6. assert r.status_code == 301
  7. assert "Location" in r.headers
  8. assert "https://www.nginx-proxy.tld/%s/port" % path == r.headers['Location']
  9. @pytest.mark.parametrize("path,port", [("web1", 81), ("web2", 82)])
  10. def test_web1_https_is_forwarded(docker_compose, nginxproxy, path, port):
  11. r = nginxproxy.get("https://www.nginx-proxy.tld/%s/port" % path, allow_redirects=False)
  12. assert r.status_code == 200
  13. assert "answer from port %d\n" % port in r.text
  14. @pytest.mark.parametrize("port", [81, 82])
  15. def test_acme_challenge_does_not_work(docker_compose, nginxproxy, acme_challenge_path, port):
  16. with pytest.raises(ConnectionError):
  17. nginxproxy.get(
  18. f"http://www.nginx-proxy.tld:{port}/{acme_challenge_path}",
  19. allow_redirects=False
  20. )