test_http3-vhost.py 2.9 KB

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