test_06_eyeballs.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 pytest
  29. from testenv import Env, CurlClient
  30. log = logging.getLogger(__name__)
  31. class TestEyeballs:
  32. @pytest.fixture(autouse=True, scope='class')
  33. def _class_scope(self, env, httpd, nghttpx):
  34. if env.have_h3():
  35. nghttpx.start_if_needed()
  36. httpd.clear_extra_configs()
  37. httpd.reload()
  38. # download using only HTTP/3 on working server
  39. @pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
  40. def test_06_01_h3_only(self, env: Env, httpd, nghttpx, repeat):
  41. curl = CurlClient(env=env)
  42. urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
  43. r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
  44. r.check_response(count=1, http_status=200)
  45. assert r.stats[0]['http_version'] == '3'
  46. # download using only HTTP/3 on missing server
  47. @pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
  48. def test_06_02_h3_only(self, env: Env, httpd, nghttpx, repeat):
  49. nghttpx.stop_if_running()
  50. curl = CurlClient(env=env)
  51. urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
  52. r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
  53. r.check_response(exitcode=7, http_status=None)
  54. # download using HTTP/3 on missing server with fallback on h2
  55. @pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
  56. def test_06_03_h3_fallback_h2(self, env: Env, httpd, nghttpx, repeat):
  57. nghttpx.stop_if_running()
  58. curl = CurlClient(env=env)
  59. urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
  60. r = curl.http_download(urls=[urln], extra_args=['--http3'])
  61. r.check_response(count=1, http_status=200)
  62. assert r.stats[0]['http_version'] == '2'
  63. # download using HTTP/3 on missing server with fallback on http/1.1
  64. @pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
  65. def test_06_04_h3_fallback_h1(self, env: Env, httpd, nghttpx, repeat):
  66. nghttpx.stop_if_running()
  67. curl = CurlClient(env=env)
  68. urln = f'https://{env.authority_for(env.domain2, "h3")}/data.json'
  69. r = curl.http_download(urls=[urln], extra_args=['--http3'])
  70. r.check_response(count=1, http_status=200)
  71. assert r.stats[0]['http_version'] == '1.1'
  72. # make a successful https: transfer and observer the timer stats
  73. def test_06_10_stats_success(self, env: Env, httpd, nghttpx, repeat):
  74. curl = CurlClient(env=env)
  75. urln = f'https://{env.authority_for(env.domain1, "h2")}/data.json'
  76. r = curl.http_download(urls=[urln])
  77. r.check_response(count=1, http_status=200)
  78. assert r.stats[0]['time_connect'] > 0.0
  79. assert r.stats[0]['time_appconnect'] > 0.0
  80. # make https: to a hostname that tcp connects, but will not verify
  81. def test_06_11_stats_fail_verify(self, env: Env, httpd, nghttpx, repeat):
  82. curl = CurlClient(env=env)
  83. urln = f'https://not-valid.com:{env.https_port}/data.json'
  84. r = curl.http_download(urls=[urln], extra_args=[
  85. '--resolve', f'not-valid.com:{env.https_port}:127.0.0.1'
  86. ])
  87. r.check_response(count=1, http_status=0, exitcode=False)
  88. assert r.stats[0]['time_connect'] > 0.0 # was tcp connected
  89. assert r.stats[0]['time_appconnect'] == 0 # but not SSL verified
  90. # make https: to an invalid address
  91. def test_06_12_stats_fail_tcp(self, env: Env, httpd, nghttpx, repeat):
  92. curl = CurlClient(env=env)
  93. urln = 'https://not-valid.com:1/data.json'
  94. r = curl.http_download(urls=[urln], extra_args=[
  95. '--resolve', f'not-valid.com:{1}:127.0.0.1'
  96. ])
  97. r.check_response(count=1, http_status=None, exitcode=False)
  98. assert r.stats[0]['time_connect'] == 0 # no one should have listened
  99. assert r.stats[0]['time_appconnect'] == 0 # did not happen either