summaryrefslogtreecommitdiff
path: root/test/elixir/test/users_db_test.exs
diff options
context:
space:
mode:
Diffstat (limited to 'test/elixir/test/users_db_test.exs')
-rw-r--r--test/elixir/test/users_db_test.exs125
1 files changed, 125 insertions, 0 deletions
diff --git a/test/elixir/test/users_db_test.exs b/test/elixir/test/users_db_test.exs
index db86b2739..7c678c4f0 100644
--- a/test/elixir/test/users_db_test.exs
+++ b/test/elixir/test/users_db_test.exs
@@ -299,4 +299,129 @@ defmodule UsersDbTest do
assert resp.body["userCtx"]["name"] == "foo@example.org"
end
+
+ test "users password requirements", _context do
+ set_config({
+ "couch_httpd_auth",
+ "password_regexp",
+ Enum.join(
+ [
+ "[{\".{10,}\"},", # 10 chars
+ "{\"[A-Z]+\", \"Requirement 2.\"},", # a uppercase char
+ "{\"[a-z]+\", \"\"},", # a lowercase char
+ "{\"\\\\d+\", \"Req 4.\"},", # A number
+ "\"[!\.,\(\)]+\"]" # A special char
+ ],
+ " "
+ )
+ })
+
+ session = login("jan", "apple")
+
+ # With password that doesn't confirm to any requirement.
+ # Requirement doesn't have a reason text.
+ jchris_user_doc =
+ prepare_user_doc([
+ {:name, "jchris@apache.org"},
+ {:password, "funnybone"}
+ ])
+ save_as(
+ @users_db_name,
+ jchris_user_doc,
+ use_session: session,
+ expect_response: 400,
+ error_message: "bad_request",
+ error_reason: "Password does not conform to requirements."
+ )
+
+ # With password that match the first requirement.
+ # Requirement does have a reason text.
+ jchris_user_doc2 = Map.put(jchris_user_doc, "password", "funnnnnybone")
+ save_as(
+ @users_db_name,
+ jchris_user_doc2,
+ use_session: session,
+ expect_response: 400,
+ error_message: "bad_request",
+ error_reason: "Password does not conform to requirements. Requirement 2."
+ )
+
+ # With password that match the first two requirements.
+ # Requirement does have an empty string as reason text.
+ jchris_user_doc3 = Map.put(jchris_user_doc, "password", "FUNNNNNYBONE")
+ save_as(
+ @users_db_name,
+ jchris_user_doc3,
+ use_session: session,
+ expect_response: 400,
+ error_message: "bad_request",
+ error_reason: "Password does not conform to requirements."
+ )
+
+ # With password that match the first three requirements.
+ # Requirement does have a reason text.
+ jchris_user_doc4 = Map.put(jchris_user_doc, "password", "funnnnnyBONE")
+ save_as(
+ @users_db_name,
+ jchris_user_doc4,
+ use_session: session,
+ expect_response: 400,
+ error_message: "bad_request",
+ error_reason: "Password does not conform to requirements. Req 4."
+ )
+
+ # With password that match all but the last requirements.
+ # Requirement does have a reason text.
+ jchris_user_doc5 = Map.put(jchris_user_doc, "password", "funnnnnyB0N3")
+ save_as(
+ @users_db_name,
+ jchris_user_doc5,
+ use_session: session,
+ expect_response: 400,
+ error_message: "bad_request",
+ error_reason: "Password does not conform to requirements."
+ )
+
+ # With password that match all requirements.
+ jchris_user_doc6 = Map.put(jchris_user_doc, "password", "funnnnnyB0N3!")
+ save_as(@users_db_name, jchris_user_doc6, use_session: session, expect_response: 201)
+
+ # with non list value
+ set_config({
+ "couch_httpd_auth",
+ "password_regexp",
+ "{{\".{10,}\"}}"
+ })
+
+ joe_user_doc =
+ prepare_user_doc([
+ {:name, "joe_erlang"},
+ {:password, "querty"}
+ ])
+
+ save_as(
+ @users_db_name,
+ joe_user_doc,
+ use_session: session,
+ expect_response: 403,
+ error_message: "forbidden",
+ error_reason: "Server cannot hash passwords at this time."
+ )
+
+ # Not correct syntax
+ set_config({
+ "couch_httpd_auth",
+ "password_regexp",
+ "[{\".{10,}\"]"
+ })
+
+ save_as(
+ @users_db_name,
+ joe_user_doc,
+ use_session: session,
+ expect_response: 403,
+ error_message: "forbidden",
+ error_reason: "Server cannot hash passwords at this time."
+ )
+ end
end