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 2023/11/20 19:20:57 UTC
(couchdb) branch fix-users-db-tests created (now 351e700eb)
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a change to branch fix-users-db-tests
in repository https://gitbox.apache.org/repos/asf/couchdb.git
at 351e700eb Attempt to fix flaky users db security test
This branch includes the following new commits:
new 351e700eb Attempt to fix flaky users db security test
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(couchdb) 01/01: Attempt to fix flaky users db security test
Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
vatamane pushed a commit to branch fix-users-db-tests
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 351e700eb4d2b3101345a8017d6ba93207397eef
Author: Nick Vatamaniuc <va...@gmail.com>
AuthorDate: Mon Nov 20 14:14:58 2023 -0500
Attempt to fix flaky users db security test
* Reset _users db before and after use to avoid polluting other tests.
* Use a common reset db and "wait for auth cache" helper function
* Since we're testing chttpd auth don't bother also setting httpd
authentication_db, that just stops and resets the local port httpd listener,
but we're not testing backend auth.
* Use a retry in login for security db to avoid flakiness
---
test/elixir/lib/couch/dbtest.ex | 17 ++++++++++++++++
test/elixir/test/cookie_auth_test.exs | 25 +++---------------------
test/elixir/test/reader_acl_test.exs | 3 +--
test/elixir/test/security_validation_test.exs | 14 +++++++++++---
test/elixir/test/users_db_security_test.exs | 28 ++++-----------------------
test/elixir/test/users_db_test.exs | 18 +++--------------
6 files changed, 39 insertions(+), 66 deletions(-)
diff --git a/test/elixir/lib/couch/dbtest.ex b/test/elixir/lib/couch/dbtest.ex
index a833582a7..0bcc50af6 100644
--- a/test/elixir/lib/couch/dbtest.ex
+++ b/test/elixir/lib/couch/dbtest.ex
@@ -179,6 +179,23 @@ defmodule Couch.DBTest do
{:ok, resp}
end
+ def reset_db(db_name, opts \\ []) do
+ delete_db(db_name)
+ create_db(db_name, opts)
+ end
+
+ def wait_for_design_auth(users_db) do
+ retry_until(fn ->
+ resp =
+ Couch.get(
+ "/#{users_db}/_changes",
+ query: [feed: "longpoll", timeout: 5000, filter: "_design"]
+ )
+ results = resp.body["results"]
+ is_list(results) && length(results) > 0
+ end, 500, 60_000)
+ end
+
def create_doc(db_name, body) do
resp = Couch.post("/#{db_name}", body: body)
assert resp.status_code in [201, 202]
diff --git a/test/elixir/test/cookie_auth_test.exs b/test/elixir/test/cookie_auth_test.exs
index 000b1d623..cf9b36c7f 100644
--- a/test/elixir/test/cookie_auth_test.exs
+++ b/test/elixir/test/cookie_auth_test.exs
@@ -31,32 +31,13 @@ defmodule CookieAuthTest do
@password "3.141592653589"
setup do
- # Create db if not exists
- Couch.put("/#{@users_db}")
-
- retry_until(fn ->
- resp =
- Couch.get(
- "/#{@users_db}/_changes",
- query: [feed: "longpoll", timeout: 5000, filter: "_design"]
- )
- length(resp.body["results"]) > 0
- end)
-
+ reset_db(@users_db)
+ wait_for_design_auth(@users_db)
on_exit(&tear_down/0)
-
- :ok
end
defp tear_down do
- # delete users
- user = URI.encode("org.couchdb.user:jchris")
- user_doc = Couch.get("/#{@users_db}/#{URI.encode(user)}").body
- Couch.delete("/#{@users_db}/#{user}", query: [rev: user_doc["_rev"]])
-
- user = URI.encode("org.couchdb.user:Jason Davies")
- user_doc = Couch.get("/#{@users_db}/#{user}").body
- Couch.delete("/#{@users_db}/#{user}", query: [rev: user_doc["_rev"]])
+ reset_db(@users_db)
end
defp login(user, password) do
diff --git a/test/elixir/test/reader_acl_test.exs b/test/elixir/test/reader_acl_test.exs
index f65e7cbf6..6ed17e5ab 100644
--- a/test/elixir/test/reader_acl_test.exs
+++ b/test/elixir/test/reader_acl_test.exs
@@ -19,8 +19,7 @@ defmodule ReaderACLTest do
}
]
setup do
- # Create db if not exists
- Couch.put("/#{@users_db_name}")
+ reset_db(@users_db_name)
# create a user with top-secret-clearance
user_doc =
diff --git a/test/elixir/test/security_validation_test.exs b/test/elixir/test/security_validation_test.exs
index 5c8db1b45..8834e17f5 100644
--- a/test/elixir/test/security_validation_test.exs
+++ b/test/elixir/test/security_validation_test.exs
@@ -54,12 +54,14 @@ defmodule SecurityValidationTest do
setup_all do
auth_db_name = random_db_name()
{:ok, _} = create_db(auth_db_name)
- on_exit(fn -> delete_db(auth_db_name) end)
+ on_exit(fn ->
+ delete_db(auth_db_name)
+ reset_db("_users")
+ end)
configs = [
- {"httpd", "authentication_handlers",
+ {"chttpd", "authentication_handlers",
"{couch_httpd_auth, cookie_authentication_handler}, {couch_httpd_auth, default_authentication_handler}"},
- {"couch_httpd_auth", "authentication_db", auth_db_name},
{"chttpd_auth", "authentication_db", auth_db_name}
]
@@ -84,6 +86,12 @@ defmodule SecurityValidationTest do
assert Couch.post("/#{auth_db_name}", body: doc).body["ok"]
end)
+ # Reset users db to force the auth cache to restart and use
+ # the new auth db
+ reset_db("_users")
+
+ wait_for_design_auth(auth_db_name)
+
{:ok, [auth_db_name: auth_db_name]}
end
diff --git a/test/elixir/test/users_db_security_test.exs b/test/elixir/test/users_db_security_test.exs
index 428541353..3c1a7e8e3 100644
--- a/test/elixir/test/users_db_security_test.exs
+++ b/test/elixir/test/users_db_security_test.exs
@@ -15,33 +15,13 @@ defmodule UsersDbSecurityTest do
}
setup_all do
- # Create db if not exists
- Couch.put("/#{@users_db}")
-
- retry_until(fn ->
- resp =
- Couch.get(
- "/#{@users_db}/_changes",
- query: [feed: "longpoll", timeout: 5000, filter: "_design"]
- )
-
- length(resp.body["results"]) > 0
- end)
-
+ reset_db(@users_db)
+ wait_for_design_auth(@users_db)
on_exit(&tear_down/0)
-
- :ok
end
defp tear_down do
- users = Map.keys(@login_user)
- Enum.each(users, fn name ->
- resp = Couch.get("/#{@users_db}/org.couchdb.user:#{name}")
- if resp.status_code == 200 do
- rev = resp.body["_rev"]
- Couch.delete("/#{@users_db}/org.couchdb.user:#{name}?rev=#{rev}")
- end
- end)
+ reset_db(@users_db)
end
defp login_as(user, password \\ nil) do
@@ -51,7 +31,7 @@ defmodule UsersDbSecurityTest do
_ -> password
end
- sess = Couch.login(user, pwd)
+ sess = retry_until(fn -> Couch.login(user, pwd) end, 500, 60_000)
assert sess.cookie, "Login correct is expected"
sess
end
diff --git a/test/elixir/test/users_db_test.exs b/test/elixir/test/users_db_test.exs
index a13c1a4f3..bc09df9ba 100644
--- a/test/elixir/test/users_db_test.exs
+++ b/test/elixir/test/users_db_test.exs
@@ -29,25 +29,13 @@ defmodule UsersDbTest do
]
setup do
- # Create db if not exists
- Couch.put("/#{@users_db_name}")
-
- resp =
- Couch.get(
- "/#{@users_db_name}/_changes",
- query: [feed: "longpoll", timeout: 5000, filter: "_design"]
- )
-
- assert resp.body
-
+ reset_db(@users_db_name)
+ wait_for_design_auth(@users_db_name)
on_exit(&tear_down/0)
-
- :ok
end
defp tear_down do
- delete_db(@users_db_name)
- create_db(@users_db_name)
+ reset_db(@users_db_name)
end
defp save_as(db_name, doc, options) do