Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http/test_14_auth.py
2066 views
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
#***************************************************************************
4
# _ _ ____ _
5
# Project ___| | | | _ \| |
6
# / __| | | | |_) | |
7
# | (__| |_| | _ <| |___
8
# \___|\___/|_| \_\_____|
9
#
10
# Copyright (C) Daniel Stenberg, <[email protected]>, 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 os
29
import pytest
30
31
from testenv import Env, CurlClient
32
33
34
log = logging.getLogger(__name__)
35
36
37
class TestAuth:
38
39
@pytest.fixture(autouse=True, scope='class')
40
def _class_scope(self, env, httpd, nghttpx):
41
env.make_data_file(indir=env.gen_dir, fname="data-10m", fsize=10*1024*1024)
42
43
# download 1 file, not authenticated
44
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
45
def test_14_01_digest_get_noauth(self, env: Env, httpd, nghttpx, proto):
46
if proto == 'h3' and not env.have_h3():
47
pytest.skip("h3 not supported")
48
curl = CurlClient(env=env)
49
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
50
r = curl.http_download(urls=[url], alpn_proto=proto)
51
r.check_response(http_status=401)
52
53
# download 1 file, authenticated
54
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
55
def test_14_02_digest_get_auth(self, env: Env, httpd, nghttpx, proto):
56
if proto == 'h3' and not env.have_h3():
57
pytest.skip("h3 not supported")
58
curl = CurlClient(env=env)
59
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
60
r = curl.http_download(urls=[url], alpn_proto=proto, extra_args=[
61
'--digest', '--user', 'test:test'
62
])
63
r.check_response(http_status=200)
64
65
# PUT data, authenticated
66
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
67
def test_14_03_digest_put_auth(self, env: Env, httpd, nghttpx, proto):
68
if proto == 'h3' and not env.have_h3():
69
pytest.skip("h3 not supported")
70
if proto == 'h3' and env.curl_uses_ossl_quic():
71
pytest.skip("openssl-quic is flaky in retrying POST")
72
data='0123456789'
73
curl = CurlClient(env=env)
74
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
75
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
76
'--digest', '--user', 'test:test'
77
])
78
r.check_response(http_status=200)
79
80
# PUT data, digest auth large pw
81
@pytest.mark.parametrize("proto", ['h2', 'h3'])
82
def test_14_04_digest_large_pw(self, env: Env, httpd, nghttpx, proto):
83
if proto == 'h3' and not env.have_h3():
84
pytest.skip("h3 not supported")
85
data='0123456789'
86
password = 'x' * 65535
87
curl = CurlClient(env=env)
88
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
89
r = curl.http_upload(urls=[url], data=data, alpn_proto=proto, extra_args=[
90
'--digest', '--user', f'test:{password}',
91
'--trace-config', 'http/2,http/3'
92
])
93
# digest does not submit the password, but a hash of it, so all
94
# works and, since the pw is not correct, we get a 401
95
r.check_response(http_status=401)
96
97
# PUT data, basic auth large pw
98
@pytest.mark.parametrize("proto", ['h2', 'h3'])
99
def test_14_05_basic_large_pw(self, env: Env, httpd, nghttpx, proto):
100
if proto == 'h3' and not env.have_h3():
101
pytest.skip("h3 not supported")
102
if proto == 'h3' and not env.curl_uses_lib('ngtcp2'):
103
# See <https://github.com/cloudflare/quiche/issues/1573>
104
pytest.skip("quiche/openssl-quic have problems with large requests")
105
# just large enough that nghttp2 will submit
106
password = 'x' * (47 * 1024)
107
fdata = os.path.join(env.gen_dir, 'data-10m')
108
curl = CurlClient(env=env)
109
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
110
r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto, extra_args=[
111
'--basic', '--user', f'test:{password}',
112
'--trace-config', 'http/2,http/3'
113
])
114
# but apache denies on length limit
115
r.check_response(http_status=431)
116
117
# PUT data, basic auth with very large pw
118
@pytest.mark.parametrize("proto", ['h2', 'h3'])
119
def test_14_06_basic_very_large_pw(self, env: Env, httpd, nghttpx, proto):
120
if proto == 'h3' and not env.have_h3():
121
pytest.skip("h3 not supported")
122
if proto == 'h3' and env.curl_uses_lib('quiche'):
123
# See <https://github.com/cloudflare/quiche/issues/1573>
124
pytest.skip("quiche has problems with large requests")
125
password = 'x' * (64 * 1024)
126
fdata = os.path.join(env.gen_dir, 'data-10m')
127
curl = CurlClient(env=env)
128
url = f'https://{env.authority_for(env.domain1, proto)}/restricted/digest/data.json'
129
r = curl.http_upload(urls=[url], data=f'@{fdata}', alpn_proto=proto, extra_args=[
130
'--basic', '--user', f'test:{password}'
131
])
132
# Depending on protocol, we might have an error sending or
133
# the server might shutdown the connection and we see the error
134
# on receiving
135
assert r.exit_code in [55, 56, 95], f'{r.dump_logs()}'
136
137