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 2020/05/24 15:18:33 UTC
[couchdb] 03/04: feat: replication & revs diff
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 7ec5baa40a92bf1048e082ca54f1fa0344c6bb1e
Author: Jan Lehnardt <ja...@apache.org>
AuthorDate: Sun May 24 13:51:53 2020 +0200
feat: replication & revs diff
---
src/chttpd/src/chttpd_db.erl | 5 +-
src/couch/src/couch_db.erl | 4 +-
src/couch/test/couchdb_access_tests.erl | 459 +++++++++++++++++++++++++++++++-
src/fabric/src/fabric_doc_open_revs.erl | 8 +-
src/fabric/src/fabric_rpc.erl | 4 +-
5 files changed, 463 insertions(+), 17 deletions(-)
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 1044c0b..cf85ead 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -831,7 +831,10 @@ db_doc_req(#httpd{method='GET', mochi_req=MochiReq}=Req, Db, DocId) ->
send_docs_multipart(Req, Results, Options)
end;
{error, Error} ->
- chttpd:send_error(Req, Error)
+ chttpd:send_error(Req, Error);
+ Else ->
+ couch_log:debug("~n open_revs Else: ~p~n", [Else]),
+ chttpd:send_error(Req, Else)
end
end;
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 47a35f1..29e8697 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -1729,7 +1729,7 @@ open_doc_revs_int(Db, IdRevs, Options) ->
lists:zipwith(
fun({Id, Revs}, Lookup) ->
case Lookup of
- #full_doc_info{rev_tree=RevTree} ->
+ #full_doc_info{rev_tree=RevTree, access=Access} ->
{FoundRevs, MissingRevs} =
case Revs of
all ->
@@ -1749,7 +1749,7 @@ open_doc_revs_int(Db, IdRevs, Options) ->
% we have the rev in our list but know nothing about it
{{not_found, missing}, {Pos, Rev}};
#leaf{deleted=IsDeleted, ptr=SummaryPtr} ->
- {ok, make_doc(Db, Id, IsDeleted, SummaryPtr, FoundRevPath)}
+ {ok, make_doc(Db, Id, IsDeleted, SummaryPtr, FoundRevPath, Access)}
end
end, FoundRevs),
Results = FoundResults ++ [{{not_found, missing}, MissingRev} || MissingRev <- MissingRevs],
diff --git a/src/couch/test/couchdb_access_tests.erl b/src/couch/test/couchdb_access_tests.erl
index e52e958..e771b6c 100644
--- a/src/couch/test/couchdb_access_tests.erl
+++ b/src/couch/test/couchdb_access_tests.erl
@@ -35,6 +35,7 @@ before_each(_) ->
after_each(_, Url) ->
{ok, 200, _, _} = test_request:delete(Url ++ "/db", ?ADMIN_REQ_HEADERS),
{_, _, _, _} = test_request:delete(Url ++ "/db2", ?ADMIN_REQ_HEADERS),
+ {_, _, _, _} = test_request:delete(Url ++ "/db3", ?ADMIN_REQ_HEADERS),
ok.
before_all() ->
@@ -110,18 +111,19 @@ access_test_() ->
% fun should_allow_user_users_access_ddoc_view_request/2,
% replication
- fun should_allow_admin_to_replicate_from_access_to_access/2
- % admin should be able to replicate all docs
- % - from access to access
- % - from no-access to access
- % - from access to no-access
- % - from no-access to no-access while retainting _access for docs
- % user should be able to replicate:
- % - access to access
- % - access to no-access
- % - no-access (w/ _access docs) to _access
-
-
+ % fun should_allow_admin_to_replicate_from_access_to_access/2,
+ % fun should_allow_admin_to_replicate_from_no_access_to_access/2,
+ % fun should_allow_admin_to_replicate_from_access_to_no_access/2,
+ % fun should_allow_admin_to_replicate_from_no_access_to_no_access/2
+
+ % fun should_allow_user_to_replicate_from_access_to_access/2,
+ % fun should_allow_user_to_replicate_from_access_to_no_access/2,
+ % fun should_allow_user_to_replicate_from_no_access_to_access/2,
+ % fun should_allow_user_to_replicate_from_no_access_to_no_access/2
+
+ % TODO: try getting _revs_diff for docs you don’t have access to
+ fun should_not_allow_user_to_revs_diff_other_docs/2
+
% TODO: create test db with role and not _users in _security.members
% and make sure a user in that group can access while a user not
@@ -145,6 +147,17 @@ make_test_cases(Mod, Funs) ->
}.
% Doc creation
+ % http://127.0.0.1:64903/db/a?revs=true&open_revs=%5B%221-23202479633c2b380f79507a776743d5%22%5D&latest=true
+
+% should_do_the_thing(_PortType, Url) ->
+% ?_test(begin
+% {ok, _, _, _} = test_request:put(Url ++ "/db/a",
+% ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+% {ok, Code, _, _} = test_request:get(Url ++ "/db/a?revs=true&open_revs=%5B%221-23202479633c2b380f79507a776743d5%22%5D&latest=true",
+% ?USERX_REQ_HEADERS),
+% ?assertEqual(200, Code)
+% end).
+%
should_not_let_anonymous_user_create_doc(_PortType, Url) ->
{ok, Code, _, _} = test_request:put(Url ++ "/db/a", "{\"a\":1,\"_access\":[\"x\"]}"),
@@ -516,12 +529,434 @@ should_allow_admin_to_replicate_from_access_to_access(_PortType, Url) ->
?assertEqual(0, DocWriteFailures),
% assert docs in target db
+ {ok, 200, _, ADBody} = test_request:get(Url ++ "/db2/_all_docs?include_docs=true",
+ ?ADMIN_REQ_HEADERS),
+ {Json} = jiffy:decode(ADBody),
+ ?assertEqual(3, proplists:get_value(<<"total_rows">>, Json))
+ end).
+
+should_allow_admin_to_replicate_from_no_access_to_access(_PortType, Url) ->
+ ?_test(begin
+ % create target db
+ {ok, 201, _, _} = test_request:put(url() ++ "/db2?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db2/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ % create source docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"x\"]}"),
+
+ % replicate
+ AdminUrl = string:replace(Url, "http://", "http://a:a@"),
+ EJRequestBody = {[
+ {<<"source">>, list_to_binary(AdminUrl ++ "/db2")},
+ {<<"target">>, list_to_binary(AdminUrl ++ "/db")}
+ ]},
+ {ok, ResponseCode, _, ResponseBody} = test_request:post(Url ++ "/_replicate",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(EJRequestBody)),
+
+ % assert replication status
+ {EJResponseBody} = jiffy:decode(ResponseBody),
+ ?assertEqual(ResponseCode, 200),
+ ?assertEqual(true, couch_util:get_value(<<"ok">>, EJResponseBody)),
+ [{History}] = couch_util:get_value(<<"history">>, EJResponseBody),
+
+ MissingChecked = couch_util:get_value(<<"missing_checked">>, History),
+ MissingFound = couch_util:get_value(<<"missing_found">>, History),
+ DocsReard = couch_util:get_value(<<"docs_read">>, History),
+ DocsWritten = couch_util:get_value(<<"docs_written">>, History),
+ DocWriteFailures = couch_util:get_value(<<"doc_write_failures">>, History),
+
+ ?assertEqual(3, MissingChecked),
+ ?assertEqual(3, MissingFound),
+ ?assertEqual(3, DocsReard),
+ ?assertEqual(3, DocsWritten),
+ ?assertEqual(0, DocWriteFailures),
+
+ % assert docs in target db
{ok, 200, _, ADBody} = test_request:get(Url ++ "/db/_all_docs?include_docs=true",
?ADMIN_REQ_HEADERS),
{Json} = jiffy:decode(ADBody),
?assertEqual(3, proplists:get_value(<<"total_rows">>, Json))
end).
+should_allow_admin_to_replicate_from_access_to_no_access(_PortType, Url) ->
+ ?_test(begin
+ % create target db
+ {ok, 201, _, _} = test_request:put(url() ++ "/db2?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db2/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ % create source docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"x\"]}"),
+
+ % replicate
+ AdminUrl = string:replace(Url, "http://", "http://a:a@"),
+ EJRequestBody = {[
+ {<<"source">>, list_to_binary(AdminUrl ++ "/db")},
+ {<<"target">>, list_to_binary(AdminUrl ++ "/db2")}
+ ]},
+ {ok, ResponseCode, _, ResponseBody} = test_request:post(Url ++ "/_replicate",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(EJRequestBody)),
+
+ % assert replication status
+ {EJResponseBody} = jiffy:decode(ResponseBody),
+ ?assertEqual(ResponseCode, 200),
+ ?assertEqual(true, couch_util:get_value(<<"ok">>, EJResponseBody)),
+ [{History}] = couch_util:get_value(<<"history">>, EJResponseBody),
+
+ MissingChecked = couch_util:get_value(<<"missing_checked">>, History),
+ MissingFound = couch_util:get_value(<<"missing_found">>, History),
+ DocsReard = couch_util:get_value(<<"docs_read">>, History),
+ DocsWritten = couch_util:get_value(<<"docs_written">>, History),
+ DocWriteFailures = couch_util:get_value(<<"doc_write_failures">>, History),
+
+ ?assertEqual(3, MissingChecked),
+ ?assertEqual(3, MissingFound),
+ ?assertEqual(3, DocsReard),
+ ?assertEqual(3, DocsWritten),
+ ?assertEqual(0, DocWriteFailures),
+
+ % assert docs in target db
+ {ok, 200, _, ADBody} = test_request:get(Url ++ "/db2/_all_docs?include_docs=true",
+ ?ADMIN_REQ_HEADERS),
+ {Json} = jiffy:decode(ADBody),
+ ?assertEqual(3, proplists:get_value(<<"total_rows">>, Json))
+ end).
+
+should_allow_admin_to_replicate_from_no_access_to_no_access(_PortType, Url) ->
+ ?_test(begin
+ % create source and target dbs
+ {ok, 201, _, _} = test_request:put(url() ++ "/db2?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db2/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ {ok, 201, _, _} = test_request:put(url() ++ "/db3?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db3/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ % create source docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"x\"]}"),
+
+ % replicate
+ AdminUrl = string:replace(Url, "http://", "http://a:a@"),
+ EJRequestBody = {[
+ {<<"source">>, list_to_binary(AdminUrl ++ "/db2")},
+ {<<"target">>, list_to_binary(AdminUrl ++ "/db3")}
+ ]},
+ {ok, ResponseCode, _, ResponseBody} = test_request:post(Url ++ "/_replicate",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(EJRequestBody)),
+
+ % assert replication status
+ {EJResponseBody} = jiffy:decode(ResponseBody),
+ ?assertEqual(ResponseCode, 200),
+ ?assertEqual(true, couch_util:get_value(<<"ok">>, EJResponseBody)),
+ [{History}] = couch_util:get_value(<<"history">>, EJResponseBody),
+
+ MissingChecked = couch_util:get_value(<<"missing_checked">>, History),
+ MissingFound = couch_util:get_value(<<"missing_found">>, History),
+ DocsReard = couch_util:get_value(<<"docs_read">>, History),
+ DocsWritten = couch_util:get_value(<<"docs_written">>, History),
+ DocWriteFailures = couch_util:get_value(<<"doc_write_failures">>, History),
+
+ ?assertEqual(3, MissingChecked),
+ ?assertEqual(3, MissingFound),
+ ?assertEqual(3, DocsReard),
+ ?assertEqual(3, DocsWritten),
+ ?assertEqual(0, DocWriteFailures),
+
+ % assert docs in target db
+ {ok, 200, _, ADBody} = test_request:get(Url ++ "/db3/_all_docs?include_docs=true",
+ ?ADMIN_REQ_HEADERS),
+ {Json} = jiffy:decode(ADBody),
+ ?assertEqual(3, proplists:get_value(<<"total_rows">>, Json))
+ end).
+
+should_allow_user_to_replicate_from_access_to_access(_PortType, Url) ->
+ ?_test(begin
+ % create source and target dbs
+ {ok, 201, _, _} = test_request:put(url() ++ "/db2?q=1&n=1&access=true",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db2/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ % create source docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"y\"]}"),
+
+ % replicate
+ UserXUrl = string:replace(Url, "http://", "http://x:x@"),
+ EJRequestBody = {[
+ {<<"source">>, list_to_binary(UserXUrl ++ "/db")},
+ {<<"target">>, list_to_binary(UserXUrl ++ "/db2")}
+ ]},
+ {ok, ResponseCode, _, ResponseBody} = test_request:post(Url ++ "/_replicate",
+ ?USERX_REQ_HEADERS, jiffy:encode(EJRequestBody)),
+
+ % assert replication status
+ {EJResponseBody} = jiffy:decode(ResponseBody),
+ ?assertEqual(ResponseCode, 200),
+ ?assertEqual(true, couch_util:get_value(<<"ok">>, EJResponseBody)),
+ [{History}] = couch_util:get_value(<<"history">>, EJResponseBody),
+
+ MissingChecked = couch_util:get_value(<<"missing_checked">>, History),
+ MissingFound = couch_util:get_value(<<"missing_found">>, History),
+ DocsReard = couch_util:get_value(<<"docs_read">>, History),
+ DocsWritten = couch_util:get_value(<<"docs_written">>, History),
+ DocWriteFailures = couch_util:get_value(<<"doc_write_failures">>, History),
+
+ ?assertEqual(2, MissingChecked),
+ ?assertEqual(2, MissingFound),
+ ?assertEqual(2, DocsReard),
+ ?assertEqual(2, DocsWritten),
+ ?assertEqual(0, DocWriteFailures),
+
+ % assert docs in target db
+ {ok, 200, _, ADBody} = test_request:get(Url ++ "/db2/_all_docs?include_docs=true",
+ ?ADMIN_REQ_HEADERS),
+ {Json} = jiffy:decode(ADBody),
+ ?assertEqual(2, proplists:get_value(<<"total_rows">>, Json))
+ end).
+
+should_allow_user_to_replicate_from_access_to_no_access(_PortType, Url) ->
+ ?_test(begin
+ % create source and target dbs
+ {ok, 201, _, _} = test_request:put(url() ++ "/db2?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db2/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ % create source docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"y\"]}"),
+
+ % replicate
+ UserXUrl = string:replace(Url, "http://", "http://x:x@"),
+ EJRequestBody = {[
+ {<<"source">>, list_to_binary(UserXUrl ++ "/db")},
+ {<<"target">>, list_to_binary(UserXUrl ++ "/db2")}
+ ]},
+ {ok, ResponseCode, _, ResponseBody} = test_request:post(Url ++ "/_replicate",
+ ?USERX_REQ_HEADERS, jiffy:encode(EJRequestBody)),
+
+ % assert replication status
+ {EJResponseBody} = jiffy:decode(ResponseBody),
+ ?assertEqual(ResponseCode, 200),
+ ?assertEqual(true, couch_util:get_value(<<"ok">>, EJResponseBody)),
+ [{History}] = couch_util:get_value(<<"history">>, EJResponseBody),
+
+ MissingChecked = couch_util:get_value(<<"missing_checked">>, History),
+ MissingFound = couch_util:get_value(<<"missing_found">>, History),
+ DocsReard = couch_util:get_value(<<"docs_read">>, History),
+ DocsWritten = couch_util:get_value(<<"docs_written">>, History),
+ DocWriteFailures = couch_util:get_value(<<"doc_write_failures">>, History),
+
+ ?assertEqual(2, MissingChecked),
+ ?assertEqual(2, MissingFound),
+ ?assertEqual(2, DocsReard),
+ ?assertEqual(2, DocsWritten),
+ ?assertEqual(0, DocWriteFailures),
+
+ % assert docs in target db
+ {ok, 200, _, ADBody} = test_request:get(Url ++ "/db2/_all_docs?include_docs=true",
+ ?ADMIN_REQ_HEADERS),
+ {Json} = jiffy:decode(ADBody),
+ ?assertEqual(2, proplists:get_value(<<"total_rows">>, Json))
+ end).
+
+should_allow_user_to_replicate_from_no_access_to_access(_PortType, Url) ->
+ ?_test(begin
+ % create source and target dbs
+ {ok, 201, _, _} = test_request:put(url() ++ "/db2?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db2/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ % create source docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"y\"]}"),
+
+ % replicate
+ UserXUrl = string:replace(Url, "http://", "http://x:x@"),
+ EJRequestBody = {[
+ {<<"source">>, list_to_binary(UserXUrl ++ "/db2")},
+ {<<"target">>, list_to_binary(UserXUrl ++ "/db")}
+ ]},
+ {ok, ResponseCode, _, ResponseBody} = test_request:post(Url ++ "/_replicate",
+ ?USERX_REQ_HEADERS, jiffy:encode(EJRequestBody)),
+
+ % assert replication status
+ {EJResponseBody} = jiffy:decode(ResponseBody),
+ ?assertEqual(ResponseCode, 200),
+ ?assertEqual(true, couch_util:get_value(<<"ok">>, EJResponseBody)),
+ [{History}] = couch_util:get_value(<<"history">>, EJResponseBody),
+
+ MissingChecked = couch_util:get_value(<<"missing_checked">>, History),
+ MissingFound = couch_util:get_value(<<"missing_found">>, History),
+ DocsReard = couch_util:get_value(<<"docs_read">>, History),
+ DocsWritten = couch_util:get_value(<<"docs_written">>, History),
+ DocWriteFailures = couch_util:get_value(<<"doc_write_failures">>, History),
+
+ ?assertEqual(2, MissingChecked),
+ ?assertEqual(2, MissingFound),
+ ?assertEqual(2, DocsReard),
+ ?assertEqual(2, DocsWritten),
+ ?assertEqual(0, DocWriteFailures),
+
+ % assert docs in target db
+ {ok, 200, _, ADBody} = test_request:get(Url ++ "/db/_all_docs?include_docs=true",
+ ?ADMIN_REQ_HEADERS),
+ {Json} = jiffy:decode(ADBody),
+ ?assertEqual(2, proplists:get_value(<<"total_rows">>, Json))
+ end).
+
+should_allow_user_to_replicate_from_no_access_to_no_access(_PortType, Url) ->
+ ?_test(begin
+ % create source and target dbs
+ {ok, 201, _, _} = test_request:put(url() ++ "/db2?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db2/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+
+ {ok, 201, _, _} = test_request:put(url() ++ "/db3?q=1&n=1",
+ ?ADMIN_REQ_HEADERS, ""),
+ % set target db security
+ {ok, _, _, _} = test_request:put(url() ++ "/db3/_security",
+ ?ADMIN_REQ_HEADERS, jiffy:encode(?SECURITY_OBJECT)),
+ % create source docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db2/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"y\"]}"),
+
+ % replicate
+ UserXUrl = string:replace(Url, "http://", "http://x:x@"),
+ EJRequestBody = {[
+ {<<"source">>, list_to_binary(UserXUrl ++ "/db2")},
+ {<<"target">>, list_to_binary(UserXUrl ++ "/db3")}
+ ]},
+ {ok, ResponseCode, _, ResponseBody} = test_request:post(Url ++ "/_replicate",
+ ?USERX_REQ_HEADERS, jiffy:encode(EJRequestBody)),
+
+ % assert replication status
+ {EJResponseBody} = jiffy:decode(ResponseBody),
+ ?assertEqual(ResponseCode, 200),
+ ?assertEqual(true, couch_util:get_value(<<"ok">>, EJResponseBody)),
+ [{History}] = couch_util:get_value(<<"history">>, EJResponseBody),
+
+ MissingChecked = couch_util:get_value(<<"missing_checked">>, History),
+ MissingFound = couch_util:get_value(<<"missing_found">>, History),
+ DocsReard = couch_util:get_value(<<"docs_read">>, History),
+ DocsWritten = couch_util:get_value(<<"docs_written">>, History),
+ DocWriteFailures = couch_util:get_value(<<"doc_write_failures">>, History),
+
+ ?assertEqual(2, MissingChecked),
+ ?assertEqual(2, MissingFound),
+ ?assertEqual(2, DocsReard),
+ ?assertEqual(2, DocsWritten),
+ ?assertEqual(0, DocWriteFailures),
+
+ % assert docs in target db
+ {ok, 200, _, ADBody} = test_request:get(Url ++ "/db3/_all_docs?include_docs=true",
+ ?ADMIN_REQ_HEADERS),
+ {Json} = jiffy:decode(ADBody),
+ ?assertEqual(2, proplists:get_value(<<"total_rows">>, Json))
+ end).
+
+
+
+% revs_diff
+should_not_allow_user_to_revs_diff_other_docs(_PortType, Url) ->
+ ?_test(begin
+ % create test docs
+ {ok, _, _, _} = test_request:put(Url ++ "/db/a",
+ ?ADMIN_REQ_HEADERS, "{\"a\":1,\"_access\":[\"x\"]}"),
+ {ok, _, _, _} = test_request:put(Url ++ "/db/b",
+ ?ADMIN_REQ_HEADERS, "{\"b\":2,\"_access\":[\"x\"]}"),
+ {ok, _, _, V} = test_request:put(Url ++ "/db/c",
+ ?ADMIN_REQ_HEADERS, "{\"c\":3,\"_access\":[\"y\"]}"),
+
+ % nothing missing
+ RevsDiff = {[
+ {<<"a">>, [
+ <<"1-23202479633c2b380f79507a776743d5">>
+ ]}
+ ]},
+ {ok, GoodCode, _, GoodBody} = test_request:post(Url ++ "/db/_revs_diff",
+ ?USERX_REQ_HEADERS, jiffy:encode(RevsDiff)),
+ EJGoodBody = jiffy:decode(GoodBody),
+ ?assertEqual(200, GoodCode),
+ ?assertEqual({[]}, EJGoodBody),
+
+ % something missing
+ MissingRevsDiff = {[
+ {<<"a">>, [
+ <<"1-missing">>
+ ]}
+ ]},
+ {ok, MissingCode, _, MissingBody} = test_request:post(Url ++ "/db/_revs_diff",
+ ?USERX_REQ_HEADERS, jiffy:encode(MissingRevsDiff)),
+ EJMissingBody = jiffy:decode(MissingBody),
+ ?assertEqual(200, MissingCode),
+ MissingExpect = {[
+ {<<"a">>, {[
+ {<<"missing">>, [<<"1-missing">>]}
+ ]}}
+ ]},
+ ?assertEqual(MissingExpect, EJMissingBody),
+
+ % other doc
+ OtherRevsDiff = {[
+ {<<"c">>, [
+ <<"1-92aef5b0e4a3f4db0aba1320869bc95d">>
+ ]}
+ ]},
+ {ok, OtherCode, _, OtherBody} = test_request:post(Url ++ "/db/_revs_diff",
+ ?USERX_REQ_HEADERS, jiffy:encode(OtherRevsDiff)),
+ EJOtherBody = jiffy:decode(OtherBody),
+ ?assertEqual(200, OtherCode),
+ ?assertEqual({[]}, EJOtherBody)
+ end).
%% ------------------------------------------------------------------
%% Internal Function Definitions
%% ------------------------------------------------------------------
diff --git a/src/fabric/src/fabric_doc_open_revs.erl b/src/fabric/src/fabric_doc_open_revs.erl
index 234b108..c4b4250 100644
--- a/src/fabric/src/fabric_doc_open_revs.erl
+++ b/src/fabric/src/fabric_doc_open_revs.erl
@@ -56,8 +56,10 @@ go(DbName, Id, Revs, Options) ->
fabric_util:log_timeout(DefunctWorkers, "open_revs"),
{error, timeout};
Else ->
+ couch_log:debug("~nopen revs result: ~p", [Else]),
Else
after
+ couch_log:debug("~nopen revs result timeout", []),
rexi_monitor:stop(RexiMon)
end.
@@ -143,7 +145,11 @@ handle_message({ok, RawReplies}, Worker, State) ->
workers = lists:delete(Worker, Workers),
repair = InRepair orelse Repair
}}
- end.
+ end;
+handle_message(Message, Worker, State) ->
+ couch_log:debug("~nMessage: ~p", [Message]),
+ couch_log:debug("~nWorker: ~p", [Worker]),
+ couch_log:debug("~nState: ~p", [State]).
tree_replies(RevTree, []) ->
diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index 2b00a36..2ee207d 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -238,7 +238,9 @@ open_doc(DbName, DocId, Options) ->
with_db(DbName, Options, {couch_db, open_doc, [DocId, Options]}).
open_revs(DbName, Id, Revs, Options) ->
- with_db(DbName, Options, {couch_db, open_doc_revs, [Id, Revs, Options]}).
+ R = with_db(DbName, Options, {couch_db, open_doc_revs, [Id, Revs, Options]}),
+ couch_log:debug("~nfabric_rpc:open_revs -> ~p~n", [R]),
+ R.
get_full_doc_info(DbName, DocId, Options) ->
with_db(DbName, Options, {couch_db, get_full_doc_info, [DocId]}).