You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2019/07/19 12:18:46 UTC

[couchdb] branch access updated (3872ed7 -> e0f7251)

This is an automated email from the ASF dual-hosted git repository.

jan pushed a change to branch access
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


    from 3872ed7  cleanup
     new f1e765c  wip
     new e0f7251  add test suite boilerplate

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/couch/src/couch_doc.erl             | 12 +++--
 src/couch/test/couchdb_access_tests.erl | 83 ++++++++++++++++++++++++++++++
 t.sh                                    | 91 ++++++++++++++++++---------------
 3 files changed, 140 insertions(+), 46 deletions(-)
 create mode 100644 src/couch/test/couchdb_access_tests.erl


[couchdb] 02/02: add test suite boilerplate

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch access
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit e0f7251dd2d76afa9e6af1e36a4ad83a22d6616c
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Fri Jul 19 14:18:36 2019 +0200

    add test suite boilerplate
---
 src/couch/test/couchdb_access_tests.erl | 83 +++++++++++++++++++++++++++++++++
 t.sh                                    | 41 +++++++++-------
 2 files changed, 108 insertions(+), 16 deletions(-)

diff --git a/src/couch/test/couchdb_access_tests.erl b/src/couch/test/couchdb_access_tests.erl
new file mode 100644
index 0000000..83bc613
--- /dev/null
+++ b/src/couch/test/couchdb_access_tests.erl
@@ -0,0 +1,83 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+-module(couchdb_access_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+
+make_url(User, Addr, PortType) ->
+    lists:concat(["http://", User, ":", User, "@", Addr, ":", port(PortType)]).
+
+setup(PortType) ->
+    Hashed = couch_passwords:hash_admin_password("a"),
+    ok = config:set("admins", "a", binary_to_list(Hashed), _Persist=false),
+    Addr = config:get("httpd", "bind_address", "127.0.0.1"),
+    Url = lists:concat(["http://", Addr, ":", port(PortType)]),
+
+    AdminUrl = make_url("a", Addr, PortType),
+    XUrl = make_url("x", Addr, PortType),
+    YUrl = make_url("y", Addr, PortType),
+
+    % create users
+    UserDbUrl = AdminUrl ++ "/_users",
+    {ok, 201, _, _} = test_request:put(UserDbUrl, ""),
+
+    UserXUrl = AdminUrl ++ "/_users/x",
+    UserXBody = "{ \"name\":\"x\", \"roles\": [], \"password\":\"x\", \"type\": \"user\" }",
+    {ok, 201, _, _} = test_request:put(UserXUrl, UserXBody),
+
+    UserYUrl = AdminUrl ++ "/_users/y",
+    UserYBody = "{ \"name\":\"y\", \"roles\": [], \"password\":\"y\", \"type\": \"user\" }",
+    {ok, 201, _, _} = test_request:put(UserYUrl, UserYBody),
+
+    {ok, _, _, _} = test_request:delete(AdminUrl ++ "/db"),
+    {ok, _, _, _} = test_request:put(AdminUrl ++ "/db?access=true", ""),
+
+    {AdminUrl, XUrl, YUrl}.
+
+teardown(_, _) ->
+    ok.
+
+
+access_test_() ->
+    Tests = [
+        fun should_let_admin_create_doc_with_access/2
+    ],
+    {
+        "Auth tests",
+        {
+            setup,
+            fun() -> test_util:start_couch([chttpd]) end, fun test_util:stop_couch/1,
+            [
+                make_test_cases(clustered, Tests)
+            ]
+        }
+    }.
+
+make_test_cases(Mod, Funs) ->
+    {
+        lists:flatten(io_lib:format("~s", [Mod])),
+        {foreachx, fun setup/1, fun teardown/2, [{Mod, Fun} || Fun <- Funs]}
+    }.
+
+should_let_admin_create_doc_with_access(_PortType, {AdminUrl, XUrl, YUrl}) ->
+    {ok, Code, _, _} = test_request:put(AdminUrl ++ "/db/a", "{\"a\":1,\"_access\":[\"x\"]}"),
+    ?_assertEqual(201, Code).
+
+%% ------------------------------------------------------------------
+%% Internal Function Definitions
+%% ------------------------------------------------------------------
+
+port(clustered) ->
+    integer_to_list(mochiweb_socket_server:get(chttpd, port));
+port(backdoor) ->
+    integer_to_list(mochiweb_socket_server:get(couch_httpd, port)).
diff --git a/t.sh b/t.sh
index 7b9b5e2..89e1283 100755
--- a/t.sh
+++ b/t.sh
@@ -1,41 +1,50 @@
 #!/bin/sh -x
-DB=http://a:a@127.0.0.1:15984
+DB=http://a:a@127.0.0.1:15984 #
 XDB=http://x:x@127.0.0.1:15984
 YDB=http://y:y@127.0.0.1:15984
 
-
-curl -sX PUT $DB/_users/org.couchdb.user:x -d @user.json > /dev/null
-curl -sX PUT $DB/_users/org.couchdb.user:y -d @user2.json > /dev/null
+curl -sX PUT $DB/_users/org.couchdb.user:x -d @user.json > /dev/null #
+curl -sX PUT $DB/_users/org.couchdb.user:y -d @user2.json > /dev/null #
 
 curl -sX DELETE $DB/db
+
+
 curl -sX PUT $DB/db?q=1'&access=true'
+##############
+
+
 
-# curl -sX PUT $DB/db/a -d '{"a":1,"_access":["x"]}'
+curl -sX PUT $DB/db/a -d '{"a":1,"_access":["x"]}'
 curl -sX PUT $DB/db/b -d '{"b":2,"_access":["x"]}'
-# curl -sX PUT $DB/db/c -d '{"c":3,"_access":["y"]}'
-# curl -sX PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
+curl -sX PUT $DB/db/c -d '{"c":3,"_access":["y"]}'
+curl -X PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
 #
-# curl -sX PUT $DB/db/d -d '{"d":4,"_access":["y"]}'
+curl -sX PUT $DB/db/d -d '{"d":4,"_access":["y"]}'
 #
-# curl -sX DELETE $DB/db/a?rev="1-79b9365c8c21f839b206c730ec3d4fc3"
+curl -sX DELETE $DB/db/a?rev="1-967a00dff5e02add41819138abb3284d"
+
+echo 
+echo "setup done"
+echo
+
 #
 # curl -s $DB/db/_all_docs?include_docs=true
 # curl -s $XDB/db/_all_docs?include_docs=true
 # curl -s $YDB/db/_all_docs?include_docs=true
-#
+# #
 # curl -s $DB/db/_changes?include_docs=true
 # curl -s $XDB/db/_changes?include_docs=true
 # curl -s $YDB/db/_changes?include_docs=true
-#
+# #
 # curl -s $DB/db/a
-curl -s $DB/db/b
+# curl -s $DB/db/b
 # curl -s $DB/db/c
 # curl -s $DB/db/d
 #
-# curl -s $XDB/db/a
-# curl -s $XDB/db/b
-# curl -s $XDB/db/c
-# curl -s $XDB/db/d
+curl -s $XDB/db/a
+curl -s $XDB/db/b
+curl -s $XDB/db/c
+curl -s $XDB/db/d
 #
 # curl -s $YDB/db/a
 # curl -s $YDB/db/b


[couchdb] 01/02: wip

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jan pushed a commit to branch access
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit f1e765c6d236e653df6e4283367daa9128da51bf
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Tue May 7 12:01:06 2019 +0200

    wip
---
 src/couch/src/couch_doc.erl | 12 +++---
 t.sh                        | 90 ++++++++++++++++++++++-----------------------
 2 files changed, 52 insertions(+), 50 deletions(-)

diff --git a/src/couch/src/couch_doc.erl b/src/couch/src/couch_doc.erl
index 802cc71..500a5c7 100644
--- a/src/couch/src/couch_doc.erl
+++ b/src/couch/src/couch_doc.erl
@@ -127,13 +127,15 @@ to_json_obj(Doc, Options) ->
 
 doc_to_json_obj(#doc{id=Id,deleted=Del,body=Body,revs={Start, RevIds},
             meta=Meta,access=Access}=Doc,Options)->
