Add more error messages for the transactions.xml endpoint #19
Add more error messages for the transactions.xml endpoint #19
Conversation
unleashed
left a comment
There was a problem hiding this comment.
looking good, check the comments
| ## | ||
| ## | ||
| post '/transactions.xml' do | ||
|
|
There was a problem hiding this comment.
I have fixed the formatting issues with blank the blank lines in a new forced push
| end | ||
|
|
||
| if transactions.any? { |_id, data| data.nil? } | ||
| raise TransactionsHasNilTransaction |
There was a problem hiding this comment.
can this actually happen? all the cases I imagine where a hash has a key the "data"/value part of it should not be nil but at most an empty string.
There was a problem hiding this comment.
This can happen.
For example, I reproduced the problem by performing the following request (see the last transactions specified without values):
[<username>@localhost apisonator]$ curl -X POST -v '127.0.0.1:3000/transactions.xml' -d 'provider_key=provider_keytest&transactions[0][app_id]=5207&transactions[0][usage][hits]=1&transactions[0][timestamp]=2018-04-17 10:13:11 UTC&transactions[1]'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 3000 (#0)
> POST /transactions.xml HTTP/1.1
> Host: 127.0.0.1:3000
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Length: 156
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 156 out of 156 bytes
< HTTP/1.1 400 Bad Request
< Content-Type: application/vnd.3scale-v2.0+xml
< Access-Control-Allow-Origin: *
< Access-Control-Expose-Headers: ETag, Link, 3scale-rejection-reason
< X-Content-Type-Options: nosniff
< Transfer-Encoding: chunked
<
* Connection #0 to host 127.0.0.1 left intact
<?xml version="1.0" encoding="UTF-8"?><error code="transactions_has_nil_transaction">transactions has a nil transaction</error>[<username>@localhost apisonator]$
The test 'returns error if any of the reported transactions are nil' in test/integration/report_test.rb also reproduces the nil error message.
| assert_equal '', last_response.body | ||
| assert_not_equal '', last_response.body | ||
|
|
||
|
|
a097289 to
e621117
Compare
| ## | ||
| ## | ||
| post '/transactions.xml' do | ||
|
|
There was a problem hiding this comment.
this diff belongs to the previous commit
There was a problem hiding this comment.
Should be placed in the other commit now
e621117 to
b22c7cb
Compare
We log a message if a request in transactions.xml has a params hash that is nil. We have manually verified that this should never happen. If we do not detect any log message after this commit then we will remove the params nil checking in all routings
…nvalid We now return a proper 400 error code with some information in XML format when the following situations are detected: · The transactions parameter is blank · The transactions parameter is not a hash · Some transaction of the transactions parameter is nil
We test that the following situations are handled: · The transactions parameter is blank · The transactions parameter is not a hash · Some transaction of the transactions parameter is nil
b22c7cb to
0de21ed
Compare
|
bors r=@eguzki,@unleashed |
19: Add more error messages for the transactions.xml endpoint r=eguzki,unleashed a=miguelsorianod We now return a proper 400 error code with some information in XML format when the following situations are detected: · The transactions parameter is blank · The transactions parameter is not a hash · Some transaction of the transactions parameter is nil Also, we have added temporary logging to confirm that the params hash can never be nil and we'll remove the checking of the nil value and the logging if we do not detect related logs for a while. Co-authored-by: Miguel Soriano <msoriano@redhat.com>
Build succeeded |
We now return a proper 400 error code with some information in XML
format when the following situations are detected:
· The transactions parameter is blank
· The transactions parameter is not a hash
· Some transaction of the transactions parameter is nil
Also, we have added temporary logging to confirm that the params hash can never be nil and we'll remove the checking of the nil value and the logging if we do not detect related logs for a while.