]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
tests/http: add --insecure tests
authorStefan Eissing <stefan@eissing.org>
Mon, 28 Oct 2024 10:59:06 +0000 (11:59 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Mon, 28 Oct 2024 12:04:28 +0000 (13:04 +0100)
Add two test cases that connection using a hostname the server has no
certificate for. First, verify that the peer verification fail, as
expected. Second, provide '--insecure' to test that the connection
succeeded and returned some data.

Closes #15429

tests/http/test_17_ssl_use.py
tests/http/testenv/env.py

index 197a5b4f92582bf0668b50bfe1b8bcef41925b19..f129b110181641de7dbd4a3ff36360980d79f531 100644 (file)
@@ -341,3 +341,28 @@ class TestSSLUse:
             if m:
                 reused_session = True
         assert reused_session, f'{r}\n{r.dump_logs()}'
+
+    # use host name server has no certificate for
+    @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
+    def test_17_11_wrong_host(self, env: Env, proto):
+        if proto == 'h3' and not env.have_h3():
+            pytest.skip("h3 not supported")
+        curl = CurlClient(env=env)
+        domain = f'insecure.{env.tld}'
+        url = f'https://{domain}:{env.port_for(proto)}/curltest/sslinfo'
+        r = curl.http_get(url=url, alpn_proto=proto)
+        assert r.exit_code == 60, f'{r}'
+
+    # use host name server has no cert for with --insecure
+    @pytest.mark.parametrize("proto", ['http/1.1', 'h2', 'h3'])
+    def test_17_12_insecure(self, env: Env, proto):
+        if proto == 'h3' and not env.have_h3():
+            pytest.skip("h3 not supported")
+        curl = CurlClient(env=env)
+        domain = f'insecure.{env.tld}'
+        url = f'https://{domain}:{env.port_for(proto)}/curltest/sslinfo'
+        r = curl.http_get(url=url, alpn_proto=proto, extra_args=[
+            '--insecure'
+        ])
+        assert r.exit_code == 0, f'{r}'
+        assert r.json, f'{r}'
index 3998be980f7584dc63887ef026aff15220b203f1..5d6ec176fac7a4b21a2c968df5240adfae310156 100644 (file)
@@ -460,6 +460,10 @@ class Env:
     def htdocs_dir(self) -> str:
         return self.CONFIG.htdocs_dir
 
+    @property
+    def tld(self) -> str:
+        return self.CONFIG.tld
+
     @property
     def domain1(self) -> str:
         return self.CONFIG.domain1