From cd75074fc57ea79025d3f4ee53f0b1c0afff34cf Mon Sep 17 00:00:00 2001 From: Paul Harvey Date: Wed, 31 Oct 2018 02:35:37 +1100 Subject: [PATCH] fix yum proxy regex (closes #47797) (#47800) * Modify yum/tasks/proxy.yml to usernames that expose regex bug * Fix bad regex backref/interpolation w/yum proxy username A yum proxy username that begins with a number was being interpolated as part of the backref, resulting in an error: "sre_constants.error: invalid group reference" Closes #47797 --- lib/ansible/modules/packaging/os/yum.py | 2 +- test/integration/targets/yum/tasks/proxy.yml | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/ansible/modules/packaging/os/yum.py b/lib/ansible/modules/packaging/os/yum.py index 409f118054..2cbee1ea3b 100644 --- a/lib/ansible/modules/packaging/os/yum.py +++ b/lib/ansible/modules/packaging/os/yum.py @@ -710,7 +710,7 @@ class YumModule(YumDnf): for item in scheme: os.environ[item + "_proxy"] = re.sub( r"(http://)", - r"\1" + namepass, proxy_url + r"\g<1>" + namepass, proxy_url ) yield except yum.Errors.YumBaseError: diff --git a/test/integration/targets/yum/tasks/proxy.yml b/test/integration/targets/yum/tasks/proxy.yml index c506c5e563..f69181a2ec 100644 --- a/test/integration/targets/yum/tasks/proxy.yml +++ b/test/integration/targets/yum/tasks/proxy.yml @@ -6,7 +6,7 @@ - lineinfile: path: /etc/tinyproxy/tinyproxy.conf - line: "BasicAuth testuser testpassword" + line: "BasicAuth 1testuser 1testpassword" state: present # systemd doesn't play nice with this in a container for some reason @@ -15,7 +15,7 @@ - lineinfile: path: /etc/yum.conf - line: "proxy=http://testuser:testpassword@127.0.0.1:8888" + line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888" state: present - yum: @@ -35,7 +35,7 @@ - lineinfile: path: /etc/yum.conf - line: "proxy=http://testuser:testpassword@127.0.0.1:8888" + line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888" state: absent - lineinfile: @@ -45,12 +45,12 @@ - lineinfile: path: /etc/yum.conf - line: "proxy_username=testuser" + line: "proxy_username=1testuser" state: present - lineinfile: path: /etc/yum.conf - line: "proxy_password=testpassword" + line: "proxy_password=1testpassword" state: present - yum: @@ -75,7 +75,7 @@ - lineinfile: path: /etc/yum.conf - line: "proxy=http://testuser:testpassword@127.0.0.1:8888" + line: "proxy=http://1testuser:1testpassword@127.0.0.1:8888" state: absent - lineinfile: @@ -85,12 +85,12 @@ - lineinfile: path: /etc/yum.conf - line: "proxy_username=testuser" + line: "proxy_username=1testuser" state: absent - lineinfile: path: /etc/yum.conf - line: "proxy_password=testpassword" + line: "proxy_password=1testpassword" state: absent when: - (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version|int == 7)