test_proxy-protocol-global-enabled.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. import socket
  2. def test_proxy_protocol_global_enabled_normal_request_fails(docker_compose, nginxproxy):
  3. try:
  4. r = nginxproxy.get(
  5. "http://proxy-protocol-global-enabled.nginx-proxy.tld/headers"
  6. )
  7. assert False
  8. except Exception as e:
  9. assert "Remote end closed connection without response" in str(e)
  10. def test_proxy_protocol_global_enabled_proto_request_works(docker_compose, nginxproxy):
  11. client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  12. client.connect((nginxproxy.get_ip(), 80))
  13. # 1.2.3.4 is the client IP
  14. # 4.3.2.1 is the proxy server IP
  15. # 8080 is the client port
  16. # 9090 is the proxy server port
  17. client.send(f"PROXY TCP4 1.2.3.4 4.3.2.1 8080 9090\r\n".encode("utf-8"))
  18. client.send(
  19. "GET /headers HTTP/1.1\r\nHost: proxy-protocol-global-enabled.nginx-proxy.tld\r\n\r\n".encode(
  20. "utf-8"
  21. )
  22. )
  23. response = client.recv(4096).decode("utf-8")
  24. assert "X-Forwarded-For: 1.2.3.4" in response
  25. assert "X-Forwarded-Port: 9090" in response