pytest fixes and improvements

- fix test_17_20 flakiness: the test case did not have `nghttpx` in
  its parameters, causing it to no check if a reload was necessary.
  When that test ran behind one that gave nghttpx another certificate,
  eg. in parallel mode, it used the wrong pinned pubkey.
- Have `env` provide lists of HTTP protocol versions available for
  testing. Replace parameterized tests on a fixed protocol list with
  the dynamic one from env. This makes checks for protocol availability
  in the test function bodies superfluous.

refs #19489
Closes #19540
This commit is contained in:
Stefan Eissing 2025-11-15 12:45:54 +01:00 committed by Daniel Stenberg
parent b3d4f17e3d
commit 217f0e4d59
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
17 changed files with 191 additions and 630 deletions

View file

@ -55,9 +55,8 @@ class TestBasic:
# simple https: GET, h2 wanted and got
@pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_03_h2_get(self, env: Env, httpd):
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url = f'https://{env.domain1}:{env.https_port}/data.json'
r = curl.http_get(url=url, extra_args=['--http2'])
@ -66,9 +65,8 @@ class TestBasic:
# simple https: GET, h2 unsupported, fallback to h1
@pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_04_h2_unsupported(self, env: Env, httpd):
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url = f'https://{env.domain2}:{env.https_port}/data.json'
r = curl.http_get(url=url, extra_args=['--http2'])
@ -86,12 +84,8 @@ class TestBasic:
# simple download, check connect/handshake timings
@pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
@pytest.mark.parametrize("proto", Env.http_protos())
def test_01_06_timings(self, env: Env, httpd, nghttpx, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
if proto == 'h3' and not env.have_h3():
pytest.skip("h3 not supported")
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/data.json'
r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True)
@ -103,13 +97,9 @@ class TestBasic:
assert r.stats[0]['time_appconnect'] > 0, f'{r.stats[0]}'
# simple https: HEAD
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
@pytest.mark.parametrize("proto", Env.http_protos())
@pytest.mark.skipif(condition=not Env.have_ssl_curl(), reason="curl without SSL")
def test_01_07_head(self, env: Env, httpd, nghttpx, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
if proto == 'h3' and not env.have_h3():
pytest.skip("h3 not supported")
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/data.json'
r = curl.http_download(urls=[url], with_stats=True, with_headers=True,
@ -122,9 +112,8 @@ class TestBasic:
assert r.stats[0]['size_download'] == 0, f'{r.stats[0]}'
# http: GET for HTTP/2, see Upgrade:, 101 switch
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_08_h2_upgrade(self, env: Env, httpd):
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url = f'http://{env.domain1}:{env.http_port}/data.json'
r = curl.http_get(url=url, extra_args=['--http2'])
@ -136,9 +125,8 @@ class TestBasic:
assert r.json['server'] == env.domain1
# http: GET for HTTP/2 with prior knowledge
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_09_h2_prior_knowledge(self, env: Env, httpd):
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url = f'http://{env.domain1}:{env.http_port}/data.json'
r = curl.http_get(url=url, extra_args=['--http2-prior-knowledge'])
@ -149,9 +137,8 @@ class TestBasic:
assert r.json['server'] == env.domain1
# http: strip TE header in HTTP/2 requests
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_10_te_strip(self, env: Env, httpd):
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, "h2")}/data.json'
r = curl.http_get(url=url, extra_args=['--http2', '-H', 'TE: gzip'])
@ -164,12 +151,8 @@ class TestBasic:
# send 48KB+ sized response headers to check we handle that correctly
# larger than 64KB headers expose a bug in Apache HTTP/2 that is not
# RSTing the stream correctly when its internal limits are exceeded.
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
@pytest.mark.parametrize("proto", Env.http_protos())
def test_01_11_large_resp_headers(self, env: Env, httpd, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
if proto == 'h3' and not env.have_h3():
pytest.skip("h3 not supported")
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}' \
f'/curltest/tweak?x-hd={48 * 1024}'
@ -181,10 +164,8 @@ class TestBasic:
# http: response headers larger than what curl buffers for
@pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
reason='httpd must be at least 2.4.64')
@pytest.mark.parametrize("proto", ['http/1.1', 'h2'])
@pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
def test_01_12_xlarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
httpd.set_extra_config('base', [
f'H2MaxHeaderBlockLen {130 * 1024}',
])
@ -200,10 +181,8 @@ class TestBasic:
# http: 1 response header larger than what curl buffers for
@pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
reason='httpd must be at least 2.4.64')
@pytest.mark.parametrize("proto", ['http/1.1', 'h2'])
@pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
def test_01_13_megalarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
httpd.set_extra_config('base', [
'LogLevel http2:trace2',
f'H2MaxHeaderBlockLen {130 * 1024}',
@ -222,10 +201,8 @@ class TestBasic:
# nghttp2 error -905: Too many CONTINUATION frames following a HEADER frame
@pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
reason='httpd must be at least 2.4.64')
@pytest.mark.parametrize("proto", ['http/1.1', 'h2'])
@pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
def test_01_14_gigalarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
httpd.set_extra_config('base', [
'LogLevel http2:trace2',
f'H2MaxHeaderBlockLen {1024 * 1024}',
@ -243,10 +220,8 @@ class TestBasic:
# http: one response header > 256 KB
@pytest.mark.skipif(condition=not Env.httpd_is_at_least('2.4.64'),
reason='httpd must be at least 2.4.64')
@pytest.mark.parametrize("proto", ['http/1.1', 'h2'])
@pytest.mark.parametrize("proto", Env.http_h1_h2_protos())
def test_01_15_gigalarge_resp_headers(self, env: Env, httpd, configures_httpd, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
httpd.set_extra_config('base', [
'LogLevel http2:trace2',
f'H2MaxHeaderBlockLen {1024 * 1024}',
@ -262,12 +237,8 @@ class TestBasic:
r.check_exit_code(100) # CURLE_TOO_LARGE
# http: invalid request headers, GET, issue #16998
@pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
@pytest.mark.parametrize("proto", Env.http_protos())
def test_01_16_inv_req_get(self, env: Env, httpd, nghttpx, proto):
if proto == 'h2' and not env.have_h2_curl():
pytest.skip("h2 not supported")
if proto == 'h3' and not env.have_h3():
pytest.skip("h3 not supported")
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo'
r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
@ -287,10 +258,9 @@ class TestBasic:
pytest.param('gzip ;q=0.2;x="y,x", trailers', 'trailers', id='gzip+q+x+trailers'),
pytest.param('gzip ;x="trailers", chunks', None, id='gzip+x+chunks'),
])
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_17_TE(self, env: Env, httpd, te_in, te_out):
proto = 'h2'
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url = f'https://{env.authority_for(env.domain1, proto)}/curltest/echo'
r = curl.http_download(urls=[url], alpn_proto=proto, with_stats=True,
@ -303,10 +273,9 @@ class TestBasic:
assert 'request-te' not in r.responses[0]['header'], f'{r.responses[0]}'
# check that an existing https: connection is not reused for http:
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_18_tls_reuse(self, env: Env, httpd):
proto = 'h2'
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url1 = f'https://{env.authority_for(env.domain1, proto)}/data.json'
url2 = f'http://{env.authority_for(env.domain1, proto)}/data.json'
@ -315,10 +284,9 @@ class TestBasic:
assert r.total_connects == 2, f'{r.dump_logs()}'
# check that an existing http: connection is not reused for https:
@pytest.mark.skipif(condition=not Env.have_h2_curl(), reason="curl without h2")
def test_01_19_plain_reuse(self, env: Env, httpd):
proto = 'h2'
if not env.have_h2_curl():
pytest.skip("h2 not supported")
curl = CurlClient(env=env)
url1 = f'http://{env.domain1}:{env.http_port}/data.json'
url2 = f'https://{env.domain1}:{env.http_port}/data.json'