Skip to content

Commit 305b6d3

Browse files
committed
Proxito: do not serve non-existent versions
Avoid serving files that are still in the storage (S3) for some reason but its associated version was deleted or de-activated. Closes readthedocs/readthedocs-ops#1139
1 parent 5c324c9 commit 305b6d3

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

readthedocs/proxito/tests/test_full.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,25 @@ def test_external_version_serving_old_slugs(self):
198198

199199
# Invalid tests
200200

201+
def test_non_existent_version(self):
202+
url = "/en/non-existent-version/"
203+
host = "project.dev.readthedocs.io"
204+
resp = self.client.get(url, HTTP_HOST=host)
205+
self.assertEqual(resp.status_code, 404)
206+
207+
def test_inactive_version(self):
208+
url = "/en/inactive/"
209+
host = "project.dev.readthedocs.io"
210+
fixture.get(
211+
Version,
212+
verbose_name="inactive",
213+
slug="inactive",
214+
active=False,
215+
project=self.project,
216+
)
217+
resp = self.client.get(url, HTTP_HOST=host)
218+
self.assertEqual(resp.status_code, 404)
219+
201220
@override_settings(
202221
RTD_EXTERNAL_VERSION_DOMAIN='dev.readthedocs.build',
203222
)

readthedocs/proxito/views/serve.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,19 @@ def get(self,
8484
version_slug=version_slug,
8585
filename=filename,
8686
)
87-
88-
# All public versions can be cached.
8987
version = final_project.versions.filter(slug=version_slug).first()
88+
89+
# Skip serving versions that don't exist or are not active. This is to
90+
# avoid serving files that we have in the storage, but its associated
91+
# version does not exist anymore or it was de-activated
92+
if not version or not version.active:
93+
raise Http404("Version does not exist or is not active.")
94+
9095
if (
9196
self._is_cache_enabled(final_project)
9297
and version and not version.is_private
9398
):
99+
# All public versions can be cached.
94100
self.cache_request = True
95101

96102
log.bind(

0 commit comments

Comments
 (0)