acceptance.sh 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/bash
  2. # test against first argument or search first file matching "leproxy*.php"
  3. bin=${1:-$(ls -b leproxy*.php | head -n1 || echo leproxy.php)}
  4. echo "Testing $bin"
  5. # test command line arguments
  6. out=$(php $bin --version) && echo -n "OK (" && echo -n $out && echo ")" || (echo "FAIL: $out" && exit 1) || exit 1
  7. out=$(php $bin --help) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  8. out=$(php $bin -h) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  9. out=$(php $bin --unknown 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  10. out=$(php $bin --unknown 2>&1 || true) && echo "$out" | grep -q "see --help" && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  11. out=$(php $bin invalid 2>&1 || true) && echo "$out" | grep -q "see --help" && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  12. out=$(php $bin 8080 2>&1 || true) && echo "$out" | grep -q "see --help" && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  13. out=$(php $bin user:pass@[::] --allow-unprotected 2>&1 || true) && echo "$out" | grep -q "see --help" && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  14. out=$(php $bin --block=http:// 2>&1 || true) && echo "$out" | grep -q "see --help" && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  15. out=$(php $bin --proxy= 2>&1 || true) && echo "$out" | grep -q "see --help" && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  16. out=$(php $bin --proxy=tcp://host/ 2>&1 || true) && echo "$out" | grep -q "see --help" && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  17. killall php 2>&- 1>&- || true
  18. php $bin 127.0.0.1:8180 --no-log &
  19. sleep 2
  20. out=$(curl -v --head --silent --fail http://localhost:8180/pac 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  21. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://127.0.0.1:8180/pac 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  22. out=$(curl -v --head --silent --fail --proxy http://localhost:8180 http://localhost:8180/pac 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  23. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  24. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 --location http://github.com 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  25. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  26. out=$(curl -v --head --silent --fail --proxy socks4a://127.0.0.1:8180 --location http://github.com 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  27. # ensure we can receive multiple "Set-Cookie" headers
  28. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 "http://httpbin.org/cookies/set?k2=v2&k1=v1" 2>&1) && (echo "$out" | grep -q "Set-Cookie: k2=v2;" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  29. # unneeded authentication should work
  30. out=$(curl -v --head --silent --fail --proxy http://user:pass@127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  31. out=$(curl -v --head --silent --fail --proxy socks5h://user:pass@127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  32. # invalid URIs should return error
  33. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://test.invalid/test 2>&1) && echo "FAIL: $out" && exit 1 || (echo "$out" | grep -q "502 Bad Gateway" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  34. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://test.invalid/test 2>&1) && echo "FAIL: $out" && exit 1 || (echo "$out" | grep -q "502 Bad Gateway" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  35. out=$(curl -v --head --silent --fail --proxy socks://127.0.0.1:8180 http://test.invalid/test 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  36. # restart LeProxy with really short timeout to ensure timeout error
  37. killall php 2>&- 1>&- || true
  38. php -d default_socket_timeout=0.001 $bin 127.0.0.1:8180 --no-log &
  39. sleep 2
  40. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://www.youtube.com 2>&1) && echo "FAIL: $out" && exit 1 || (echo "$out" | grep -q "504 Gateway Time-out" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  41. # restart LeProxy on IPv6 address unless we're on Travis (does not support IPv6)
  42. if [ -z "$TRAVIS" ]
  43. then
  44. killall php 2>&- 1>&- || true
  45. php $bin [::]:8180 --no-log &
  46. sleep 2
  47. out=$(curl -v --head --silent --fail --proxy http://[::1]:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  48. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  49. out=$(curl -v --head --silent --fail --proxy http://[::1]:8180 http://[::1]:8180/pac 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  50. out=$(curl -v --head --silent --fail --proxy socks://[::1]:8180 -4 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  51. out=$(curl -v --head --silent --fail --proxy socks://127.0.0.1:8180 -4 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  52. out=$(curl -v --head --silent --fail --proxy socks5://[::1]:8180 http://[::1]:8180/pac 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  53. fi
  54. # restart LeProxy with hosts and plain HTTP port blocked
  55. killall php 2>&- 1>&- || true
  56. php $bin 127.0.0.1:8180 --block=youtube.com --block=*.google.com --block=*:80 --no-log &
  57. sleep 2
  58. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://youtube.com 2>&1) && echo "FAIL: $out" && exit 1 || (echo "$out" | grep -q "403 Forbidden" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  59. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 https://youtube.com 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  60. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://www.google.com 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  61. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 https://www.google.com 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  62. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://youtube.com 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  63. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 http://www.google.com 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  64. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://google.de 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  65. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 http://www.google.de 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  66. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://www.youtube.com 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  67. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 https://www.youtube.com 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  68. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://google.de 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  69. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 https://google.de 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  70. # restart LeProxy with hosts file and plain HTTP port blocked
  71. killall php 2>&- 1>&- || true
  72. php $bin 127.0.0.1:8180 --block-hosts=tests/hosts-google --no-log &
  73. sleep 2
  74. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://google.com 2>&1) && echo "FAIL: $out" && exit 1 || (echo "$out" | grep -q "403 Forbidden" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  75. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://maps.google.com 2>&1) && echo "FAIL: $out" && exit 1 || (echo "$out" | grep -q "403 Forbidden" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  76. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 https://google.de 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  77. # restart LeProxy on Unix domain socket path and another LeProxy instance for chaining
  78. killall php 2>&- 1>&- || true
  79. php $bin ./leproxy.tmp.socket --no-log &
  80. pid=$!
  81. php $bin :8180 --proxy ./leproxy.tmp.socket --no-log &
  82. sleep 2
  83. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  84. kill $pid && rm leproxy.tmp.socket && echo . || (echo "FAIL" && exit 1) || exit 1
  85. # restart LeProxy with authentication required
  86. killall php 2>&- 1>&- || true
  87. php $bin user:pass@127.0.0.1:8180 --no-log &
  88. sleep 2
  89. # authentication should work
  90. out=$(curl -v --head --silent --fail --proxy http://user:pass@127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  91. out=$(curl -v --head --silent --fail --proxy socks5h://user:pass@127.0.0.1:8180 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  92. # invalid authentication should return error
  93. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8180 http://reactphp.org 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  94. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8180 http://reactphp.org 2>&1) && echo "FAIL: $out" && exit 1 || echo OK
  95. # start another LeProxy instance for HTTP proxy chaining / nesting
  96. php $bin 127.0.0.1:8181 --proxy=http://user:pass@127.0.0.1:8180 --no-log &
  97. sleep 2
  98. # client does not need authentication because first chain passes to next via HTTP
  99. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8181 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  100. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8181 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  101. # start another LeProxy instance for SOCKS proxy chaining / nesting
  102. php $bin 127.0.0.1:8182 --proxy=socks://user:pass@127.0.0.1:8180 --no-log &
  103. sleep 2
  104. # client does not need authentication because first chain passes to next via SOCKS
  105. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8182 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  106. out=$(curl -v --head --silent --fail --proxy socks5h://127.0.0.1:8182 http://reactphp.org 2>&1) && echo OK || (echo "FAIL: $out" && exit 1) || exit 1
  107. # start another LeProxy instance for invalid HTTP proxy chaining / nesting
  108. php $bin 127.0.0.1:8183 --proxy=http://user:invalid@127.0.0.1:8180 --no-log &
  109. sleep 2
  110. # client does not need authentication because first chain passes to next via HTTP
  111. out=$(curl -v --head --silent --fail --proxy http://127.0.0.1:8183 https://youtube.com 2>&1) && echo "FAIL: $out" && exit 1 || (echo "$out" | grep -q "502 Bad Gateway" && echo OK) || (echo "FAIL: $out" && exit 1) || exit 1
  112. killall php 2>&- 1>&- || true
  113. echo DONE