If you pass a bytestring to validate(), and it doesn't decode cleanly, log this and exit gracefully.

There's still a remaining issue: we always decode the bytestring as UTF-8, but it might not be. Marked with XXX.

Hence also: log.info() the incoming message before attempting to decode the bytestring.

Also: don't bother logging when we've launched the validation task, since that always succeeds.
status-serialisers
Marnanel Thurman 2020-09-21 17:52:07 +01:00
rodzic 0679cb12ae
commit 9afc7dd220
1 zmienionych plików z 9 dodań i 5 usunięć

Wyświetl plik

@ -103,14 +103,20 @@ def validate(path, headers, body):
import kepi.trilby_api.models as trilby_models
if isinstance(body, bytes):
body = str(body, encoding='UTF-8')
logger.info('Begin validation. Body is %s',
body)
logger.info('and headers are %s',
headers)
if isinstance(body, bytes):
try:
# XXX It might not be UTF-8; we have to check the headers
body = str(body, encoding='UTF-8')
except UnicodeDecodeError as ude:
logger.info(" -- failed validation: invalid encoding: %s",
ude)
return
# make sure this is a real dict.
# httpsig.utils.CaseInsensitiveDict doesn't
# reimplement get(), which cases confusion.
@ -132,8 +138,6 @@ def validate(path, headers, body):
logger.debug('%s: invoking the validation task',
message.id)
_run_validation(message.id)
logger.debug('%s: finished invoking the validation task',
message.id)
@shared_task()
def _run_validation(