url: connection reuse fixes for starttls

Add test_31_13 to check connection reuse on mixed --ssl-reqd setting.
For that add debug env var CURL_DBG_NO_USE_SSL_ON_FIRST to disable
--ssl-reqd for the first url. Check that the connection without SSL
from the first url is not reused on the second URL that requires it.

Tweak special ftp: protocol check to fail a DEBUGASSERT on mismatched
`use_ssl` settings as that should have been caught before in the
connection reuse matching (imap/smtp etc. do not have this extra check
and rely on the general part doing its job).

Closes #21665
This commit is contained in:
Stefan Eissing 2026-05-19 10:57:53 +02:00 committed by Daniel Stenberg
parent f1a6f190a6
commit 4ff212f8ed
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 55 additions and 14 deletions

View file

@ -270,6 +270,30 @@ class TestVsFTPD:
dstfile = os.path.join(vsftpds.docs_dir, docname)
assert os.path.exists(dstfile), f'{r.dump_logs()}'
# connection reuse with STARTTLS required
# 1st download without STARTTLS, 2nd with --ssl-reqd
@pytest.mark.skipif(condition=not Env.curl_is_debug(), reason="needs curl debug")
def test_31_13_starttls_reuse(self, env: Env, vsftpds: VsFTPD):
run_env = os.environ.copy()
run_env['CURL_DBG_NO_USE_SSL_ON_FIRST'] = '1'
curl = CurlClient(env=env, run_env=run_env)
url1 = f'ftp://{env.ftp_domain}:{vsftpds.port}/data-1k'
url2 = f'ftp://{env.ftp_domain}:{vsftpds.port}/data-10k'
r = curl.run_direct(with_stats=True, args=[
'-svv', '--resolve', f'{env.ftp_domain}:{vsftpds.port}:127.0.0.1',
'--cacert', env.ca.cert_file,
url1, '--out-null',
url2, '--out-null', '--ssl-reqd'
])
r.check_exit_code(0)
r.check_stats(count=2, http_status=226)
# expect 4 connections to have been made:
# 1. 1st CONTROL without STARTTLS
# 2. 1st DATA for download
# 3. 2nd CONTROL with STARTTLS (not reuse of 1)
# 4. 2nd DATA for download
assert r.total_connects == 4, f'{r.dump_logs()}'
def check_downloads(self, client, srcfile: str, count: int,
complete: bool = True):
for i in range(count):