From 61b08325251aa657ac9d0ee06a1d2561b49f8483 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Stenstr=C3=B6m?= Date: Thu, 2 May 2024 23:09:17 +0200 Subject: [PATCH] Inline test_replace_slot_in_view_with_insecure_content. --- tests/test_component_as_view.py | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/tests/test_component_as_view.py b/tests/test_component_as_view.py index d471d99e..bbed9d2a 100644 --- a/tests/test_component_as_view.py +++ b/tests/test_component_as_view.py @@ -29,22 +29,8 @@ class MockInsecureComponentContext(component.Component): return self.render_to_response({"variable": ""}) -class MockInsecureComponentSlot(component.Component): - template = """ - {% load component_tags %} -
- {% slot "test_slot" %} - {% endslot %} -
- """ - - def get(self, request, *args, **kwargs) -> HttpResponse: - return self.render_to_response({}, {"test_slot": ""}) - - components_urlpatterns = [ path("test_context_insecure/", MockInsecureComponentContext.as_view()), - path("test_slot_insecure/", MockInsecureComponentSlot.as_view()), ] @@ -75,7 +61,6 @@ class TestComponentAsView(BaseTestCase): @classmethod def setUpClass(self): component.registry.register("testcomponent_context_insecure", MockInsecureComponentContext) - component.registry.register("testcomponent_slot_insecure", MockInsecureComponentSlot) def setUp(self): self.client = CustomClient() @@ -196,7 +181,20 @@ class TestComponentAsView(BaseTestCase): ) def test_replace_slot_in_view_with_insecure_content(self): - response = self.client.get("/test_slot_insecure/") + class MockInsecureComponentSlot(component.Component): + template = """ + {% load component_tags %} +
+ {% slot "test_slot" %} + {% endslot %} +
+ """ + + def get(self, request, *args, **kwargs) -> HttpResponse: + return self.render_to_response({}, {"test_slot": ""}) + + client = CustomClient(urlpatterns=[path("test_slot_insecure/", MockInsecureComponentSlot.as_view())]) + response = client.get("/test_slot_insecure/") self.assertEqual(response.status_code, 200) self.assertNotIn( b"