File tree 2 files changed +27
-2
lines changed 2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,25 @@ def test_external_version_serving_old_slugs(self):
198
198
199
199
# Invalid tests
200
200
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
+
201
220
@override_settings (
202
221
RTD_EXTERNAL_VERSION_DOMAIN = 'dev.readthedocs.build' ,
203
222
)
Original file line number Diff line number Diff line change @@ -84,13 +84,19 @@ def get(self,
84
84
version_slug = version_slug ,
85
85
filename = filename ,
86
86
)
87
-
88
- # All public versions can be cached.
89
87
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
+
90
95
if (
91
96
self ._is_cache_enabled (final_project )
92
97
and version and not version .is_private
93
98
):
99
+ # All public versions can be cached.
94
100
self .cache_request = True
95
101
96
102
log .bind (
You can’t perform that action at this time.
0 commit comments