File tree Expand file tree Collapse file tree 1 file changed +14
-0
lines changed
instrumentation/opentelemetry-instrumentation-django/tests Expand file tree Collapse file tree 1 file changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,20 @@ def test_templated_route_get(self):
234234 self .assertEqual (span .attributes ["http.scheme" ], "http" )
235235 self .assertEqual (span .attributes ["http.status_code" ], 200 )
236236
237+ def test_when_middleware_triggers_host_check_then_raises_exception (self ):
238+ def return_host (request ):
239+ # "HttpRequest.get_host" checks for allowed hosts and raises
240+ # `django.core.DisallowedHost` if it isn't allowed.
241+ return request .get_host ()
242+
243+ with patch .object (
244+ _DjangoMiddleware , "process_request" , side_effect = return_host
245+ ) as process_mock :
246+ response = Client ().get ("/route/2020/template/" )
247+
248+ assert response .status_code == 400
249+ process_mock .assert_called_once ()
250+
237251 def test_traced_get (self ):
238252 Client ().get ("/traced/" )
239253
You can’t perform that action at this time.
0 commit comments