@@ -494,6 +494,48 @@ def validate_name_length(
494494 return json_dump (body )
495495
496496
497+ @wrapt .decorator
498+ def validate_name_characters_in_range (
499+ wrapped : Callable [..., str ],
500+ instance : Any , # pylint: disable=unused-argument
501+ args : Tuple [_RequestObjectProxy , _Context ],
502+ kwargs : Dict ,
503+ ) -> str :
504+ """
505+ Validate the characters in the name argument given to a VWS endpoint.
506+
507+ Args:
508+ wrapped: An endpoint function for `requests_mock`.
509+ instance: The class that the endpoint function is in.
510+ args: The arguments given to the endpoint function.
511+ kwargs: The keyword arguments given to the endpoint function.
512+
513+ Returns:
514+ The result of calling the endpoint.
515+ An ``INTERNAL_SERVER_ERROR`` response if the name is given includes
516+ characters outside of the accepted range.
517+ """
518+ request , context = args
519+
520+ if not request .text :
521+ return wrapped (* args , ** kwargs )
522+
523+ if 'name' not in request .json ():
524+ return wrapped (* args , ** kwargs )
525+
526+ name = request .json ()['name' ]
527+
528+ if all (ord (character ) <= 65535 for character in name ):
529+ return wrapped (* args , ** kwargs )
530+
531+ context .status_code = codes .INTERNAL_SERVER_ERROR
532+ body = {
533+ 'transaction_id' : uuid .uuid4 ().hex ,
534+ 'result_code' : ResultCodes .FAIL .value ,
535+ }
536+ return json_dump (body )
537+
538+
497539@wrapt .decorator
498540def validate_image_format (
499541 wrapped : Callable [..., str ],
0 commit comments