You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by va...@apache.org on 2022/09/16 02:45:17 UTC
[couchdb] branch main updated: add test coverage to prevent junk in eventsource
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/couchdb.git
The following commit(s) were added to refs/heads/main by this push:
new d7ee5049f add test coverage to prevent junk in eventsource
d7ee5049f is described below
commit d7ee5049f529382620b900fdf4d49d985c6c4018
Author: Zach Lankton <za...@gmail.com>
AuthorDate: Fri Sep 16 00:05:46 2022 +0000
add test coverage to prevent junk in eventsource
eventsource events should only ever contain data, id, event
or empty lines
adding a test to ensure that new code/changes
will not break this rule
---
test/elixir/test/changes_async_test.exs | 24 ++++++++++++++++++++++++
test/elixir/test/config/suite.elixir | 1 +
2 files changed, 25 insertions(+)
diff --git a/test/elixir/test/changes_async_test.exs b/test/elixir/test/changes_async_test.exs
index 6c833d433..5f174de1d 100644
--- a/test/elixir/test/changes_async_test.exs
+++ b/test/elixir/test/changes_async_test.exs
@@ -103,6 +103,30 @@ defmodule ChangesAsyncTest do
HTTPotion.stop_worker_process(worker_pid)
end
+ @tag :with_db
+ test "eventsource no junk in response", context do
+ db_name = context[:db_name]
+
+ check_empty_db(db_name)
+ create_doc(db_name, sample_doc_foo())
+ create_doc_bar(db_name, "bar")
+
+ resp = Rawresp.get("/#{db_name}/_changes?feed=eventsource&timeout=500")
+
+ lines = String.split(resp.body, "\n")
+
+ all_lines = lines
+ |> Enum.map(fn p -> Enum.at(String.split(p, ":"), 0) end)
+
+ allowed = ["", "data", "id", "event"]
+
+ allowed_lines = all_lines
+ |> Enum.filter(fn p -> Enum.member?(allowed, p) end)
+
+ assert length(all_lines) == length(allowed_lines)
+
+ end
+
@tag :with_db
test "eventsource heartbeat", context do
db_name = context[:db_name]
diff --git a/test/elixir/test/config/suite.elixir b/test/elixir/test/config/suite.elixir
index 265e600db..91763989b 100644
--- a/test/elixir/test/config/suite.elixir
+++ b/test/elixir/test/config/suite.elixir
@@ -101,6 +101,7 @@
"continuous filtered changes",
"continuous filtered changes with doc ids",
"eventsource changes",
+ "eventsource no junk in response",
"eventsource heartbeat",
"live changes",
"longpoll changes",