Skip to content

Add more error messages for the transactions.xml endpoint #19

Merged
bors[bot] merged 3 commits intomasterfrom
improvement/add_transactions_error_messages
Apr 17, 2018
Merged

Add more error messages for the transactions.xml endpoint #19
bors[bot] merged 3 commits intomasterfrom
improvement/add_transactions_error_messages

Conversation

@miguelsorianod
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

@unleashed unleashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looking good, check the comments

Comment thread lib/3scale/backend/listener.rb Outdated
##
##
post '/transactions.xml' do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra blank line here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok 👍

Comment thread test/integration/report_test.rb Outdated
assert_equal '', last_response.body
assert_not_equal '', last_response.body


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra blank line

@miguelsorianod miguelsorianod force-pushed the improvement/add_transactions_error_messages branch from a097289 to e621117 Compare April 17, 2018 16:00
Comment thread lib/3scale/backend/listener.rb Outdated
##
##
post '/transactions.xml' do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this diff belongs to the previous commit

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be placed in the other commit now

@miguelsorianod miguelsorianod force-pushed the improvement/add_transactions_error_messages branch from e621117 to b22c7cb Compare April 17, 2018 16:18
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
@miguelsorianod miguelsorianod force-pushed the improvement/add_transactions_error_messages branch from b22c7cb to 0de21ed Compare April 17, 2018 16:20
@unleashed
Copy link
Copy Markdown
Contributor

bors r=@eguzki,@unleashed

bors Bot added a commit that referenced this pull request Apr 17, 2018
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>
@bors
Copy link
Copy Markdown
Contributor

bors Bot commented Apr 17, 2018

Build succeeded

@bors bors Bot merged commit 0de21ed into master Apr 17, 2018
@bors bors Bot deleted the improvement/add_transactions_error_messages branch April 17, 2018 16:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants