File tree Expand file tree Collapse file tree
tests/integration_tests/security Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -239,7 +239,15 @@ def guest_token(self) -> Response:
239239 $ref: '#/components/responses/500'
240240 """
241241 try :
242- body = guest_token_create_schema .load (request .json )
242+ request_json = request .get_json (silent = True )
243+ if request_json is None :
244+ return self .response_400 (
245+ message = (
246+ "Request is not JSON. Ensure the Content-Type header "
247+ "is set to 'application/json'."
248+ )
249+ )
250+ body = guest_token_create_schema .load (request_json )
243251 self .appbuilder .sm .validate_guest_token_resources (
244252 body ["resources" ], datasets = body .get ("datasets" )
245253 )
Original file line number Diff line number Diff line change @@ -175,6 +175,18 @@ def test_post_guest_token_unauthorized(self):
175175 response = self .client .post (self .uri )
176176 self .assert403 (response )
177177
178+ def test_post_guest_token_wrong_content_type (self ):
179+ """
180+ Security API: Posting a guest token request with a non-JSON
181+ Content-Type (or no body) should return a clean 400, not an
182+ unhandled 500.
183+ """
184+ self .login (ADMIN_USERNAME )
185+ response = self .client .post (
186+ self .uri , data = "not-json" , content_type = "text/plain"
187+ )
188+ self .assert400 (response )
189+
178190 @pytest .mark .usefixtures ("load_birth_names_dashboard_with_slices" )
179191 def test_post_guest_token_authorized (self ):
180192 self .dash = db .session .query (Dashboard ).filter_by (slug = "births" ).first ()
You can’t perform that action at this time.
0 commit comments