Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http/test_05_errors.py
2645 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 pytest
29
30
from testenv import Env, CurlClient
31
32
33
log = logging.getLogger(__name__)
34
35
36
@pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.55'),
37
reason=f"httpd version too old for this: {Env.httpd_version()}")
38
class TestErrors:
39
40
# download 1 file, check that we get CURLE_PARTIAL_FILE
41
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
42
def test_05_01_partial_1(self, env: Env, httpd, nghttpx, proto):
43
if proto == 'h3' and not env.have_h3():
44
pytest.skip("h3 not supported")
45
count = 1
46
curl = CurlClient(env=env)
47
urln = f'https://{env.authority_for(env.domain1, proto)}' \
48
f'/curltest/tweak?id=[0-{count - 1}]'\
49
'&chunks=3&chunk_size=16000&body_error=reset'
50
r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
51
'--retry', '0'
52
])
53
r.check_exit_code(False)
54
invalid_stats = []
55
for idx, s in enumerate(r.stats):
56
if 'exitcode' not in s or s['exitcode'] not in [18, 56, 92, 95]:
57
invalid_stats.append(f'request {idx} exit with {s["exitcode"]}')
58
assert len(invalid_stats) == 0, f'failed: {invalid_stats}'
59
60
# download files, check that we get CURLE_PARTIAL_FILE for all
61
@pytest.mark.parametrize("proto", ['h2', 'h3'])
62
def test_05_02_partial_20(self, env: Env, httpd, nghttpx, proto):
63
if proto == 'h3' and not env.have_h3():
64
pytest.skip("h3 not supported")
65
if proto == 'h3' and env.curl_uses_ossl_quic():
66
pytest.skip("openssl-quic is flaky in yielding proper error codes")
67
count = 20
68
curl = CurlClient(env=env)
69
urln = f'https://{env.authority_for(env.domain1, proto)}' \
70
f'/curltest/tweak?id=[0-{count - 1}]'\
71
'&chunks=5&chunk_size=16000&body_error=reset'
72
r = curl.http_download(urls=[urln], alpn_proto=proto, extra_args=[
73
'--retry', '0', '--parallel',
74
])
75
r.check_exit_code(False)
76
assert len(r.stats) == count, f'did not get all stats: {r}'
77
invalid_stats = []
78
for idx, s in enumerate(r.stats):
79
if 'exitcode' not in s or s['exitcode'] not in [18, 55, 56, 92, 95]:
80
invalid_stats.append(f'request {idx} exit with {s["exitcode"]}\n{s}')
81
assert len(invalid_stats) == 0, f'failed: {invalid_stats}'
82
83
# access a resource that, on h2, RST the stream with HTTP_1_1_REQUIRED
84
def test_05_03_required(self, env: Env, httpd, nghttpx):
85
curl = CurlClient(env=env)
86
proto = 'http/1.1'
87
urln = f'https://{env.authority_for(env.domain1, proto)}/curltest/1_1'
88
r = curl.http_download(urls=[urln], alpn_proto=proto)
89
r.check_exit_code(0)
90
r.check_response(http_status=200, count=1)
91
proto = 'h2'
92
urln = f'https://{env.authority_for(env.domain1, proto)}/curltest/1_1'
93
r = curl.http_download(urls=[urln], alpn_proto=proto)
94
r.check_exit_code(0)
95
r.check_response(http_status=200, count=1)
96
# check that we did a downgrade
97
assert r.stats[0]['http_version'] == '1.1', r.dump_logs()
98
99
# On the URL used here, Apache is doing an "unclean" TLS shutdown,
100
# meaning it sends no shutdown notice and just closes TCP.
101
# The HTTP response delivers a body without Content-Length. We expect:
102
# - http/1.0 to fail since it relies on a clean connection close to
103
# detect the end of the body
104
# - http/1.1 to work since it will used "chunked" transfer encoding
105
# and stop receiving when that signals the end
106
# - h2 to work since it will signal the end of the response before
107
# and not see the "unclean" close either
108
@pytest.mark.parametrize("proto", ['http/1.0', 'http/1.1', 'h2'])
109
def test_05_04_unclean_tls_shutdown(self, env: Env, httpd, nghttpx, proto):
110
if proto == 'h3' and not env.have_h3():
111
pytest.skip("h3 not supported")
112
count = 10 if proto == 'h2' else 1
113
curl = CurlClient(env=env)
114
url = f'https://{env.authority_for(env.domain1, proto)}'\
115
f'/curltest/shutdown_unclean?id=[0-{count-1}]&chunks=4'
116
r = curl.http_download(urls=[url], alpn_proto=proto, extra_args=[
117
'--parallel', '--trace-config', 'ssl'
118
])
119
if proto == 'http/1.0':
120
# we are inconsistent if we fail or not in missing TLS shutdown
121
# openssl code ignore such errors intentionally in non-debug builds
122
r.check_exit_code(56)
123
else:
124
r.check_exit_code(0)
125
r.check_response(http_status=200, count=count)
126
127