2
0

test_14_auth.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. httpd.clear_extra_configs()
  40. httpd.reload()
  41. # download 1 file, not authenticated
  42. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  43. def test_14_01_digest_get_noauth(self, env: Env, httpd, nghttpx, repeat, proto):
  44. if proto == 'h3' and not env.have_h3():
  45. pytest.skip("h3 not supported")
  46. curl = CurlClient(env=env)
  47. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  48. r = curl.http_download(urls=[url], alpn_proto=proto)
  49. r.check_response(http_status=401)
  50. # download 1 file, authenticated
  51. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  52. def test_14_02_digest_get_auth(self, env: Env, httpd, nghttpx, repeat, proto):
  53. if proto == 'h3' and not env.have_h3():
  54. pytest.skip("h3 not supported")
  55. curl = CurlClient(env=env)
  56. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  57. r = curl.http_download(urls=[url], alpn_proto=proto, extra_args=[
  58. '--digest', '--user', 'test:test'
  59. ])
  60. r.check_response(http_status=200)
  61. # PUT data, authenticated
  62. @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
  63. def test_14_03_digest_put_auth(self, env: Env, httpd, nghttpx, repeat, proto):
  64. if proto == 'h3' and not env.have_h3():
  65. pytest.skip("h3 not supported")
  66. data='0123456789'
  67. curl = CurlClient(env=env)
  68. url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
  69. r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
  70. '--digest', '--user', 'test:test'
  71. ])
  72. r.check_response(http_status=200)