From 70282328ca19b53fea09b2e816a5488a0c6be5a7 Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Wed, 27 Sep 2023 17:10:57 +0200 Subject: [PATCH] Use username and password from --proxy=URL * When URL in --proxy=URL contains username and password (e.g. --proxy=https://user:pass@proxy.server.com: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 --- src/subscription_manager/managercli.py | 2 ++ test/test_managercli.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/subscription_manager/managercli.py b/src/subscription_manager/managercli.py index 95546bd439..087786c9d3 100644 --- a/src/subscription_manager/managercli.py +++ b/src/subscription_manager/managercli.py @@ -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) diff --git a/test/test_managercli.py b/test/test_managercli.py index 35ab637d38..40c28fb817 100644 --- a/test/test_managercli.py +++ b/test/test_managercli.py @@ -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:bar@www.example.com", + "--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()