Skip to content

Commit

Permalink
Use username and password from --proxy=URL
Browse files Browse the repository at this point in the history
* When URL in --proxy=URL contains username and password
  (e.g. --proxy=https://user:[email protected]:3128),
  then user and pass are used as proxy_user and proxy_pass
* The --proxyuser and --proxypassword have higher priority.
  Thus, it does not break backward compatibility.
* Added one unit test for this case
  • Loading branch information
jirihnidek committed Oct 16, 2023
1 parent a99bb83 commit 7028232
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/subscription_manager/managercli.py
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ def main(self, args=None):
proxy_user, proxy_pass, proxy_hostname, proxy_port, proxy_prefix = rhsm.utils.parse_url(
self.options.proxy_url, default_port=default_proxy_port
)
self.proxy_user = proxy_user
self.proxy_password = proxy_pass
self.proxy_hostname = proxy_hostname
self.proxy_port = int(proxy_port)

Expand Down
18 changes: 18 additions & 0 deletions test/test_managercli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2484,6 +2484,24 @@ def test_list_by_default_with_options_from_super_class(self):
self.cc._validate_options()
self.assertTrue(self.cc.options.list)

def test_proxy_user_and_pass_from_url_overridden_by_cli_options(self):
"""
Test that --proxyuser and --proxypassword have higher priority than --proxy
"""
self.cc.main(
[
"--proxy",
"https://foo:[email protected]",
"--proxyuser",
"other-user",
"--proxypassword",
"other-password",
]
)
self.cc._validate_options()
self.assertEqual(self.cc.proxy_user, "other-user")
self.assertEqual(self.cc.proxy_password, "other-password")

def test_add_with_multiple_colons(self):
self.cc.main(["--repo", "x", "--add", "url:http://example.com"])
self.cc._validate_options()
Expand Down

0 comments on commit 7028232

Please sign in to comment.