-
Notifications
You must be signed in to change notification settings - Fork 89
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
Migrate http proxy tests to pproxy #199
Migrate http proxy tests to pproxy #199
Conversation
a789c6b
to
9c4edb3
Compare
9c4edb3
to
a6033ad
Compare
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.
Looking good!
How come the HTTPS proxy test passes w/o further configuration or tweaks, though, whereas there are a few fixtures such as ca_ssl_context
that relate to our previous HTTPS proxy setup? We ought to clean up any fixtures we don't use anymore, and see if there's anything we need to update in HTTPS proxies tests.
def example_org_cert_path(example_org_cert: trustme.LeafCert) -> typing.Iterator[str]: | ||
with example_org_cert.private_key_and_cert_chain_pem.tempfile() as tmp: | ||
yield tmp | ||
def proxy_server() -> typing.Iterator[URL]: |
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.
Instead of overriding the existing code, which makes things a bit hard to review (nothing blocking though), should we take the opportunity here and define any code related to the test proxy in conftest/utils.py
? I think it's a good pattern to isolate anything that doesn't need to be defined in conftest.py
to somewhere else, for readability. Bonus point here is the diff should be easier to review. :-)
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.
I hope I understood you correctly. I've moved all the code apart from fixture initialization into the tests/utils.py
tests/conftest.py
Outdated
The server is configured to use a trustme CA and key, this will allow our | ||
test client to make HTTPS requests when using the ca_ssl_context fixture | ||
above. | ||
print(f"HTTP proxy started on http://{http_proxy_host}:{http_proxy_port}/") |
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.
Should we instead let the stdout/stderr of the pproxy process pass through?
Not sure which flag we'd need to pass to Popen(stdout=..., stderr=...)
, but that way we wouldn't need this print statement, and we'd be able to see the full output using controls built into pytest (such as the -s
flag).
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.
You are right, I was not consistent. Removed the print
statement and the pipes
a265186
to
16efcc2
Compare
Removed unused fixtures. Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
16efcc2
to
f083e47
Compare
@florimondmanca |
@cdeler Sounds good, feel free to drop anything you don't need as of this PR, I can add stuff back in the future. :) |
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.
Great work! Two nits, but this is mergeable to me. Feel free to address whatever feels appropriate, and then we can get this merged. :)
tests/conftest.py
Outdated
yield (b"http", PROXY_HOST.encode(), PROXY_PORT, b"/") | ||
finally: | ||
thread.join() | ||
with http_proxy_server(proxy_host, proxy_port) as proxy_server_fixture: |
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.
(Nit) How about as proxy_url
, since it seems the context manager returns an URL tuple?
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.
Renamed
tests/utils.py
Outdated
@@ -11,6 +15,17 @@ def lookup_sync_backend(): | |||
return "sync" | |||
|
|||
|
|||
def wait_until_pproxy_serve_on_port(host: str, port: int): |
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.
(Nit) Looks like there's nothing particular to pproxy here, so rather should we name this _wait_can_connect(host, port)
, or something more generic like that? (With _
indicating this is not a helper we're meaning to import from conftest or our tests.)
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.
Good point, renamed
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
[1] encode/httpcore#199 git-svn-id: file:///srv/repos/svn-community/svn@722265 9fca08f4-af9d-4005-b8df-a31f2cc04f65
[1] encode/httpcore#199 git-svn-id: file:///srv/repos/svn-community/svn@722265 9fca08f4-af9d-4005-b8df-a31f2cc04f65
…changes (details below) * mitmproxy, trustme -> python-pproxy encode/httpcore#199 * pytest-asyncio, pytest-trio -> python-anyio encode/httpcore#181 Some tests still use pytest.mark.trio, though git-svn-id: file:///srv/repos/svn-community/svn@726093 9fca08f4-af9d-4005-b8df-a31f2cc04f65
…changes (details below) * mitmproxy, trustme -> python-pproxy encode/httpcore#199 * pytest-asyncio, pytest-trio -> python-anyio encode/httpcore#181 Some tests still use pytest.mark.trio, though git-svn-id: file:///srv/repos/svn-community/svn@726093 9fca08f4-af9d-4005-b8df-a31f2cc04f65
In #196 comments it was mentioned that the first step of implementing
socks
proxy support might be replacingmitmproxy
bypproxy
(which allows us to testhttp
,socks4
andsocks5
support)So that I rewrote the test fixtures and changed
requirement
file.The next steps I propose to do after this PR: