Gateway: Properly report 'not compressed, badly form-encoded' to uploaders

* This code worked if the request was *properly* form-encoded, with a
'data' key whose value was a valid message.

* It failed to detect where the request was form-encoded, with without a
'data' key.  It would just assume 'not form-encoded' in that case, then
fail later on JSON parsing.

Thus, re-use the `urlparse.parse_qs()` check for form-encoded format.
This passes:

  1. Properly, `data` key, form-encoded with valid value is fully JSON
  parsed, schema checked and accepted.
  2. *NOT* compressed *or* form-encoded valid message is properly parsed
  and accepted.
  2. Uncompressed, form-encoded, but no `data` key correctly returns the
  same error status and body as the compressed+form-encoded+no data key
  path.
This commit is contained in:
Athanasius 2022-01-07 16:45:37 +00:00
parent 872af7f594
commit 10d70bfe77

View File

@ -164,13 +164,28 @@ def get_decompressed_message():
logger.debug('Request is *NOT* form-encoded')
else:
# Uncompressed request. Bottle handles all of the parsing of the
# POST key/vals, or un-encoded body.
data_key = request.forms.get('data')
if data_key:
# This is a form-encoded POST. Support the silly people.
message_body = data_key
logger.debug('Content-Encoding indicates *not* compressed...')
form_enc_parsed = urlparse.parse_qs(request.body.read())
if form_enc_parsed:
logger.debug('Request is form-encoded')
# Uncompressed request. Bottle handles all of the parsing of the
# POST key/vals, or un-encoded body.
data_key = request.forms.get('data')
if data_key:
logger.debug('form-encoded POST request detected...')
# This is a form-encoded POST. Support the silly people.
message_body = data_key
else:
raise MalformedUploadError(
"No 'data' POST key/value found. Check your POST key "
"name for spelling, and make sure you're passing a value."
)
else:
logger.debug('Plain POST request detected...')
# This is a non form-encoded POST body.
message_body = request.body.read()