summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgarren smith <garren.smith@gmail.com>2019-02-25 18:39:54 +0200
committerGitHub <noreply@github.com>2019-02-25 18:39:54 +0200
commita54f420b21c124143c377148bcee2ecaeaa355e7 (patch)
treeab1b66ddc78d92fac1760c98e8e2dd6f23f0d911
parent94b9abe8a994b49f075739348ef73eec1e9f343d (diff)
downloadcouchdb-a54f420b21c124143c377148bcee2ecaeaa355e7.tar.gz
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
-rw-r--r--src/chttpd/src/chttpd_db.erl5
-rw-r--r--test/elixir/test/partition_mango_test.exs23
2 files changed, 28 insertions, 0 deletions
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 003b0d8dc..5a0911559 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 68a26e169..5a5978915 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