From 0365a57307aee22b2ddbeb56a0ff2fa932ec9f6c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 30 Mar 2021 10:46:02 -0700 Subject: [PATCH] Handle invalid status urls with 404 --- bookwyrm/tests/views/test_feed.py | 12 ++++++++++++ bookwyrm/views/feed.py | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/test_feed.py b/bookwyrm/tests/views/test_feed.py index 1ff99573..dd38a3eb 100644 --- a/bookwyrm/tests/views/test_feed.py +++ b/bookwyrm/tests/views/test_feed.py @@ -66,6 +66,18 @@ class FeedViews(TestCase): self.assertIsInstance(result, ActivitypubResponse) self.assertEqual(result.status_code, 200) + def test_status_page_not_found(self, *_): + """ there are so many views, this just makes sure it LOADS """ + view = views.Status.as_view() + + request = self.factory.get("") + request.user = self.local_user + with patch("bookwyrm.views.feed.is_api_request") as is_api: + is_api.return_value = False + result = view(request, "mouse", 12345) + + self.assertEqual(result.status_code, 404) + def test_status_page_with_image(self, *_): """ there are so many views, this just makes sure it LOADS """ view = views.Status.as_view() diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index eb4e370e..9f56dae5 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -115,7 +115,7 @@ class Status(View): status = models.Status.objects.select_subclasses().get( id=status_id, deleted=False ) - except ValueError: + except (ValueError, models.Status.DoesNotExist): return HttpResponseNotFound() # the url should have the poster's username in it