couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [11/13] couch commit: updated refs/heads/master to 311ba94
Date Wed, 12 Aug 2015 15:54:11 GMT
Tests for 'authentication_handlers' and 'authenticated' on '_session'


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/b387a0b7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/b387a0b7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/b387a0b7

Branch: refs/heads/master
Commit: b387a0b70596e5610ef6ab13ef92c71afb84f4f4
Parents: 2b49575
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Wed Aug 5 13:45:35 2015 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Tue Aug 11 12:25:00 2015 -0700

----------------------------------------------------------------------
 test/couchdb_auth_tests.erl | 69 ++++++++++++++++++++++++++++++++--------
 1 file changed, 56 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/b387a0b7/test/couchdb_auth_tests.erl
----------------------------------------------------------------------
diff --git a/test/couchdb_auth_tests.erl b/test/couchdb_auth_tests.erl
index 61aedbc..5ee0a5a 100644
--- a/test/couchdb_auth_tests.erl
+++ b/test/couchdb_auth_tests.erl
@@ -15,32 +15,40 @@
 -include_lib("couch/include/couch_eunit.hrl").
 
 
-setup() ->
+setup(PortType) ->
+    ok = config:set("admins", "rocko", "artischocko", false),
     Addr = config:get("httpd", "bind_address", "127.0.0.1"),
-    Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)),
-    lists:concat(["http://", Addr, ":", Port, "/_session"]).
+    lists:concat(["http://", Addr, ":", port(PortType), "/_session"]).
 
-teardown(_) ->
+teardown(_, _) ->
     ok.
 
 
 auth_test_() ->
+    Tests = [
+        fun should_not_return_username_on_post_to_session/2,
+        fun should_return_authenticated_field/2,
+        fun should_return_list_of_handlers/2
+    ],
     {
         "Auth tests",
         {
             setup,
-            fun test_util:start_couch/0, fun test_util:stop_couch/1,
-            {
-                foreach,
-                fun setup/0, fun teardown/1,
-                [
-                    fun should_not_return_username_on_post_to_session/1
-                ]
-            }
+            fun() -> test_util:start_couch([chttpd]) end, fun test_util:stop_couch/1,
+            [
+                make_test_cases(clustered, Tests),
+                make_test_cases(backdoor, Tests)
+            ]
         }
     }.
 
-should_not_return_username_on_post_to_session(Url) ->
+make_test_cases(Mod, Funs) ->
+    {
+        lists:flatten(io_lib:format("~s", [Mod])),
+        {foreachx, fun setup/1, fun teardown/2, [{Mod, Fun} || Fun <- Funs]}
+    }.
+
+should_not_return_username_on_post_to_session(_PortType, Url) ->
     ?_assertEqual(<<"rocko">>,
         begin
             ok = config:set("admins", "rocko", "artischocko", false),
@@ -49,3 +57,38 @@ should_not_return_username_on_post_to_session(Url) ->
             {Json} = jiffy:decode(Body),
             proplists:get_value(<<"name">>, Json)
         end).
+
+should_return_authenticated_field(_PortType, Url) ->
+    ?_assertEqual(<<"local">>,
+        begin
+            couch_util:get_nested_json_value(session(Url), [
+                <<"info">>, <<"authenticated">>])
+        end).
+
+should_return_list_of_handlers(backdoor, Url) ->
+    ?_assertEqual([<<"oauth">>,<<"cookie">>,<<"default">>,
<<"local">>],
+        begin
+            couch_util:get_nested_json_value(session(Url), [
+                <<"info">>, <<"authentication_handlers">>])
+        end);
+should_return_list_of_handlers(clustered, Url) ->
+    ?_assertEqual([<<"cookie">>,<<"default">>,<<"local">>],
+        begin
+            couch_util:get_nested_json_value(session(Url), [
+                <<"info">>, <<"authentication_handlers">>])
+        end).
+
+
+%% ------------------------------------------------------------------
+%% Internal Function Definitions
+%% ------------------------------------------------------------------
+
+session(Url) ->
+    {ok, _, _, Body} = test_request:get(Url, [{"Content-Type", "application/json"}],
+        "{\"name\":\"rocko\", \"password\":\"artischocko\"}"),
+    jiffy:decode(Body).
+
+port(clustered) ->
+    integer_to_list(mochiweb_socket_server:get(chttpd, port));
+port(backdoor) ->
+    integer_to_list(mochiweb_socket_server:get(couch_httpd, port)).


Mime
View raw message