Skip to content

Commit

Permalink
Fix HTTP-proxy in ULN-remotes
Browse files Browse the repository at this point in the history
backports #9647
https://pulp.plan.io/issues/9647

fixes #9653
[nocoverage]

(cherry picked from commit 99295f5)
  • Loading branch information
dralley committed Dec 21, 2021
1 parent cf99090 commit a08c269
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGES/9653.bugfix
@@ -0,0 +1,2 @@
Fix HTTP-proxy support for ULN-remotes
(backported from #9647)
20 changes: 17 additions & 3 deletions pulp_rpm/app/downloaders.py
Expand Up @@ -170,7 +170,9 @@ async def _run(self, extra_data=None):
SERVER_URL = os.path.join(self.uln_server_base_url, "rpc/api")

# set proxy for authentification
client = AllowProxyServerProxy(SERVER_URL, proxy=self.proxy, auth=self.auth)
client = AllowProxyServerProxy(
SERVER_URL, proxy=self.proxy, proxy_auth=self.proxy_auth, auth=self.auth
)
if not self.session_key:
self.session_key = await client["auth.login"](self.username, self.password)
if len(self.session_key) != 43:
Expand All @@ -182,7 +184,7 @@ async def _run(self, extra_data=None):
path = parsed.path.lstrip("/")
url = os.path.join(self.uln_server_base_url, "XMLRPC/GET-REQ", channelLabel, path)
async with self.session.get(
url, proxy=self.proxy, auth=self.auth, headers=self.headers
url, proxy=self.proxy, proxy_auth=self.proxy_auth, auth=self.auth, headers=self.headers
) as response:
self.raise_for_status(response)
to_return = await self._handle_response(response)
Expand All @@ -203,11 +205,12 @@ class AllowProxyServerProxy(ServerProxy):
This only works for http connection to the proxy, https connections are not supported!
"""

def __init__(self, *args, proxy, auth, **kwargs):
def __init__(self, *args, proxy, proxy_auth, auth, **kwargs):
"""
Initialisation with proxy.
"""
self.proxy = proxy
self.proxy_auth = proxy_auth
self.auth = auth
super().__init__(*args, **kwargs)

Expand All @@ -224,8 +227,19 @@ async def __remote_call(self, method_name, *args, **kwargs):
),
headers=self.headers,
proxy=self.proxy,
proxy_auth=self.proxy_auth,
auth=self.auth,
) as response:
response.raise_for_status()

return self._parse_response((await response.read()), method_name)

def __getitem__(self, method_name):
"""
Dynamically create method for item.
"""

def method(*args, **kwargs):
return self.__remote_call(method_name, *args, **kwargs)

return method
8 changes: 4 additions & 4 deletions pulp_rpm/tests/unit/test_uln_download.py
@@ -1,9 +1,8 @@
import aiohttp_xmlrpc
import asyncio
import asynctest
import os

from pulp_rpm.app.downloaders import UlnDownloader, UlnCredentialsError
from pulp_rpm.app.downloaders import UlnDownloader, UlnCredentialsError, AllowProxyServerProxy


class TestUlnDownloader(asynctest.TestCase):
Expand Down Expand Up @@ -85,7 +84,7 @@ def create_Future(self, *args):
f.set_result(None)
return f

@asynctest.patch.object(aiohttp_xmlrpc.client.ServerProxy, "__getitem__")
@asynctest.patch.object(AllowProxyServerProxy, "__getitem__")
@asynctest.patch("aiohttp.ClientSession")
def test_valid_auth(self, mock_session, mock_getitem):
"""
Expand Down Expand Up @@ -121,11 +120,12 @@ def test_valid_auth(self, mock_session, mock_getitem):
mock_session.get.assert_called_with(
repomd_url,
proxy=self.downloader.proxy,
proxy_auth=self.downloader.proxy_auth,
auth=self.downloader.auth,
headers=self.downloader.headers,
)

@asynctest.patch.object(aiohttp_xmlrpc.client.ServerProxy, "__getitem__")
@asynctest.patch.object(AllowProxyServerProxy, "__getitem__")
@asynctest.patch("aiohttp.ClientSession")
def test_invalid_auth(self, mock_session, mock_getitem):
"""
Expand Down

0 comments on commit a08c269

Please sign in to comment.