cdent / gabbi

Declarative HTTP Testing for Python and anything else
http://gabbi.readthedocs.org/
Other
148 stars 34 forks source link

gabbi doesn't support client cert yet #315

Open wu-wenxiang opened 2 years ago

wu-wenxiang commented 2 years ago

Gabbi doesn't support client cert yet

Help gabbi could support: gabbi-run ... --cacert /etc/kubernetes/pki/ca.crt --cert /etc/kubernetes/pki/client.crt --key /etc/kubernetes/pki/client.key ...

wu-wenxiang commented 2 years ago
diff --git a/gabbi/httpclient.py b/gabbi/httpclient.py
index b64b8a2..3dbff1b 100644
--- a/gabbi/httpclient.py
+++ b/gabbi/httpclient.py
@@ -186,11 +186,17 @@ class VerboseHttp(Http):
 def get_http(verbose=False, caption='', cert_validate=True, hostname=None):
     """Return an ``Http`` class for making requests."""
     cert_validation = {'cert_reqs': 'CERT_NONE'} if not cert_validate else {}
+    cert_validation = {
+        'cert_file': '/Users/wuwenxiang/Desktop/test.crt',
+        'cert_reqs': "CERT_REQUIRED",
+        'ca_certs': '/Users/wuwenxiang/Desktop/test.cacert',
+        'key_file': "/Users/wuwenxiang/Desktop/test.key",
+    }

     if not verbose:
         return Http(
             strict=True,
-            ca_certs=certifi.where(),
+            # ca_certs=certifi.where(),
             server_hostname=hostname,
             **cert_validation
         )
@@ -205,7 +211,7 @@ def get_http(verbose=False, caption='', cert_validate=True, hostname=None):
         caption=caption,
         colorize=True,
         strict=True,
-        ca_certs=certifi.where(),
+        # ca_certs=certifi.where(),
         server_hostname=hostname,
         **cert_validation
     )
wu-wenxiang commented 2 years ago

we should pass cmd line args to here...

cdent commented 2 years ago

Thanks, this is a good idea.

It will take some thought to work out how best to integrate it with the command line and with test suites, but we would be able to figure it out.

Did you have any ideas on whether it should be expressed in the YAML files?

wu-wenxiang commented 2 years ago

Be expressed in the YAML files seems better! It could be used both in fixtures & single case in tests