diff --git a/swh/core/pytest_plugin.py b/swh/core/pytest_plugin.py --- a/swh/core/pytest_plugin.py +++ b/swh/core/pytest_plugin.py @@ -11,7 +11,7 @@ from functools import partial from os import path from typing import Dict, List, Optional -from urllib.parse import urlparse +from urllib.parse import urlparse, unquote from requests.adapters import BaseAdapter from requests.structures import CaseInsensitiveDict @@ -80,10 +80,11 @@ logger.debug('get_response_cb(%s, %s)', request, context) logger.debug('url: %s', request.url) logger.debug('ignore_urls: %s', ignore_urls) - if request.url in ignore_urls: + unquoted_url = unquote(request.url) + if unquoted_url in ignore_urls: context.status_code = 404 return None - url = urlparse(request.url) + url = urlparse(unquoted_url) # http://pypi.org ~> http_pypi.org # https://files.pythonhosted.org ~> https_files.pythonhosted.org dirname = '%s_%s' % (url.scheme, url.hostname) diff --git a/swh/core/tests/data/https_forge.s.o/api_diffusion,attachments[uris]=1 b/swh/core/tests/data/https_forge.s.o/api_diffusion,attachments[uris]=1 new file mode 100644 --- /dev/null +++ b/swh/core/tests/data/https_forge.s.o/api_diffusion,attachments[uris]=1 @@ -0,0 +1 @@ +"something" diff --git a/swh/core/tests/test_pytest_plugin.py b/swh/core/tests/test_pytest_plugin.py --- a/swh/core/tests/test_pytest_plugin.py +++ b/swh/core/tests/test_pytest_plugin.py @@ -6,10 +6,20 @@ import requests from os import path +from urllib.parse import unquote from swh.core.pytest_plugin import requests_mock_datadir_factory +def test_get_response_cb_with_encoded_url(requests_mock_datadir): + # The following urls (quoted, unquoted) will be resolved as the same file + encoded_url = 'https://forge.s.o/api/diffusion?attachments%5Buris%5D=1' + for url in [encoded_url, unquote(encoded_url)]: + response = requests.get(url) + assert response.ok + assert response.json() == 'something' + + def test_get_response_cb_with_visits_nominal(requests_mock_datadir_visits): response = requests.get('https://example.com/file.json') assert response.ok