-
-
Notifications
You must be signed in to change notification settings - Fork 590
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix client for HTTPS endpoints with Python 3.12 (#1454)
* Fix client for HTTPS endpoints for python 3.12 * Use only `DEFAULT_SSL_CONTEXT_OPTIONS` to prevent `CRIME` attacks * lint fix * install certifi types * pre commit * Avoid using dep options for >=3.10 * More tests * Fix lint issues * Use `3.12` by default everywhere * Skip `grout -h` test on windows * Add http only test * Rollback to python versions, 3.12 causes doc/lint failures * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Keep proxy.py benchmarking on so that users dont run into surprises * Install certifi * No need of certifi --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
74c42f6
commit 0bfd7d7
Showing
7 changed files
with
129 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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,62 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
proxy.py | ||
~~~~~~~~ | ||
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on | ||
Network monitoring, controls & Application development, testing, debugging. | ||
:copyright: (c) 2013-present by Abhinav Singh and contributors. | ||
:license: BSD, see LICENSE for more details. | ||
""" | ||
import unittest | ||
|
||
from proxy.http.client import client | ||
|
||
|
||
class TestClient(unittest.TestCase): | ||
|
||
def test_http(self) -> None: | ||
response = client( | ||
host=b'google.com', | ||
port=80, | ||
scheme=b'http', | ||
path=b'/', | ||
method=b'GET', | ||
content_type=b'text/html', | ||
) | ||
assert response is not None | ||
self.assertEqual(response.code, b'301') | ||
|
||
def test_client(self) -> None: | ||
response = client( | ||
host=b'google.com', | ||
port=443, | ||
scheme=b'https', | ||
path=b'/', | ||
method=b'GET', | ||
content_type=b'text/html', | ||
) | ||
assert response is not None | ||
self.assertEqual(response.code, b'301') | ||
|
||
def test_client_connection_refused(self) -> None: | ||
response = client( | ||
host=b'cannot-establish-connection.com', | ||
port=443, | ||
scheme=b'https', | ||
path=b'/', | ||
method=b'GET', | ||
content_type=b'text/html', | ||
) | ||
assert response is None | ||
|
||
def test_cannot_ssl_wrap(self) -> None: | ||
response = client( | ||
host=b'example.com', | ||
port=80, | ||
scheme=b'https', | ||
path=b'/', | ||
method=b'GET', | ||
content_type=b'text/html', | ||
) | ||
assert response is None |
This file contains 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,31 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
proxy.py | ||
~~~~~~~~ | ||
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on | ||
Network monitoring, controls & Application development, testing, debugging. | ||
:copyright: (c) 2013-present by Abhinav Singh and contributors. | ||
:license: BSD, see LICENSE for more details. | ||
""" | ||
import sys | ||
|
||
import pytest | ||
import unittest | ||
|
||
from proxy import grout | ||
from proxy.common.constants import IS_WINDOWS | ||
|
||
|
||
@pytest.mark.skipif( | ||
IS_WINDOWS, | ||
reason="sys.argv replacement don't really work on windows", | ||
) | ||
class TestGrout(unittest.TestCase): | ||
|
||
def test_grout(self) -> None: | ||
with self.assertRaises(SystemExit): | ||
original = sys.argv | ||
sys.argv = ['grout', '-h'] | ||
grout() | ||
sys.argv = original |