2
0

test_14_auth.py 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 difflib
  28. import filecmp
  29. import logging
  30. import os
  31. import pytest
  32. from testenv import Env, CurlClient, LocalClient
  33. log = logging.getLogger(__name__)
  34. class TestAuth:
  35. @pytest.fixture(autouse=True, scope='class')
  36. def _class_scope(self, env, httpd, nghttpx):
  37. if env.have_h3():
  38. nghttpx.start_if_needed()
  39. env.make_data_file(indir=env.gen_dir, fname="data-10m", fsize=10*1024*1024)
  40. httpd.clear_extra_configs()
  41. httpd.reload()
  42. # download 1 file, not authenticated
  43. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  44. def test_14_01_digest_get_noauth(self, env: Env, httpd, nghttpx, repeat, proto):
  45. if proto == 'h3' and not env.have_h3():
  46. pytest.skip("h3 not supported")
  47. curl = CurlClient(env=env)
  48. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  49. r = curl.http_download(urls=[url], alpn_proto=proto)
  50. r.check_response(http_status=401)
  51. # download 1 file, authenticated
  52. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  53. def test_14_02_digest_get_auth(self, env: Env, httpd, nghttpx, repeat, proto):
  54. if proto == 'h3' and not env.have_h3():
  55. pytest.skip("h3 not supported")
  56. curl = CurlClient(env=env)
  57. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  58. r = curl.http_download(urls=[url], alpn_proto=proto, extra_args=[
  59. '--digest', '--user', 'test:test'
  60. ])
  61. r.check_response(http_status=200)
  62. # PUT data, authenticated
  63. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  64. def test_14_03_digest_put_auth(self, env: Env, httpd, nghttpx, repeat, proto):
  65. if proto == 'h3' and not env.have_h3():
  66. pytest.skip("h3 not supported")
  67. data='0123456789'
  68. curl = CurlClient(env=env)
  69. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  70. r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
  71. '--digest', '--user', 'test:test'
  72. ])
  73. r.check_response(http_status=200)
  74. # PUT data, digest auth large pw
  75. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  76. def test_14_04_digest_large_pw(self, env: Env, httpd, nghttpx, repeat, proto):
  77. if proto == 'h3' and not env.have_h3():
  78. pytest.skip("h3 not supported")
  79. data='0123456789'
  80. password = 'x' * 65535
  81. curl = CurlClient(env=env)
  82. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  83. r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
  84. '--digest', '--user', f'test:{password}',
  85. '--trace-config', 'http/2,http/3'
  86. ])
  87. # digest does not submit the password, but a hash of it, so all
  88. # works and, since the pw is not correct, we get a 401
  89. r.check_response(http_status=401)
  90. # PUT data, basic auth large pw
  91. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  92. def test_14_05_basic_large_pw(self, env: Env, httpd, nghttpx, repeat, proto):
  93. if proto == 'h3' and not env.have_h3():
  94. pytest.skip("h3 not supported")
  95. if proto == 'h3' and env.curl_uses_lib('quiche'):
  96. # See <https://github.com/cloudflare/quiche/issues/1573>
  97. pytest.skip("quiche has problems with large requests")
  98. # just large enough that nghttp2 will submit
  99. password = 'x' * (47 * 1024)
  100. fdata = os.path.join(env.gen_dir, 'data-10m')
  101. curl = CurlClient(env=env)
  102. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  103. r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto, extra_args=[
  104. '--basic', '--user', f'test:{password}',
  105. '--trace-config', 'http/2,http/3'
  106. ])
  107. # but apache denies on length limit
  108. r.check_response(http_status=431)
  109. # PUT data, basic auth with very large pw
  110. @pytest.mark.parametrize("proto", ['h2', 'h3'])
  111. def test_14_06_basic_very_large_pw(self, env: Env, httpd, nghttpx, repeat, proto):
  112. if proto == 'h3' and not env.have_h3():
  113. pytest.skip("h3 not supported")
  114. if proto == 'h3' and env.curl_uses_lib('quiche'):
  115. # See <https://github.com/cloudflare/quiche/issues/1573>
  116. pytest.skip("quiche has problems with large requests")
  117. password = 'x' * (64 * 1024)
  118. fdata = os.path.join(env.gen_dir, 'data-10m')
  119. curl = CurlClient(env=env)
  120. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  121. r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto, extra_args=[
  122. '--basic', '--user', f'test:{password}'
  123. ])
  124. # request was never sent
  125. r.check_response(exitcode=55, http_status=0)