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
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 pytest
29
30
from testenv import Env, CurlClient
31
32
33
log = logging.getLogger(__name__)
34
35
36
class TestEyeballs:
37
38
# download using only HTTP/3 on working server
39
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
40
def test_06_01_h3_only(self, env: Env, httpd, nghttpx):
41
curl = CurlClient(env=env)
42
urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'
43
r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
44
r.check_response(count=1, http_status=200)
45
assert r.stats[0]['http_version'] == '3'
46
47
# download using only HTTP/3 on missing server
48
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
49
def test_06_02_h3_only(self, env: Env, httpd, nghttpx):
50
curl = CurlClient(env=env)
51
urln = f'https://{env.domain1}:{env.https_only_tcp_port}/data.json'
52
r = curl.http_download(urls=[urln], extra_args=['--http3-only'])
53
r.check_response(exitcode=7, http_status=None)
54
55
# download using HTTP/3 on missing server with fallback on h2
56
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
57
def test_06_03_h3_fallback_h2(self, env: Env, httpd, nghttpx):
58
curl = CurlClient(env=env)
59
urln = f'https://{env.domain1}:{env.https_only_tcp_port}/data.json'
60
r = curl.http_download(urls=[urln], extra_args=['--http3'])
61
r.check_response(count=1, http_status=200)
62
assert r.stats[0]['http_version'] == '2'
63
64
# download using HTTP/3 on missing server with fallback on http/1.1
65
@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")
66
def test_06_04_h3_fallback_h1(self, env: Env, httpd, nghttpx):
67
curl = CurlClient(env=env)
68
urln = f'https://{env.domain2}:{env.https_only_tcp_port}/data.json'
69
r = curl.http_download(urls=[urln], extra_args=['--http3'])
70
r.check_response(count=1, http_status=200)
71
assert r.stats[0]['http_version'] == '1.1'
72
73
# make a successful https: transfer and observer the timer stats
74
def test_06_10_stats_success(self, env: Env, httpd, nghttpx):
75
curl = CurlClient(env=env)
76
urln = f'https://{env.authority_for(env.domain1, "h2")}/data.json'
77
r = curl.http_download(urls=[urln])
78
r.check_response(count=1, http_status=200)
79
assert r.stats[0]['time_connect'] > 0.0
80
assert r.stats[0]['time_appconnect'] > 0.0
81
82
# make https: to a hostname that tcp connects, but will not verify
83
def test_06_11_stats_fail_verify(self, env: Env, httpd, nghttpx):
84
curl = CurlClient(env=env)
85
urln = f'https://not-valid.com:{env.https_port}/data.json'
86
r = curl.http_download(urls=[urln], extra_args=[
87
'--resolve', f'not-valid.com:{env.https_port}:127.0.0.1'
88
])
89
r.check_response(count=1, http_status=0, exitcode=False)
90
assert r.stats[0]['time_connect'] > 0.0 # was tcp connected
91
assert r.stats[0]['time_appconnect'] == 0 # but not SSL verified
92
93
# make https: to an invalid address
94
def test_06_12_stats_fail_tcp(self, env: Env, httpd, nghttpx):
95
curl = CurlClient(env=env)
96
urln = 'https://not-valid.com:1/data.json'
97
r = curl.http_download(urls=[urln], extra_args=[
98
'--resolve', f'not-valid.com:{1}:127.0.0.1'
99
])
100
r.check_response(count=1, http_status=None, exitcode=False)
101
assert r.stats[0]['time_connect'] == 0 # no one should have listened
102
assert r.stats[0]['time_appconnect'] == 0 # did not happen either
103
104