Skip to content

Commit

Permalink
fix SSL context with local path (#1438)
Browse files Browse the repository at this point in the history
* 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 <jar@stripe.com>
  • Loading branch information
xavdid-stripe and jar-stripe authored Dec 19, 2024
1 parent 627c691 commit 27c6833
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stripe/_http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@ def __init__(
kwargs = {}
if self._verify_ssl_certs:
kwargs["verify"] = ssl.create_default_context(
capath=stripe.ca_bundle_path
cafile=stripe.ca_bundle_path
)
else:
kwargs["verify"] = False
Expand Down
31 changes: 31 additions & 0 deletions tests/test_http_client.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import base64
from typing import Any, List
from typing_extensions import Type
from unittest.mock import call
Expand Down Expand Up @@ -1971,3 +1972,33 @@ def test_timeout(self):

def test_timeout_async(self):
pass


class TestLiveHTTPClients:
"""
Tests that actually make HTTP requests in order to test functionality (like https)
end to end.
"""

@pytest.mark.anyio
async def test_httpx_request_async_https(self):
"""
Test to ensure that httpx https calls succeed by making a live test call
to the public stripe API.
"""
method = "get"
abs_url = "https://api.stripe.com/v1/balance"
data = {}

client = _http_client.HTTPXClient(verify_ssl_certs=True)
# the public test secret key, as found on https://docs.stripe.com/keys#obtain-api-keys
test_api_key = "sk_test_4eC39HqLyjWDarjtT1zdp7dc"
basic_auth = base64.b64encode(
(test_api_key + ":").encode("utf-8")
).decode("utf-8")
headers = {"Authorization": "Basic " + basic_auth}

_, code, _ = await client.request_with_retries_async(
method, abs_url, headers, data
)
assert code >= 200 and code < 400

0 comments on commit 27c6833

Please sign in to comment.