test_http3_vhost.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import pytest
  2. import re
  3. #Python Requests is not able to do native http3 requests.
  4. #We only check for directives which should enable http3.
  5. def test_http3_vhost_enabled_ALTSVC_header(docker_compose, nginxproxy):
  6. r = nginxproxy.get("http://http3-vhost-enabled.nginx-proxy.tld/headers")
  7. assert r.status_code == 200
  8. assert "Host: http3-vhost-enabled.nginx-proxy.tld" in r.text
  9. assert "alt-svc" in r.headers
  10. assert r.headers["alt-svc"] == 'h3=":443"; ma=86400;'
  11. def test_http3_vhost_enabled_config(docker_compose, nginxproxy):
  12. conf = nginxproxy.get_conf().decode('ASCII')
  13. r = nginxproxy.get("http://http3-vhost-enabled.nginx-proxy.tld")
  14. assert r.status_code == 200
  15. assert re.search(r"listen 443 quic reuseport\;", conf)
  16. assert re.search(r"(?s)http3-vhost-enabled\.nginx-proxy\.tld;.*listen 443 quic", conf)
  17. assert re.search(r"(?s)http3-vhost-enabled\.nginx-proxy\.tld;.*http3 on\;", conf)
  18. assert re.search(r"(?s)http3-vhost-enabled\.nginx-proxy\.tld;.*add_header alt-svc \'h3=\":443\"; ma=86400;\'", conf)
  19. def test_http3_vhost_disabled_ALTSVC_header(docker_compose, nginxproxy):
  20. r = nginxproxy.get("http://http3-vhost-disabled.nginx-proxy.tld/headers")
  21. assert r.status_code == 200
  22. assert "Host: http3-vhost-disabled.nginx-proxy.tld" in r.text
  23. assert not "alt-svc" in r.headers
  24. def test_http3_vhost_disabled_config(docker_compose, nginxproxy):
  25. conf = nginxproxy.get_conf().decode('ASCII')
  26. r = nginxproxy.get("http://http3-vhost-disabled.nginx-proxy.tld")
  27. assert r.status_code == 200
  28. assert not re.search(r"(?s)http3-vhost-disabled\.nginx-proxy\.tld.*listen 443 quic.*\# http3-vhost-enabled\.nginx-proxy\.tld", conf)
  29. assert not re.search(r"(?s)http3-vhost-disabled\.nginx-proxy\.tld.*http3 on.*\# http3-vhost-enabled\.nginx-proxy\.tld", conf)
  30. assert not re.search(r"(?s)http3-vhost-disabled\.nginx-proxy\.tld;.*add_header alt-svc \'h3=\":443\"; ma=86400;\'.*\# http3-vhost-enabled\.nginx-proxy\.tld", conf)
  31. def test_http3_vhost_disabledbydefault_ALTSVC_header(docker_compose, nginxproxy):
  32. r = nginxproxy.get("http://http3-vhost-default-disabled.nginx-proxy.tld/headers")
  33. assert r.status_code == 200
  34. assert "Host: http3-vhost-default-disabled.nginx-proxy.tld" in r.text
  35. assert not "alt-svc" in r.headers
  36. def test_http3_vhost_disabledbydefault_config(docker_compose, nginxproxy):
  37. conf = nginxproxy.get_conf().decode('ASCII')
  38. r = nginxproxy.get("http://http3-vhost-default-disabled.nginx-proxy.tld")
  39. assert r.status_code == 200
  40. assert not re.search(r"(?s)http3-vhost-default-disabled\.nginx-proxy\.tld.*listen 443 quic.*\# http3-vhost-disabled\.nginx-proxy\.tld", conf)
  41. assert not re.search(r"(?s)http3-vhost-default-disabled\.nginx-proxy\.tld.*http3 on.*\# http3-vhost-disabled\.nginx-proxy\.tld", conf)
  42. assert not re.search(r"(?s)http3-vhost-default-disabled\.nginx-proxy\.tld;.*add_header alt-svc \'h3=\":443\"; ma=86400;\'.*\# http3-vhost-disabled\.nginx-proxy\.tld", conf)