Skip to content
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

Merged
merged 4 commits into from
Oct 4, 2020

Conversation

cdeler
Copy link
Member

@cdeler cdeler commented Sep 28, 2020

In #196 comments it was mentioned that the first step of implementing socks proxy support might be replacing mitmproxy by pproxy (which allows us to test http, socks4 and socks5 support)

So that I rewrote the test fixtures and changed requirement file.

The next steps I propose to do after this PR:

  1. rebase Implement socks5 proxy support using socksio #188 draft
  2. move on acroding to the comment https://gitter.im/encode/community?at=5f6db8edf41f4105e4d7a9eb

Copy link
Member

@florimondmanca florimondmanca left a 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.

tests/conftest.py Outdated Show resolved Hide resolved
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]:
Copy link
Member

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. :-)

Copy link
Member Author

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 Show resolved Hide resolved
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}/")
Copy link
Member

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).

Copy link
Member Author

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

@cdeler cdeler force-pushed the migrate-http-proxy-tests-to-pproxy branch 5 times, most recently from a265186 to 16efcc2 Compare October 3, 2020 19:15
cdeler and others added 3 commits October 3, 2020 22:15
Removed unused fixtures.

Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
Co-authored-by: Florimond Manca <florimond.manca@gmail.com>
@cdeler cdeler force-pushed the migrate-http-proxy-tests-to-pproxy branch from 16efcc2 to f083e47 Compare October 3, 2020 19:16
@cdeler
Copy link
Member Author

cdeler commented Oct 3, 2020

@florimondmanca
I've removed trustme from requirements, but found that you are using it in the #205

@florimondmanca
Copy link
Member

@cdeler Sounds good, feel free to drop anything you don't need as of this PR, I can add stuff back in the future. :)

Copy link
Member

@florimondmanca florimondmanca left a 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. :)

yield (b"http", PROXY_HOST.encode(), PROXY_PORT, b"/")
finally:
thread.join()
with http_proxy_server(proxy_host, proxy_port) as proxy_server_fixture:
Copy link
Member

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?

Copy link
Member Author

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):
Copy link
Member

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.)

Copy link
Member Author

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>
@cdeler cdeler merged commit 73905ad into encode:master Oct 4, 2020
@cdeler cdeler deleted the migrate-http-proxy-tests-to-pproxy branch October 4, 2020 09:11
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Oct 9, 2020
[1] encode/httpcore#199



git-svn-id: file:///srv/repos/svn-community/svn@722265 9fca08f4-af9d-4005-b8df-a31f2cc04f65
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Oct 9, 2020
[1] encode/httpcore#199



git-svn-id: file:///srv/repos/svn-community/svn@722265 9fca08f4-af9d-4005-b8df-a31f2cc04f65
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Oct 18, 2020
…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
archlinux-github pushed a commit to archlinux/svntogit-community that referenced this pull request Oct 18, 2020
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants