From ee754467667f00ca9f475bdfcb4a0365c84eff33 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 23 Apr 2020 14:29:04 -0500 Subject: [PATCH 1/2] Make tests fail --- readthedocs/proxito/tests/handler_404_urls.py | 2 +- readthedocs/proxito/tests/test_full.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/readthedocs/proxito/tests/handler_404_urls.py b/readthedocs/proxito/tests/handler_404_urls.py index c918a709394..f39180c8efb 100644 --- a/readthedocs/proxito/tests/handler_404_urls.py +++ b/readthedocs/proxito/tests/handler_404_urls.py @@ -25,7 +25,7 @@ def inner_view(request, exception, *args, **kwargs): return view_func( request, *args, - proxito_path=request.get_full_path(), + proxito_path=request.path, **kwargs, ) return inner_view diff --git a/readthedocs/proxito/tests/test_full.py b/readthedocs/proxito/tests/test_full.py index 2d91803e40d..d022846825a 100644 --- a/readthedocs/proxito/tests/test_full.py +++ b/readthedocs/proxito/tests/test_full.py @@ -333,8 +333,7 @@ def test_directory_indexes_get_args(self): self.project.versions.update(active=True, built=True) # Confirm we've serving from storage for the `index-exists/index.html` file response = self.client.get( - reverse('proxito_404_handler', kwargs={ - 'proxito_path': '/en/latest/index-exists?foo=bar'}), + reverse('proxito_404_handler', kwargs={'proxito_path': '/en/latest/index-exists'}) + '?foo=bar', HTTP_HOST='project.readthedocs.io', ) self.assertEqual( From d0ec6c6af48ade94d4b6da743e2ae555d30ff420 Mon Sep 17 00:00:00 2001 From: Santos Gallegos Date: Thu, 23 Apr 2020 14:29:26 -0500 Subject: [PATCH 2/2] Fix tests --- readthedocs/proxito/views/mixins.py | 2 ++ readthedocs/proxito/views/serve.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/readthedocs/proxito/views/mixins.py b/readthedocs/proxito/views/mixins.py index 4d62afe5376..8931e87eedd 100644 --- a/readthedocs/proxito/views/mixins.py +++ b/readthedocs/proxito/views/mixins.py @@ -205,6 +205,8 @@ def get_redirect_response(self, request, redirect_path, proxito_path, http_statu """ schema, netloc, path, params, query, fragments = urlparse(proxito_path) + # `proxito_path` doesn't include query params. + query = urlparse(request.get_full_path()).query new_path = urlunparse((schema, netloc, redirect_path, params, query, fragments)) # Re-use the domain and protocol used in the current request. diff --git a/readthedocs/proxito/views/serve.py b/readthedocs/proxito/views/serve.py index 91f844d3b1b..5ad268315d9 100644 --- a/readthedocs/proxito/views/serve.py +++ b/readthedocs/proxito/views/serve.py @@ -235,7 +235,13 @@ def get(self, request, proxito_path, template_name='404.html'): new_path = parts.path.rstrip('/') + f'/{tryfile}' else: new_path = parts.path.rstrip('/') + '/' - new_parts = parts._replace(path=new_path) + + # `proxito_path` doesn't include query params.` + query = urlparse(request.get_full_path()).query + new_parts = parts._replace( + path=new_path, + query=query, + ) redirect_url = new_parts.geturl() # TODO: decide if we need to check for infinite redirect here