Skip to content

Commit ed1609b

Browse files
committed
Make sure we cache admin pass prior to test run
couch_server is responsible for calling hash_admin_passwords whenever "admin" section of config changes. However as you can see it from [here](https://github.com/apache/couchdb/blob/master/src/couch/src/couch_server.erl#L219) the call is asynchronous. This means that our test cases might fail when we try to using admin user while admin password is not yet hashed.
1 parent 0d09ab3 commit ed1609b

10 files changed

+22
-11
lines changed

src/chttpd/test/chttpd_db_doc_size_tests.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626

2727

2828
setup() ->
29-
ok = config:set("admins", ?USER, ?PASS, _Persist=false),
29+
Hashed = couch_passwords:hash_admin_password(?PASS),
30+
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
3031
ok = config:set("couchdb", "max_document_size", "50"),
3132
TmpDb = ?tempdb(),
3233
Addr = config:get("chttpd", "bind_address", "127.0.0.1"),

src/chttpd/test/chttpd_db_test.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
-define(FIXTURE_TXT, ?ABS_PATH(?FILE)).
2323

2424
setup() ->
25-
ok = config:set("admins", ?USER, ?PASS, _Persist=false),
25+
Hashed = couch_passwords:hash_admin_password(?PASS),
26+
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
2627
TmpDb = ?tempdb(),
2728
Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
2829
Port = mochiweb_socket_server:get(chttpd, port),

src/chttpd/test/chttpd_open_revs_error_test.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
"multipart/form-data;boundary=\"bound\""}).
2424

2525
setup() ->
26-
ok = config:set("admins", ?USER, ?PASS, _Persist=false),
26+
Hashed = couch_passwords:hash_admin_password(?PASS),
27+
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
2728
TmpDb = ?tempdb(),
2829
Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
2930
Port = mochiweb_socket_server:get(chttpd, port),

src/chttpd/test/chttpd_welcome_test.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323

2424
setup() ->
25-
ok = config:set("admins", ?USER, ?PASS, _Persist=false),
25+
Hashed = couch_passwords:hash_admin_password(?PASS),
26+
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
2627
Addr = config:get("chttpd", "bind_address", "127.0.0.1"),
2728
Port = mochiweb_socket_server:get(chttpd, port),
2829
Url = lists:concat(["http://", Addr, ":", Port, "/"]),

src/couch/test/couch_db_mpr_tests.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828

2929
setup() ->
30-
ok = config:set("admins", ?USER, ?PASS, _Persist=false),
30+
Hashed = couch_passwords:hash_admin_password(?PASS),
31+
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
3132
TmpDb = ?tempdb(),
3233
Addr = config:get("httpd", "bind_address", "127.0.0.1"),
3334
Port = mochiweb_socket_server:get(couch_httpd, port),

src/couch/test/couchdb_auth_tests.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717

1818
setup(PortType) ->
19-
ok = config:set("admins", "rocko", "artischocko", false),
19+
Hashed = couch_passwords:hash_admin_password("artischocko"),
20+
ok = config:set("admins", "rocko", binary_to_list(Hashed), _Persist=false),
2021
Addr = config:get("httpd", "bind_address", "127.0.0.1"),
2122
lists:concat(["http://", Addr, ":", port(PortType), "/_session"]).
2223

@@ -51,7 +52,8 @@ make_test_cases(Mod, Funs) ->
5152
should_return_username_on_post_to_session(_PortType, Url) ->
5253
?_assertEqual(<<"rocko">>,
5354
begin
54-
ok = config:set("admins", "rocko", "artischocko", false),
55+
Hashed = couch_passwords:hash_admin_password(<<"artischocko">>),
56+
ok = config:set("admins", "rocko", binary_to_list(Hashed), false),
5557
{ok, _, _, Body} = test_request:post(Url, [{"Content-Type", "application/json"}],
5658
"{\"name\":\"rocko\", \"password\":\"artischocko\"}"),
5759
{Json} = jiffy:decode(Body),

src/couch/test/couchdb_mrview_cors_tests.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131

3232
start() ->
3333
Ctx = test_util:start_couch([chttpd]),
34-
ok = config:set("admins", ?USER, ?PASS, _Persist=false),
34+
Hashed = couch_passwords:hash_admin_password(?PASS),
35+
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
3536
ok = config:set("httpd", "enable_cors", "true", false),
3637
ok = config:set("vhosts", "example.com", "/", false),
3738
Ctx.

src/couch/test/couchdb_mrview_tests.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242

4343
start() ->
4444
Ctx = test_util:start_couch([chttpd]),
45-
ok = config:set("admins", ?USER, ?PASS, _Persist=false),
45+
Hashed = couch_passwords:hash_admin_password(?PASS),
46+
ok = config:set("admins", ?USER, ?b2l(Hashed), _Persist=false),
4647
Ctx.
4748

4849
setup(PortType) ->

src/couch/test/global_changes_tests.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ decode_response(BinBody, ToDecode) ->
144144
[couch_util:get_value(Key, Body) || Key <- ToDecode].
145145

146146
add_admin(User, Pass) ->
147-
config:set("admins", User, Pass, false).
147+
Hashed = couch_passwords:hash_admin_password(Pass),
148+
config:set("admins", User, ?b2l(Hashed), _Persist=false).
148149

149150
delete_admin(User) ->
150151
config:delete("admins", User, false).

src/couch_peruser/test/couch_peruser_test.erl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
setup_all() ->
2222
TestCtx = test_util:start_couch([chttpd]),
23-
config:set("admins", ?ADMIN_USERNAME, ?ADMIN_PASSWORD),
23+
Hashed = couch_passwords:hash_admin_password(?ADMIN_PASSWORD),
24+
ok = config:set("admins", ?ADMIN_USERNAME, ?b2l(Hashed), _Persist=false),
2425
TestCtx.
2526

2627
teardown_all(TestCtx) ->

0 commit comments

Comments
 (0)