@@ -39,7 +39,9 @@ def test_404s_by_default(self):
3939 def test_logs_request_data_if_option_enabled (
4040 self , mock_logger_info : MagicMock , mock_metrics_incr : MagicMock
4141 ):
42- response = self .client .post (self .url , self .report_data )
42+ response = self .client .post (
43+ self .url , self .report_data , content_type = "application/reports+json"
44+ )
4345
4446 assert response .status_code == status .HTTP_200_OK
4547 mock_logger_info .assert_any_call (
@@ -48,3 +50,15 @@ def test_logs_request_data_if_option_enabled(
4850 mock_metrics_incr .assert_any_call (
4951 "browser_reporting.raw_report_received" , tags = {"type" : self .report_data ["type" ]}
5052 )
53+
54+ @override_options ({"issues.browser_reporting.collector_endpoint_enabled" : True })
55+ @patch ("sentry.issues.endpoints.browser_reporting_collector.metrics.incr" )
56+ def test_rejects_invalid_content_type (self , mock_metrics_incr : MagicMock ):
57+ """Test that the endpoint rejects invalid content type and does not call the browser reporting metric"""
58+ response = self .client .post (self .url , self .report_data , content_type = "bad/type/json" )
59+
60+ assert response .status_code == status .HTTP_415_UNSUPPORTED_MEDIA_TYPE
61+ # Verify that the browser_reporting.raw_report_received metric was not called
62+ # Check that none of the calls were for the browser_reporting.raw_report_received metric
63+ for call in mock_metrics_incr .call_args_list :
64+ assert call [0 ][0 ] != "browser_reporting.raw_report_received"
0 commit comments