test_08_caddy.py 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #***************************************************************************
  4. # _ _ ____ _
  5. # Project ___| | | | _ \| |
  6. # / __| | | | |_) | |
  7. # | (__| |_| | _ <| |___
  8. # \___|\___/|_| \_\_____|
  9. #
  10. # Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  11. #
  12. # This software is licensed as described in the file COPYING, which
  13. # you should have received as part of this distribution. The terms
  14. # are also available at https://curl.se/docs/copyright.html.
  15. #
  16. # You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. # copies of the Software, and permit persons to whom the Software is
  18. # furnished to do so, under the terms of the COPYING file.
  19. #
  20. # This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. # KIND, either express or implied.
  22. #
  23. # SPDX-License-Identifier: curl
  24. #
  25. ###########################################################################
  26. #
  27. import logging
  28. import os
  29. import pytest
  30. from testenv import Env, CurlClient, Caddy
  31. log = logging.getLogger(__name__)
  32. @pytest.mark.skipif(condition=not Env.has_caddy(), reason=f"missing caddy")
  33. @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason=f"curl without SSL")
  34. class TestCaddy:
  35. @pytest.fixture(autouse=True, scope='class')
  36. def caddy(self, env):
  37. caddy = Caddy(env=env)
  38. assert caddy.start()
  39. yield caddy
  40. caddy.stop()
  41. def _make_docs_file(self, docs_dir: str, fname: str, fsize: int):
  42. fpath = os.path.join(docs_dir, fname)
  43. data1k = 1024*'x'
  44. flen = 0
  45. with open(fpath, 'w') as fd:
  46. while flen < fsize:
  47. fd.write(data1k)
  48. flen += len(data1k)
  49. return flen
  50. @pytest.fixture(autouse=True, scope='class')
  51. def _class_scope(self, env, caddy):
  52. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data1.data', fsize=1024*1024)
  53. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data5.data', fsize=5*1024*1024)
  54. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data10.data', fsize=10*1024*1024)
  55. self._make_docs_file(docs_dir=caddy.docs_dir, fname='data100.data', fsize=100*1024*1024)
  56. env.make_data_file(indir=env.gen_dir, fname="data-10m", fsize=10*1024*1024)
  57. # download 1 file
  58. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  59. def test_08_01_download_1(self, env: Env, caddy: Caddy, repeat, proto):
  60. if proto == 'h3' and not env.have_h3_curl():
  61. pytest.skip("h3 not supported in curl")
  62. if proto == 'h3' and env.curl_uses_lib('msh3'):
  63. pytest.skip("msh3 itself crashes")
  64. curl = CurlClient(env=env)
  65. url = f'https://{env.domain1}:{caddy.port}/data.json'
  66. r = curl.http_download(urls=[url], alpn_proto=proto)
  67. r.check_response(count=1, http_status=200)
  68. # download 1MB files sequentially
  69. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  70. def test_08_02_download_1mb_sequential(self, env: Env, caddy: Caddy,
  71. repeat, proto):
  72. if proto == 'h3' and not env.have_h3_curl():
  73. pytest.skip("h3 not supported in curl")
  74. if proto == 'h3' and env.curl_uses_lib('msh3'):
  75. pytest.skip("msh3 itself crashes")
  76. count = 50
  77. curl = CurlClient(env=env)
  78. urln = f'https://{env.domain1}:{caddy.port}/data1.data?[0-{count-1}]'
  79. r = curl.http_download(urls=[urln], alpn_proto=proto)
  80. r.check_response(count=count, http_status=200, connect_count=1)
  81. # download 1MB files parallel
  82. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  83. def test_08_03_download_1mb_parallel(self, env: Env, caddy: Caddy,
  84. repeat, proto):
  85. if proto == 'h3' and not env.have_h3_curl():
  86. pytest.skip("h3 not supported in curl")
  87. if proto == 'h3' and env.curl_uses_lib('msh3'):
  88. pytest.skip("msh3 itself crashes")
  89. count = 20
  90. curl = CurlClient(env=env)
  91. urln = f'https://{env.domain1}:{caddy.port}/data1.data?[0-{count-1}]'
  92. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  93. '--parallel'
  94. ])
  95. r.check_response(count=count, http_status=200)
  96. if proto == 'http/1.1':
  97. # http/1.1 parallel transfers will open multiple connections
  98. assert r.total_connects > 1, r.dump_logs()
  99. else:
  100. assert r.total_connects == 1, r.dump_logs()
  101. # download 5MB files sequentially
  102. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  103. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  104. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  105. def test_08_04a_download_10mb_sequential(self, env: Env, caddy: Caddy,
  106. repeat, proto):
  107. if proto == 'h3' and not env.have_h3_curl():
  108. pytest.skip("h3 not supported in curl")
  109. if proto == 'h3' and env.curl_uses_lib('msh3'):
  110. pytest.skip("msh3 itself crashes")
  111. count = 40
  112. curl = CurlClient(env=env)
  113. urln = f'https://{env.domain1}:{caddy.port}/data5.data?[0-{count-1}]'
  114. r = curl.http_download(urls=[urln], alpn_proto=proto)
  115. r.check_response(count=count, http_status=200, connect_count=1)
  116. # download 10MB files sequentially
  117. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  118. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  119. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  120. def test_08_04b_download_10mb_sequential(self, env: Env, caddy: Caddy,
  121. repeat, proto):
  122. if proto == 'h3' and not env.have_h3_curl():
  123. pytest.skip("h3 not supported in curl")
  124. if proto == 'h3' and env.curl_uses_lib('msh3'):
  125. pytest.skip("msh3 itself crashes")
  126. count = 20
  127. curl = CurlClient(env=env)
  128. urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
  129. r = curl.http_download(urls=[urln], alpn_proto=proto)
  130. r.check_response(count=count, http_status=200, connect_count=1)
  131. # download 10MB files parallel
  132. @pytest.mark.skipif(condition=Env().slow_network, reason="not suitable for slow network tests")
  133. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  134. @pytest.mark.skipif(condition=Env().ci_run, reason="not suitable for CI runs")
  135. def test_08_05_download_1mb_parallel(self, env: Env, caddy: Caddy,
  136. repeat, proto):
  137. if proto == 'h3' and not env.have_h3_curl():
  138. pytest.skip("h3 not supported in curl")
  139. if proto == 'h3' and env.curl_uses_lib('msh3'):
  140. pytest.skip("msh3 itself crashes")
  141. if proto == 'http/1.1' and env.curl_uses_lib('mbedtls'):
  142. pytest.skip("mbedtls 3.6.0 fails on 50 connections with: "\
  143. "ssl_handshake returned: (-0x7F00) SSL - Memory allocation failed")
  144. count = 50
  145. curl = CurlClient(env=env)
  146. urln = f'https://{env.domain1}:{caddy.port}/data10.data?[0-{count-1}]'
  147. r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
  148. '--parallel'
  149. ])
  150. r.check_response(count=count, http_status=200)
  151. if proto == 'http/1.1':
  152. # http/1.1 parallel transfers will open multiple connections
  153. assert r.total_connects > 1, r.dump_logs()
  154. else:
  155. assert r.total_connects == 1, r.dump_logs()
  156. # post data parallel, check that they were echoed
  157. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  158. def test_08_06_post_parallel(self, env: Env, httpd, caddy, repeat, proto):
  159. if proto == 'h3' and not env.have_h3():
  160. pytest.skip("h3 not supported")
  161. if proto == 'h3' and env.curl_uses_lib('msh3'):
  162. pytest.skip("msh3 stalls here")
  163. # limit since we use a separate connection in h1
  164. count = 20
  165. data = '0123456789'
  166. curl = CurlClient(env=env)
  167. url = f'https://{env.domain2}:{caddy.port}/curltest/echo?id=[0-{count-1}]'
  168. r = curl.http_upload(urls=[url], data=data, alpn_proto=proto,
  169. extra_args=['--parallel'])
  170. r.check_stats(count=count, http_status=200, exitcode=0)
  171. for i in range(0,count):
  172. respdata = open(curl.response_file(i)).readlines()
  173. assert respdata == [data]
  174. # put large file, check that they length were echoed
  175. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  176. def test_08_07_put_large(self, env: Env, httpd, caddy, repeat, proto):
  177. if proto == 'h3' and not env.have_h3():
  178. pytest.skip("h3 not supported")
  179. if proto == 'h3' and env.curl_uses_lib('msh3'):
  180. pytest.skip("msh3 stalls here")
  181. # limit since we use a separate connection in h1<
  182. count = 1
  183. fdata = os.path.join(env.gen_dir, 'data-10m')
  184. curl = CurlClient(env=env)
  185. url = f'https://{env.domain2}:{caddy.port}/curltest/put?id=[0-{count-1}]'
  186. r = curl.http_put(urls=[url], fdata=fdata, alpn_proto=proto)
  187. exp_data = [f'{os.path.getsize(fdata)}']
  188. r.check_response(count=count, http_status=200)
  189. for i in range(count):
  190. respdata = open(curl.response_file(i)).readlines()
  191. assert respdata == exp_data