diff options
author | Eric Avdey <eiri@eiri.ca> | 2018-08-30 09:40:00 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-30 09:40:00 -0300 |
commit | b2b6988e65af7273ddd8b9223b2236c3d182c779 (patch) | |
tree | 1bcc5b84aae100811feee129467f269ac59e0140 | |
parent | cf7e92deab53e2cfbf5912816e646fb7e7d1067c (diff) | |
download | couchdb-b2b6988e65af7273ddd8b9223b2236c3d182c779.tar.gz |
Check if db exists in /db/_ensure_full_commit call (#1588)
We removed a security call in `do_db_req` to avoid
a duplicate authorization check and as a result
there are now no db validation in noop call
`/db/_ensure_full_commit`. This makes it always
return a success code, even for missing databases.
This fix places the security check back, directly
in _ensure_full_commit call and adds eunit tests
for a good measure.
-rw-r--r-- | src/chttpd/src/chttpd_db.erl | 7 | ||||
-rw-r--r-- | src/chttpd/test/chttpd_db_test.erl | 22 |
2 files changed, 28 insertions, 1 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl index d3655c35d..49d7b5849 100644 --- a/src/chttpd/src/chttpd_db.erl +++ b/src/chttpd/src/chttpd_db.erl @@ -375,8 +375,13 @@ db_req(#httpd{method='POST', path_parts=[DbName], user_ctx=Ctx}=Req, Db) -> db_req(#httpd{path_parts=[_DbName]}=Req, _Db) -> send_method_not_allowed(Req, "DELETE,GET,HEAD,POST"); -db_req(#httpd{method='POST',path_parts=[_,<<"_ensure_full_commit">>]}=Req, _Db) -> +db_req(#httpd{method='POST', path_parts=[DbName, <<"_ensure_full_commit">>], + user_ctx=Ctx}=Req, _Db) -> chttpd:validate_ctype(Req, "application/json"), + %% use fabric call to trigger a database_does_not_exist exception + %% for missing databases that'd return error 404 from chttpd + %% get_security used to prefer shards on the same node over other nodes + fabric:get_security(DbName, [{user_ctx, Ctx}]), send_json(Req, 201, {[ {ok, true}, {instance_start_time, <<"0">>} diff --git a/src/chttpd/test/chttpd_db_test.erl b/src/chttpd/test/chttpd_db_test.erl index 636603710..2708aa033 100644 --- a/src/chttpd/test/chttpd_db_test.erl +++ b/src/chttpd/test/chttpd_db_test.erl @@ -61,6 +61,8 @@ all_test_() -> fun setup/0, fun teardown/1, [ fun should_return_ok_true_on_bulk_update/1, + fun should_return_ok_true_on_ensure_full_commit/1, + fun should_return_404_for_ensure_full_commit_on_no_db/1, fun should_accept_live_as_an_alias_for_continuous/1, fun should_return_404_for_delete_att_on_notadoc/1, fun should_return_409_for_del_att_without_rev/1, @@ -100,6 +102,26 @@ should_return_ok_true_on_bulk_update(Url) -> end). +should_return_ok_true_on_ensure_full_commit(Url0) -> + ?_test(begin + Url = Url0 ++ "/_ensure_full_commit", + {ok, RC, _, Body} = test_request:post(Url, [?CONTENT_JSON, ?AUTH], []), + {Json} = ?JSON_DECODE(Body), + ?assertEqual(201, RC), + ?assert(couch_util:get_value(<<"ok">>, Json)) + end). + + +should_return_404_for_ensure_full_commit_on_no_db(Url0) -> + ?_test(begin + Url = Url0 ++ "-missing-db" ++ "/_ensure_full_commit", + {ok, RC, _, Body} = test_request:post(Url, [?CONTENT_JSON, ?AUTH], []), + {Json} = ?JSON_DECODE(Body), + ?assertEqual(404, RC), + ?assertEqual(<<"not_found">>, couch_util:get_value(<<"error">>, Json)) + end). + + should_accept_live_as_an_alias_for_continuous(Url) -> GetLastSeq = fun(Bin) -> Parts = binary:split(Bin, <<"\n">>, [global]), |