Skip to content

Commit 27c6833

Browse files
fix SSL context with local path (#1438)
* fix SSL context with local path * added live client test class, and added a test specifically for testing https requests thru HTTPXClient --------- Co-authored-by: Jesse Rosalia <[email protected]>
1 parent 627c691 commit 27c6833

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

stripe/_http_client.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1245,7 +1245,7 @@ def __init__(
12451245
kwargs = {}
12461246
if self._verify_ssl_certs:
12471247
kwargs["verify"] = ssl.create_default_context(
1248-
capath=stripe.ca_bundle_path
1248+
cafile=stripe.ca_bundle_path
12491249
)
12501250
else:
12511251
kwargs["verify"] = False

tests/test_http_client.py

+31
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import base64
12
from typing import Any, List
23
from typing_extensions import Type
34
from unittest.mock import call
@@ -1971,3 +1972,33 @@ def test_timeout(self):
19711972

19721973
def test_timeout_async(self):
19731974
pass
1975+
1976+
1977+
class TestLiveHTTPClients:
1978+
"""
1979+
Tests that actually make HTTP requests in order to test functionality (like https)
1980+
end to end.
1981+
"""
1982+
1983+
@pytest.mark.anyio
1984+
async def test_httpx_request_async_https(self):
1985+
"""
1986+
Test to ensure that httpx https calls succeed by making a live test call
1987+
to the public stripe API.
1988+
"""
1989+
method = "get"
1990+
abs_url = "https://api.stripe.com/v1/balance"
1991+
data = {}
1992+
1993+
client = _http_client.HTTPXClient(verify_ssl_certs=True)
1994+
# the public test secret key, as found on https://docs.stripe.com/keys#obtain-api-keys
1995+
test_api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
1996+
basic_auth = base64.b64encode(
1997+
(test_api_key + ":").encode("utf-8")
1998+
).decode("utf-8")
1999+
headers = {"Authorization": "Basic " + basic_auth}
2000+
2001+
_, code, _ = await client.request_with_retries_async(
2002+
method, abs_url, headers, data
2003+
)
2004+
assert code >= 200 and code < 400

0 commit comments

Comments
 (0)