test_01_basic.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #***************************************************************************
  4. # _ _ ____ _
  5. # Project ___| | | | _ \| |
  6. # / __| | | | |_) | |
  7. # | (__| |_| | _ <| |___
  8. # \___|\___/|_| \_\_____|
  9. #
  10. # Copyright (C) 2008 - 2022, 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. @pytest.mark.skipif(condition=Env.setup_incomplete(),
  33. reason=f"missing: {Env.incomplete_reason()}")
  34. class TestBasic:
  35. # simple http: GET
  36. def test_01_01_http_get(self, env: Env, httpd):
  37. curl = CurlClient(env=env)
  38. url = f'http://{env.domain1}:{env.http_port}/data.json'
  39. r = curl.http_get(url=url)
  40. assert r.exit_code == 0
  41. assert r.response['status'] == 200
  42. assert r.json['server'] == env.domain1
  43. # simple https: GET, any http version
  44. def test_01_02_https_get(self, env: Env, httpd):
  45. curl = CurlClient(env=env)
  46. url = f'https://{env.domain1}:{env.https_port}/data.json'
  47. r = curl.http_get(url=url)
  48. assert r.exit_code == 0
  49. assert r.response['status'] == 200
  50. assert r.json['server'] == env.domain1
  51. # simple https: GET, h2 wanted and got
  52. def test_01_02_h2_get(self, env: Env, httpd):
  53. curl = CurlClient(env=env)
  54. url = f'https://{env.domain1}:{env.https_port}/data.json'
  55. r = curl.http_get(url=url, extra_args=['--http2'])
  56. assert r.exit_code == 0
  57. assert r.response['status'] == 200
  58. assert r.response['protocol'] == 'HTTP/2'
  59. assert r.json['server'] == env.domain1
  60. # simple https: GET, h2 unsupported, fallback to h1
  61. def test_01_02_h2_unsupported(self, env: Env, httpd):
  62. curl = CurlClient(env=env)
  63. url = f'https://{env.domain2}:{env.https_port}/data.json'
  64. r = curl.http_get(url=url, extra_args=['--http2'])
  65. assert r.exit_code == 0
  66. assert r.response['status'] == 200
  67. assert r.response['protocol'] == 'HTTP/1.1'
  68. assert r.json['server'] == env.domain2
  69. # simple h3: GET, want h3 and get it
  70. @pytest.mark.skipif(condition=not Env.have_h3_curl(), reason="no h3 curl")
  71. @pytest.mark.skipif(condition=not Env.have_h3_server(), reason="no h3 server")
  72. def test_01_03_h3_get(self, env: Env, httpd, nghttpx):
  73. curl = CurlClient(env=env)
  74. url = f'https://{env.domain1}:{env.h3_port}/data.json'
  75. r = curl.http_get(url=url, extra_args=['--http3'])
  76. assert r.exit_code == 0, f'{r}'
  77. assert r.response['status'] == 200
  78. assert r.response['protocol'] == 'HTTP/3'
  79. assert r.json['server'] == env.domain1