-
Notifications
You must be signed in to change notification settings - Fork 4
feat: add proxy and CA certificate support #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f8947c4
feat: add proxy and CA certificate support to HttpConfig
chonknick 0d63d49
feat(python): add proxy and ca_cert params to Client
chonknick e3cd36d
test(python): add tests for proxy and ca_cert params
chonknick 60cd6b8
style: fix cargo fmt formatting in http.rs test
chonknick 91b027d
fix: treat empty strings as None for proxy/ca_cert and add integratio…
chonknick 5b334d6
test(python): add negative test for invalid proxy URL
chonknick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| def test_client_with_proxy(): | ||
| """Test that Client accepts a proxy parameter.""" | ||
| from catsu import Client | ||
|
|
||
| client = Client(proxy="http://proxy.example.com:8080") | ||
| assert client is not None | ||
|
|
||
|
|
||
| def test_client_with_invalid_ca_cert(): | ||
| """Test that Client raises an error for invalid CA certificate.""" | ||
| from catsu import Client | ||
|
|
||
| with pytest.raises(RuntimeError): | ||
| Client(ca_cert="not a valid certificate") | ||
|
|
||
|
|
||
| def test_client_with_invalid_proxy(): | ||
| """Test that Client raises an error for invalid proxy URL.""" | ||
| from catsu import Client | ||
|
|
||
| with pytest.raises(RuntimeError): | ||
| Client(proxy="not-a-valid-url") | ||
|
|
||
|
|
||
| def test_client_with_valid_ca_cert_format(): | ||
| """Test that Client accepts a valid PEM format CA certificate. | ||
|
|
||
| Note: This uses a syntactically valid but fake certificate. | ||
| The client may fail later when making requests, but construction should work. | ||
| """ | ||
| from catsu import Client | ||
|
|
||
| # A minimal self-signed test certificate (valid PEM format) | ||
| test_cert = """-----BEGIN CERTIFICATE----- | ||
| MIIBkTCB+wIJAKHBfpegPjMCMA0GCSqGSIb3DQEBCwUAMBExDzANBgNVBAMMBnVu | ||
| dXNlZDAeFw0yMzAxMDEwMDAwMDBaFw0yNDAxMDEwMDAwMDBaMBExDzANBgNVBAMM | ||
| BnVudXNlZDBcMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQC6fGQKtQ3u3tLGDNnM8Jv2 | ||
| vHNJJnKJkf8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6j | ||
| AgMBAAEwDQYJKoZIhvcNAQELBQADQQBN6V7t8Hy8cWJxmXNvh8J6jJJ8J8J6jJJ8 | ||
| J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6jJJ8J8J6 | ||
| -----END CERTIFICATE-----""" | ||
|
|
||
| # This may raise due to invalid cert content, but should at least parse the PEM format | ||
| try: | ||
| client = Client(ca_cert=test_cert) | ||
| assert client is not None | ||
| except RuntimeError as e: | ||
| # Accept errors about invalid cert content, but not about unexpected params | ||
| assert "certificate" in str(e).lower() or "pem" in str(e).lower() or "base64" in str(e).lower() | ||
|
|
||
|
|
||
| def test_client_with_proxy_and_other_options(): | ||
| """Test that proxy can be combined with other options.""" | ||
| from catsu import Client | ||
|
|
||
| client = Client( | ||
| proxy="http://proxy.example.com:8080", | ||
| max_retries=5, | ||
| timeout=60, | ||
| ) | ||
| assert client is not None |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Rust tests only verify configuration storage but don't test actual HttpClient construction with proxy and CA certificate. Consider adding a test that constructs an HttpClient with these configurations to ensure they are properly applied to the underlying reqwest client:
This would catch any issues with the builder pattern or reqwest integration.