Path: blob/main/external/curl/tests/http/test_06_eyeballs.py
2066 views
#!/usr/bin/env python31# -*- coding: utf-8 -*-2#***************************************************************************3# _ _ ____ _4# Project ___| | | | _ \| |5# / __| | | | |_) | |6# | (__| |_| | _ <| |___7# \___|\___/|_| \_\_____|8#9# Copyright (C) Daniel Stenberg, <[email protected]>, et al.10#11# This software is licensed as described in the file COPYING, which12# you should have received as part of this distribution. The terms13# are also available at https://curl.se/docs/copyright.html.14#15# You may opt to use, copy, modify, merge, publish, distribute and/or sell16# copies of the Software, and permit persons to whom the Software is17# furnished to do so, under the terms of the COPYING file.18#19# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY20# KIND, either express or implied.21#22# SPDX-License-Identifier: curl23#24###########################################################################25#26import logging27import pytest2829from testenv import Env, CurlClient303132log = logging.getLogger(__name__)333435class TestEyeballs:3637# download using only HTTP/3 on working server38@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")39def test_06_01_h3_only(self, env: Env, httpd, nghttpx):40curl = CurlClient(env=env)41urln = f'https://{env.authority_for(env.domain1, "h3")}/data.json'42r = curl.http_download(urls=[urln], extra_args=['--http3-only'])43r.check_response(count=1, http_status=200)44assert r.stats[0]['http_version'] == '3'4546# download using only HTTP/3 on missing server47@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")48def test_06_02_h3_only(self, env: Env, httpd, nghttpx):49curl = CurlClient(env=env)50urln = f'https://{env.domain1}:{env.https_only_tcp_port}/data.json'51r = curl.http_download(urls=[urln], extra_args=['--http3-only'])52r.check_response(exitcode=7, http_status=None)5354# download using HTTP/3 on missing server with fallback on h255@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")56def test_06_03_h3_fallback_h2(self, env: Env, httpd, nghttpx):57curl = CurlClient(env=env)58urln = f'https://{env.domain1}:{env.https_only_tcp_port}/data.json'59r = curl.http_download(urls=[urln], extra_args=['--http3'])60r.check_response(count=1, http_status=200)61assert r.stats[0]['http_version'] == '2'6263# download using HTTP/3 on missing server with fallback on http/1.164@pytest.mark.skipif(condition=not Env.have_h3(), reason="missing HTTP/3 support")65def test_06_04_h3_fallback_h1(self, env: Env, httpd, nghttpx):66curl = CurlClient(env=env)67urln = f'https://{env.domain2}:{env.https_only_tcp_port}/data.json'68r = curl.http_download(urls=[urln], extra_args=['--http3'])69r.check_response(count=1, http_status=200)70assert r.stats[0]['http_version'] == '1.1'7172# make a successful https: transfer and observer the timer stats73def test_06_10_stats_success(self, env: Env, httpd, nghttpx):74curl = CurlClient(env=env)75urln = f'https://{env.authority_for(env.domain1, "h2")}/data.json'76r = curl.http_download(urls=[urln])77r.check_response(count=1, http_status=200)78assert r.stats[0]['time_connect'] > 0.079assert r.stats[0]['time_appconnect'] > 0.08081# make https: to a hostname that tcp connects, but will not verify82def test_06_11_stats_fail_verify(self, env: Env, httpd, nghttpx):83curl = CurlClient(env=env)84urln = f'https://not-valid.com:{env.https_port}/data.json'85r = curl.http_download(urls=[urln], extra_args=[86'--resolve', f'not-valid.com:{env.https_port}:127.0.0.1'87])88r.check_response(count=1, http_status=0, exitcode=False)89assert r.stats[0]['time_connect'] > 0.0 # was tcp connected90assert r.stats[0]['time_appconnect'] == 0 # but not SSL verified9192# make https: to an invalid address93def test_06_12_stats_fail_tcp(self, env: Env, httpd, nghttpx):94curl = CurlClient(env=env)95urln = 'https://not-valid.com:1/data.json'96r = curl.http_download(urls=[urln], extra_args=[97'--resolve', f'not-valid.com:{1}:127.0.0.1'98])99r.check_response(count=1, http_status=None, exitcode=False)100assert r.stats[0]['time_connect'] == 0 # no one should have listened101assert r.stats[0]['time_appconnect'] == 0 # did not happen either102103104