This is an automated email from the ASF dual-hosted git repository. garren pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/master by this push: new a54f420 Send correct 400 for missing partition with _find (#1936) a54f420 is described below commit a54f420b21c124143c377148bcee2ecaeaa355e7 Author: garren smith <garren.sm...@gmail.com> AuthorDate: Mon Feb 25 18:39:54 2019 +0200 Send correct 400 for missing partition with _find (#1936) When sending an incorrect partition query e.g: /parition/_find, send a 400 with the message: Partition must not start with an underscore This makes it consistent with all the other partition requests --- src/chttpd/src/chttpd_db.erl | 5 +++++ test/elixir/test/partition_mango_test.exs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl index 003b0d8..5a09115 100644 --- a/src/chttpd/src/chttpd_db.erl +++ b/src/chttpd/src/chttpd_db.erl @@ -274,6 +274,11 @@ handle_partition_req(#httpd{method='GET', path_parts=[_,_,PartId]}=Req, Db) -> throw({bad_request, <<"database is not partitioned">>}) end; +handle_partition_req(#httpd{method='POST', + path_parts=[_, <<"_partition">>, <<"_", _/binary>>]}, _Db) -> + Msg = <<"Partition must not start with an underscore">>, + throw({illegal_partition, Msg}); + handle_partition_req(#httpd{path_parts = [_, _, _]}=Req, _Db) -> send_method_not_allowed(Req, "GET"); diff --git a/test/elixir/test/partition_mango_test.exs b/test/elixir/test/partition_mango_test.exs index 68a26e1..5a59789 100644 --- a/test/elixir/test/partition_mango_test.exs +++ b/test/elixir/test/partition_mango_test.exs @@ -610,4 +610,27 @@ defmodule PartitionMangoTest do assert length(partitions) == 50 assert_correct_partition(partitions, "foo") end + + @tag :with_partitioned_db + test "partitioned _find and _explain with missing partition returns 400", context do + db_name = context[:db_name] + + selector = %{ + selector: %{ + some: "field" + } + } + + resp = Couch.get("/#{db_name}/_partition/_find", body: selector) + validate_missing_partition(resp) + + resp = Couch.get("/#{db_name}/_partition/_explain", body: selector) + validate_missing_partition(resp) + end + + defp validate_missing_partition(resp) do + assert resp.status_code == 400 + %{:body => %{"reason" => reason}} = resp + assert Regex.match?(~r/Partition must not start/, reason) + end end