-    {[{<<"_id">>, Id}]
+    R={[{<<"_id">>, Id}]
         ++ to_json_rev(Start, RevIds)
         ++ to_json_body(Del, Body, Access)
         ++ to_json_revisions(Options, Start, RevIds)
         ++ to_json_meta(Meta)
         ++ to_json_attachments(Doc#doc.atts, Options)
-    }.
+    },
+    couch_log:info("~n~n loading this from disk: Doc: ~p ~n~n", [R]),
+    R.
 
 from_json_obj_validate(EJson) ->
     from_json_obj_validate(EJson, undefined).
@@ -141,6 +143,7 @@ from_json_obj_validate(EJson) ->
 from_json_obj_validate(EJson, DbName) ->
     MaxSize = config:get_integer("couchdb", "max_document_size", 4294967296),
     Doc = from_json_obj(EJson, DbName),
+    couch_log:info("~n~n writing this to disk: Doc: ~p ~n~n", [Doc]),
     case couch_ejson_size:encoded_size(Doc#doc.body) =< MaxSize of
         true ->
              validate_attachment_sizes(Doc#doc.atts),
@@ -260,10 +263,9 @@ transfer_fields([{<<"_id">>, Id} | Rest], Doc, DbName) ->
     validate_docid(Id, DbName),
     transfer_fields(Rest, Doc#doc{id=Id}, DbName);
 
-transfer_fields([{<<"_access">>, Access} = Field | Rest],
-    #doc{body=Fields} = Doc, DbName) ->
+transfer_fields([{<<"_access">>, Access} = Field | Rest], Doc, DbName) ->
     % TODO: validate access as array strings, and optional arrays of strings
-    transfer_fields(Rest, Doc#doc{body=[Field|Fields],access=Access}, DbName);
+    transfer_fields(Rest, Doc#doc{body=Rest,access=Access}, DbName);
 
 transfer_fields([{<<"_rev">>, Rev} | Rest], #doc{revs={0, []}}=Doc, DbName) ->
     {Pos, RevId} = parse_rev(Rev),
diff --git a/t.sh b/t.sh
index a9cd5a5..7b9b5e2 100755
--- a/t.sh
+++ b/t.sh
@@ -10,50 +10,50 @@ curl -sX PUT $DB/_users/org.couchdb.user:y -d @user2.json > /dev/null
 curl -sX DELETE $DB/db
 curl -sX PUT $DB/db?q=1'&access=true'
 
-curl -sX PUT $DB/db/a -d '{"a":1,"_access":["x"]}'
+# curl -sX PUT $DB/db/a -d '{"a":1,"_access":["x"]}'
 curl -sX PUT $DB/db/b -d '{"b":2,"_access":["x"]}'
-curl -sX PUT $DB/db/c -d '{"c":3,"_access":["y"]}'
-curl -sX PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
-
-curl -sX PUT $DB/db/d -d '{"d":4,"_access":["y"]}'
-
-curl -sX DELETE $DB/db/a?rev="1-79b9365c8c21f839b206c730ec3d4fc3"
-
-curl -s $DB/db/_all_docs?include_docs=true
-curl -s $XDB/db/_all_docs?include_docs=true
-curl -s $YDB/db/_all_docs?include_docs=true
-
-curl -s $DB/db/_changes?include_docs=true
-curl -s $XDB/db/_changes?include_docs=true
-curl -s $YDB/db/_changes?include_docs=true
-
-curl -s $DB/db/a
+# curl -sX PUT $DB/db/c -d '{"c":3,"_access":["y"]}'
+# curl -sX PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
+#
+# curl -sX PUT $DB/db/d -d '{"d":4,"_access":["y"]}'
+#
+# curl -sX DELETE $DB/db/a?rev="1-79b9365c8c21f839b206c730ec3d4fc3"
+#
+# curl -s $DB/db/_all_docs?include_docs=true
+# curl -s $XDB/db/_all_docs?include_docs=true
+# curl -s $YDB/db/_all_docs?include_docs=true
+#
+# curl -s $DB/db/_changes?include_docs=true
+# curl -s $XDB/db/_changes?include_docs=true
+# curl -s $YDB/db/_changes?include_docs=true
+#
+# curl -s $DB/db/a
 curl -s $DB/db/b
-curl -s $DB/db/c
-curl -s $DB/db/d
-
-curl -s $XDB/db/a
-curl -s $XDB/db/b
-curl -s $XDB/db/c
-curl -s $XDB/db/d
-
-curl -s $YDB/db/a
-curl -s $YDB/db/b
-curl -s $YDB/db/c
-curl -s $YDB/db/d
-
-curl -sX PUT $XDB/db/b?rev="1-809cfddb59a4f02dc1009785fad978b4" -d '{"b":5,"_access":["x"]}'
-curl -sX PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
-curl -sX PUT $XDB/db/d?rev="1-87adddda059e643409c43bea87c37bfe" -d '{"d":7,"_access":["y"]}'
-
-curl -sX PUT $YDB/db/b?rev="1-809cfddb59a4f02dc1009785fad978b4" -d '{"b":5,"_access":["x"]}'
-curl -sX PUT $YDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
-curl -sX PUT $YDB/db/d?rev="1-87adddda059e643409c43bea87c37bfe" -d '{"d":7,"_access":["y"]}'
-
-curl -sX DELETE $XDB/db/b?rev="2-384262a5168d1187dff405530046666"
-curl -sX DELETE $XDB/db/c?rev="2-4cdae6f0a7539ea92dc79f3d3b0379b"
-curl -sX DELETE $XDB/db/d?rev="2-868c18641965cfae831be1114b49a66b"
-
-curl -sX DELETE $YDB/db/b?rev="2-384262a5168d1187dff405530046666"
-curl -sX DELETE $YDB/db/c?rev="2-4cdae6f0a7539ea92dc79f3d3b0379b"
-curl -sX DELETE $YDB/db/d?rev="2-868c18641965cfae831be1114b49a66b"
+# curl -s $DB/db/c
+# curl -s $DB/db/d
+#
+# curl -s $XDB/db/a
+# curl -s $XDB/db/b
+# curl -s $XDB/db/c
+# curl -s $XDB/db/d
+#
+# curl -s $YDB/db/a
+# curl -s $YDB/db/b
+# curl -s $YDB/db/c
+# curl -s $YDB/db/d
+#
+# curl -sX PUT $XDB/db/b?rev="1-809cfddb59a4f02dc1009785fad978b4" -d '{"b":5,"_access":["x"]}'
+# curl -sX PUT $XDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
+# curl -sX PUT $XDB/db/d?rev="1-87adddda059e643409c43bea87c37bfe" -d '{"d":7,"_access":["y"]}'
+#
+# curl -sX PUT $YDB/db/b?rev="1-809cfddb59a4f02dc1009785fad978b4" -d '{"b":5,"_access":["x"]}'
+# curl -sX PUT $YDB/db/c?rev="1-0865d643568aa9be6bcdc15d88b25912" -d '{"c":6,"_access":["y"]}'
+# curl -sX PUT $YDB/db/d?rev="1-87adddda059e643409c43bea87c37bfe" -d '{"d":7,"_access":["y"]}'
+#
+# curl -sX DELETE $XDB/db/b?rev="2-384262a5168d1187dff405530046666"
+# curl -sX DELETE $XDB/db/c?rev="2-4cdae6f0a7539ea92dc79f3d3b0379b"
+# curl -sX DELETE $XDB/db/d?rev="2-868c18641965cfae831be1114b49a66b"
+#
+# curl -sX DELETE $YDB/db/b?rev="2-384262a5168d1187dff405530046666"
+# curl -sX DELETE $YDB/db/c?rev="2-4cdae6f0a7539ea92dc79f3d3b0379b"
+# curl -sX DELETE $YDB/db/d?rev="2-868c18641965cfae831be1114b49a66b"