test_06_eyeballs.py 5.0 KB

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