test_01_basic.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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
  30. from testenv import CurlClient
  31. log = logging.getLogger(__name__)
  32. class TestBasic:
  33. @pytest.fixture(autouse=True, scope='class')
  34. def _class_scope(self, env, nghttpx):
  35. if env.have_h3():
  36. nghttpx.start_if_needed()
  37. # simple http: GET
  38. def test_01_01_http_get(self, env: Env, httpd):
  39. curl = CurlClient(env=env)
  40. url = f'http://{env.domain1}:{env.http_port}/data.json'
  41. r = curl.http_get(url=url)
  42. r.check_response(http_status=200)
  43. assert r.json['server'] == env.domain1
  44. # simple https: GET, any http version
  45. @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason=f"curl without SSL")
  46. def test_01_02_https_get(self, env: Env, httpd):
  47. curl = CurlClient(env=env)
  48. url = f'https://{env.domain1}:{env.https_port}/data.json'
  49. r = curl.http_get(url=url)
  50. r.check_response(http_status=200)
  51. assert r.json['server'] == env.domain1
  52. # simple https: GET, h2 wanted and got
  53. @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason=f"curl without SSL")
  54. def test_01_03_h2_get(self, env: Env, httpd):
  55. curl = CurlClient(env=env)
  56. url = f'https://{env.domain1}:{env.https_port}/data.json'
  57. r = curl.http_get(url=url, extra_args=['--http2'])
  58. r.check_response(http_status=200, protocol='HTTP/2')
  59. assert r.json['server'] == env.domain1
  60. # simple https: GET, h2 unsupported, fallback to h1
  61. @pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason=f"curl without SSL")
  62. def test_01_04_h2_unsupported(self, env: Env, httpd):
  63. curl = CurlClient(env=env)
  64. url = f'https://{env.domain2}:{env.https_port}/data.json'
  65. r = curl.http_get(url=url, extra_args=['--http2'])
  66. r.check_response(http_status=200, protocol='HTTP/1.1')
  67. assert r.json['server'] == env.domain2
  68. # simple h3: GET, want h3 and get it
  69. @pytest.mark.skipif(condition=not Env.have_h3(), reason="h3 not supported")
  70. def test_01_05_h3_get(self, env: Env, httpd, nghttpx):
  71. curl = CurlClient(env=env)
  72. url = f'https://{env.domain1}:{env.h3_port}/data.json'
  73. r = curl.http_get(url=url, extra_args=['--http3'])
  74. r.check_response(http_status=200, protocol='HTTP/3')
  75. assert r.json['server'] == env.domain1