Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/external/curl/tests/http/test_06_eyeballs.py
2659 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 re
29
import pytest
30
31
from testenv import Env, CurlClient
32
33
34
log = logging.getLogger(__name__)
35
36
37
class TestEyeballs:
38
39
# download using only HTTP/3 on working server
40
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
41
def test_06_01_h3_only(self, env: Env, httpd, nghttpx):
42
curl = CurlClient(env=env)
43
urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
44
r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
45
r.check_response(count=1, http_status=200)
46
assert r.stats[0]['http_version'] == '3'
47
48
# download using only HTTP/3 on missing server
49
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
50
def test_06_02_h3_only(self, env: Env, httpd, nghttpx):
51
curl = CurlClient(env=env)
52
urln = f'https://{env.domain1}:{env.https_only_tcp_port}/data.json'
53
r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
54
r.check_response(exitcode=7, http_status=None)
55
56
# download using HTTP/3 on missing server with fallback on h2
57
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
58
def test_06_03_h3_fallback_h2(self, env: Env, httpd, nghttpx):
59
curl = CurlClient(env=env)
60
urln = f'https://{env.domain1}:{env.https_only_tcp_port}/data.json'
61
r = curl.http_download(urls=[urln], extra_args=['--http3'])
62
r.check_response(count=1, http_status=200)
63
assert r.stats[0]['http_version'] == '2'
64
65
# download using HTTP/3 on missing server with fallback on http/1.1
66
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
67
def test_06_04_h3_fallback_h1(self, env: Env, httpd, nghttpx):
68
curl = CurlClient(env=env)
69
urln = f'https://{env.domain2}:{env.https_only_tcp_port}/data.json'
70
r = curl.http_download(urls=[urln], extra_args=['--http3'])
71
r.check_response(count=1, http_status=200)
72
assert r.stats[0]['http_version'] == '1.1'
73
74
# make a successful https: transfer and observer the timer stats
75
def test_06_10_stats_success(self, env: Env, httpd, nghttpx):
76
curl = CurlClient(env=env)
77
urln = f'https://{env.authority_for(env.domain1, "h2")}/data.json'
78
r = curl.http_download(urls=[urln])
79
r.check_response(count=1, http_status=200)
80
assert r.stats[0]['time_connect'] > 0.0
81
assert r.stats[0]['time_appconnect'] > 0.0
82
83
# make https: to a hostname that tcp connects, but will not verify
84
def test_06_11_stats_fail_verify(self, env: Env, httpd, nghttpx):
85
curl = CurlClient(env=env)
86
urln = f'https://not-valid.com:{env.https_port}/data.json'
87
r = curl.http_download(urls=[urln], extra_args=[
88
'--resolve', f'not-valid.com:{env.https_port}:127.0.0.1'
89
])
90
r.check_response(count=1, http_status=0, exitcode=False)
91
assert r.stats[0]['time_connect'] > 0.0 # was tcp connected
92
assert r.stats[0]['time_appconnect'] == 0 # but not SSL verified
93
94
# make https: to an invalid address
95
def test_06_12_stats_fail_tcp(self, env: Env, httpd, nghttpx):
96
curl = CurlClient(env=env)
97
urln = 'https://not-valid.com:1/data.json'
98
r = curl.http_download(urls=[urln], extra_args=[
99
'--resolve', f'not-valid.com:{1}:127.0.0.1'
100
])
101
r.check_response(count=1, http_status=None, exitcode=False)
102
assert r.stats[0]['time_connect'] == 0 # no one should have listened
103
assert r.stats[0]['time_appconnect'] == 0 # did not happen either
104
105
# check timers when trying 3 unresponsive addresses
106
@pytest.mark.skipif(condition=not Env.curl_has_feature('IPv6'),
107
reason='curl lacks ipv6 support')
108
@pytest.mark.skipif(condition=not Env.curl_is_verbose(), reason="needs curl verbose strings")
109
def test_06_13_timers(self, env: Env):
110
curl = CurlClient(env=env)
111
# ipv6 0100::/64 is supposed to go into the void (rfc6666)
112
r = curl.http_download(urls=['https://xxx.invalid/'], extra_args=[
113
'--resolve', 'xxx.invalid:443:0100::1,0100::2,0100::3',
114
'--connect-timeout', '1',
115
'--happy-eyeballs-timeout-ms', '123',
116
'--trace-config', 'timer,happy-eyeballs,tcp'
117
])
118
r.check_response(count=1, http_status=None, exitcode=False)
119
assert r.stats[0]['time_connect'] == 0 # no one connected
120
# check that we indeed started attempts on all 3 addresses
121
tcp_attempts = [line for line in r.trace_lines
122
if re.match(r'.*Trying \[100::[123]]:443', line)]
123
assert len(tcp_attempts) == 3, f'fond: {"".join(tcp_attempts)}\n{r.dump_logs()}'
124
# if the 0100::/64 really goes into the void, we should see 2 HAPPY_EYEBALLS
125
# timeouts being set here
126
failed_attempts = [line for line in r.trace_lines
127
if re.match(r'.*checked connect attempts: 0 ongoing', line)]
128
if len(failed_attempts):
129
# github CI fails right away with "Network is unreachable", slackers...
130
assert len(failed_attempts) == 3, f'found: {"".join(failed_attempts)}\n{r.dump_logs()}'
131
else:
132
# no immediately failed attempts, as should be
133
he_timers_set = [line for line in r.trace_lines
134
if re.match(r'.*\[TIMER] \[HAPPY_EYEBALLS] set for', line)]
135
assert len(he_timers_set) == 2, f'found: {"".join(he_timers_set)}\n{r.dump_logs()}'
136
137