diff options
author | Christopher Astfalk <christopher.astfalk@icloud.com> | 2021-03-29 16:44:48 +0200 |
---|---|---|
committer | Bessenyei Balázs Donát <bessbd@users.noreply.github.com> | 2021-05-05 10:31:38 +0200 |
commit | 19204484c56f043514376721caafe74fd7ad5c74 (patch) | |
tree | 68823755f6088b79b2520b4ca0bc9e1e5eae2794 | |
parent | 4b863d50f6acffcbbf1a4d1f7f665eb5611bf92b (diff) | |
download | couchdb-19204484c56f043514376721caafe74fd7ad5c74.tar.gz |
Add tests for password reqexp
-rw-r--r-- | test/elixir/test/users_db_test.exs | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/test/elixir/test/users_db_test.exs b/test/elixir/test/users_db_test.exs index db86b2739..4ef6d5371 100644 --- a/test/elixir/test/users_db_test.exs +++ b/test/elixir/test/users_db_test.exs @@ -299,4 +299,70 @@ defmodule UsersDbTest do assert resp.body["userCtx"]["name"] == "foo@example.org" end + + test "users password requirements", context do + set_config({ + "couch_httpd_auth", + "password_reqexp", + "[{\".{10,}\"}, {\"[A-Z]+\", \"Requirement 2.\"}, {\"[a-z]+\", \"\"}, {\"\\\\d+\", \"Req 4.\"}]" + }) + + 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: 403, + error_message: "forbidden", + 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: 403, + error_message: "forbidden", + 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: 403, + error_message: "forbidden", + error_reason: "Password does not conform to requirements." + ) + + # With password that match all but the last 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: 403, + error_message: "forbidden", + error_reason: "Password does not conform to requirements. Req 4." + ) + + # With password that match all requirements. + jchris_user_doc5 = Map.put(jchris_user_doc, "password", "funnnnnyB0N3") + save_as(@users_db_name, jchris_user_doc5, use_session: session, expect_response: 201) + end end |