summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEric Avdey <eiri@eiri.ca>2021-02-17 16:50:02 -0400
committerEric Avdey <eiri@eiri.ca>2021-02-17 16:50:02 -0400
commit525716f1ce5f349da683363c73222179887b34a9 (patch)
tree3a19d8321c45f75baea9451afa3764ae50aa0474 /test
parent0805b99699388a02943877ddb2da8f3229e089a1 (diff)
downloadcouchdb-525716f1ce5f349da683363c73222179887b34a9.tar.gz
Read and validate JSON payload on POST to _changes3087-read-body-on-post-to-changes
Diffstat (limited to 'test')
-rw-r--r--test/elixir/test/changes_test.exs58
1 files changed, 58 insertions, 0 deletions
diff --git a/test/elixir/test/changes_test.exs b/test/elixir/test/changes_test.exs
index 5bb376b9c..fe7329176 100644
--- a/test/elixir/test/changes_test.exs
+++ b/test/elixir/test/changes_test.exs
@@ -228,6 +228,64 @@ defmodule ChangesTest do
end
@tag :with_db
+ test "changes filtering on custom filter", context do
+ db_name = context[:db_name]
+ create_filters_view(db_name)
+
+ resp = Couch.post("/#{db_name}/_changes?filter=changes_filter/bop")
+ assert Enum.empty?(resp.body["results"]), "db must be empty"
+
+ {:ok, doc_resp} = create_doc(db_name, %{bop: "foom"})
+ rev = doc_resp.body["rev"]
+ create_doc(db_name, %{bop: false})
+
+ resp = Couch.post("/#{db_name}/_changes?filter=changes_filter/bop")
+ assert length(resp.body["results"]) == 1
+ change_rev = get_change_rev_at(resp.body["results"], 0)
+ assert change_rev == rev
+
+ resp = Couch.post("/#{db_name}/_changes?filter=changes_filter/bop",
+ body: %{doc_ids: ["doc1", "doc3", "doc4"]},
+ headers: ["Content-Type": "application/json"]
+ )
+ assert length(resp.body["results"]) == 1
+ change_rev = get_change_rev_at(resp.body["results"], 0)
+ assert change_rev == rev
+ end
+
+ @tag :with_db
+ test "changes fail on invalid payload", context do
+ db_name = context[:db_name]
+ create_filters_view(db_name)
+
+ resp = Couch.post("/#{db_name}/_changes?filter=changes_filter/bop",
+ body: "[\"doc1\"]",
+ headers: ["Content-Type": "application/json"]
+ )
+ assert resp.status_code == 400
+ assert resp.body["error"] == "bad_request"
+ assert resp.body["reason"] == "Request body must be a JSON object"
+
+ resp = Couch.post("/#{db_name}/_changes?filter=changes_filter/bop",
+ body: "{\"doc_ids\": [\"doc1\",",
+ headers: ["Content-Type": "application/json"]
+ )
+ assert resp.status_code == 400
+ assert resp.body["error"] == "bad_request"
+ assert resp.body["reason"] == "invalid UTF-8 JSON"
+
+ set_config({"httpd", "max_http_request_size", "16"})
+
+ resp = Couch.post("/#{db_name}/_changes?filter=changes_filter/bop",
+ body: %{doc_ids: ["doc1", "doc3", "doc4"]},
+ headers: ["Content-Type": "application/json"]
+ )
+ assert resp.status_code == 413
+ assert resp.body["error"] == "too_large"
+ assert resp.body["reason"] == "the request entity is too large"
+ end
+
+ @tag :with_db
test "COUCHDB-1037-empty result for ?limit=1&filter=foo/bar in some cases",
context do
db_name = context[:db_name]