diff options
author | Frederick Kaempfer <frederick.kaempfer@gmail.com> | 2017-07-11 16:10:59 +0200 |
---|---|---|
committer | Joan Touzet <wohali@users.noreply.github.com> | 2017-07-12 11:12:37 -0400 |
commit | 6ff73aa963fafff02c324a0e0842e65a151ce431 (patch) | |
tree | 000e3d53492d7414c5173227aa14b88844ecdd2a | |
parent | 6d2ece55c06d8a2fdd3eeb416288630a4ebac9bf (diff) | |
download | couchdb-6ff73aa963fafff02c324a0e0842e65a151ce431.tar.gz |
Fix test
-rw-r--r-- | src/chttpd/test/chttpd_security_tests.erl | 26 |
1 files changed, 12 insertions, 14 deletions
diff --git a/src/chttpd/test/chttpd_security_tests.erl b/src/chttpd/test/chttpd_security_tests.erl index 6e4b8b5a3..009f22fc8 100644 --- a/src/chttpd/test/chttpd_security_tests.erl +++ b/src/chttpd/test/chttpd_security_tests.erl @@ -34,7 +34,7 @@ setup() -> ok = config:set("admins", ?USER, ?PASS, _Persist=false), - UserDb = ?tempdb(), + UserDb = <<"_users">>, TmpDb = ?tempdb(), ok = config:set("couch_httpd_auth", "authentication_db", ?b2l(UserDb)), Addr = config:get("chttpd", "bind_address", "127.0.0.1"), @@ -45,8 +45,8 @@ setup() -> create_db(UsersUrl), create_db(Url), create_design_doc(Url), - create_user(UsersUrl,?TEST_MEMBER,[<<?TEST_MEMBER_PASS>>]), - create_user(UsersUrl,?TEST_ADMIN,[<<?TEST_MEMBER_PASS>>]), + create_user(UsersUrl,?TEST_MEMBER,?TEST_MEMBER_PASS,[<<?TEST_MEMBER>>]), + create_user(UsersUrl,?TEST_ADMIN,?TEST_ADMIN_PASS,[<<?TEST_ADMIN>>]), set_security(Url), [Url, UsersUrl]. @@ -58,7 +58,7 @@ teardown([Url,UsersUrl]) -> ok = config:delete("admins", ?USER, _Persist=false). create_db(Url) -> - {ok, Status, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"), + {ok, Status, _, Body} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], "{}"), ?assert(Status =:= 201 orelse Status =:= 202). create_design_doc(Url) -> @@ -67,29 +67,27 @@ create_design_doc(Url) -> ?assert(Status =:= 201 orelse Status =:= 202). set_security(Url) -> - SecurityUrl = lists:concat([Url, "/_security"]), SecurityProperties = [ - {<<"admins">>,{[{<<"roles">>,[<<"test_admin">>]}]}}, - {<<"members">>,{[{<<"roles">>,[<<"test_member">>]}]}} + {<<"admins">>,{[{<<"roles">>,[<<?TEST_ADMIN>>]}]}}, + {<<"members">>,{[{<<"roles">>,[<<?TEST_MEMBER>>]}]}} ], Body = jiffy:encode({SecurityProperties}), - {ok, Status, _, _} = test_request:post(Url, [?CONTENT_JSON, ?AUTH], Body), - ?assert(Status =:= 201 orelse Status =:= 202). + {ok, Status, _, _} = test_request:put(SecurityUrl, [?CONTENT_JSON, ?AUTH], Body), + ?assert(Status =:= 200). delete_db(Url) -> {ok, 200, _, _} = test_request:delete(Url, [?AUTH]). -create_user(UsersUrl,Name, Roles) -> +create_user(UsersUrl, Name, Password, Roles) -> Body = "{\"name\":\"" ++ Name ++ - "\",\"type\":\"user\",\"roles\":" ++ erlang:binary_to_list(jiffy:encode(Roles)) ++ ",\"password\":\"secret\"}", + "\",\"type\":\"user\",\"roles\":" ++ erlang:binary_to_list(jiffy:encode(Roles)) ++ ",\"password\":\"" ++ Password ++"\"}", + Url = lists:concat([ UsersUrl, "/org.couchdb.user:", Name]), - {ok, 201, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], Body), - % let's proceed after giving couch_peruser some time to create the user db - timer:sleep(2000). + {ok, 201, _, _} = test_request:put(Url, [?CONTENT_JSON, ?AUTH], Body). all_test_() -> |