[py] Add support for http proxy authentication to remote_connection#10358
Merged
AutomatedTester merged 3 commits intoSeleniumHQ:trunkfrom Feb 28, 2022
Merged
Conversation
Member
|
Hey, thanks for the PR. Could you please check the github actions failures |
Contributor
Author
|
Hi David, |
Currently, urllib3.ProxyManager is used when connecting to a Selenium Server via http proxy. The proxy url is read from environment variables. When using a proxy which requires authentication, credentials are usually passed in the url like this: 'http://username:[email protected]:8080' urllib3.ProxyManager does not support this, but instead provides a proxy_header field which takes a basic auth header for authentication. This commit implements support for this. If credentials are given in the proxy url, they are seperated out. Then, the url without credentials and a proxy authentication header, which is created from the url credentials, are used to create the ProxyManager instance.
4ef6282 to
35eadf1
Compare
Contributor
Author
|
I rebased my feature branch, maybe that fixes the issue. |
|
Kudos, SonarCloud Quality Gate passed! |
AutomatedTester
approved these changes
Feb 28, 2022
elgatov
pushed a commit
to elgatov/selenium
that referenced
this pull request
Jun 27, 2022
…eleniumHQ#10358) * Add support for proxy authentication to remote_connection Currently, urllib3.ProxyManager is used when connecting to a Selenium Server via http proxy. The proxy url is read from environment variables. When using a proxy which requires authentication, credentials are usually passed in the url like this: 'http://username:[email protected]:8080' urllib3.ProxyManager does not support this, but instead provides a proxy_header field which takes a basic auth header for authentication. This commit implements support for this. If credentials are given in the proxy url, they are seperated out. Then, the url without credentials and a proxy authentication header, which is created from the url credentials, are used to create the ProxyManager instance. * Fix flake8 style violations Co-authored-by: David Burns <[email protected]>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.








Description
Currently,
urllib3.ProxyManageris used when connecting to a Selenium Server via http proxy.The proxy url is read from environment variables.
Some http proxies require authentication. Credentials are usually passed in the url like this:
http://username:[email protected]:8080
When specifying a url like this and passing it into the ProxyManager's
proxy_urlattribute,the ProxyManager is not able to authenticate to the proxy and a ProxyError is thrown:
ProxyError('Cannot connect to proxy.', OSError('Tunnel connection failed: 407 Proxy Authentication Required'))Instead ProxyManager uses a
proxy_headerfield for authentication, which can take aproxy-authorizationheaderthat is then used to authenticate to the http proxy.
This PR implements support for this header.
If credentials are specified in the proxy url like shown above, they are seperated out.
They are then used to create a HTTP basic proxy-authorization header
using the urllib3.util.make_headers method provided by urllib3.
The credentials are removed from the url and the ProxyManager object is created using the
url without credentials and the authorization header.
If a regular url is passed in without credentials, no auth header is specified and the ProxyManager is created as it was before.
Motivation and Context
It is currently not possible to connect to a Selenium Server behind an http proxy that requires authentication using the Python Remote Webdriver.
This problem is solved here, as credentials can now be specified in the proxy url using the following standardized format:
http://username:[email protected]:8080
This feature is already present in other Selenium implementations (I tested it in Ruby), and this adds support for Python as well.
Types of changes
Checklist
(This is my first ever open source contribution, so if there is anything I can improve, please let me know!)