New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make changes feed return bad request for invalid heartbeat values #2270
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution @bessbd.
Would you mind writing a test case for it.
You can use any of the available test suites:
- exunit : see examples
- eunit :
- exunit integration suite :
- see examples in the https://github.com/apache/couchdb/blob/master/test/elixir/test/ directory
src/chttpd/src/chttpd_db.erl
Outdated
Args#changes_args{heartbeat=list_to_integer(Value)}; | ||
try list_to_integer(Value) of | ||
V when V > 0 -> | ||
Args#changes_args{heartbeat=heartbeat_integer}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think heartbeat_integer
is correct.
Args#changes_args{heartbeat=heartbeat_integer};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call! I've just pushed a commit to fix this.
I am so sorry I missed the fact that you have some tests |
src/chttpd/src/chttpd_db.erl
Outdated
HeartbeatInteger when HeartbeatInteger > 0 -> | ||
Args#changes_args{heartbeat=HeartbeatInteger}; | ||
_ -> | ||
throw({bad_request, <<"Negative heartbeat value">>}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "Negative heartbeat value" doesn't sound correct if user pass 0
. Should we change the wording to something like:
- The heartbeat value should be positive integer (in milliseconds)
src/chttpd/src/chttpd_db.erl
Outdated
_ -> | ||
throw({bad_request, <<"Negative heartbeat value">>}) | ||
catch error:badarg -> | ||
throw({bad_request, <<"Invalid heartbeat value">>}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to give user a hint. Something like:
<<"Invalid heartbeat value. Expecting positive integer value (in milliseconds).">>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 conditional to CI pass
@bessbd Could you squash commits. |
Using a negative heartbeat value does not return a 400 bad request, instead getting just an empty response with no status code at all. This commit adds extra checks so that negative and non-integer heartbeat values return 400 bad request responses. This fixes apache#2234
cabe4c4
to
a47f0fa
Compare
Done! |
Thank you for your contribution. |
Thank you for the review and the merge, @iilyak ! |
Overview
Using a negative heartbeat value does not return a 400 bad request, instead getting just an empty response with no status code at all.
This commit adds extra checks so that negative and non-integer heartbeat values return 400 bad request responses.
Testing recommendations
The changes has been tested manually:
Also, there are new test cases added for the new behavior.
Related Issues or Pull Requests
This fixes #2234
Checklist
rel/overlay/etc/default.ini