Skip to content

Commit b1e1899

Browse files
committed
fix remaining access tests
1 parent 5ec411a commit b1e1899

File tree

2 files changed

+7
-49
lines changed

2 files changed

+7
-49
lines changed

src/couch/src/couch_db_updater.erl

+4-3
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ sort_and_tag_grouped_docs(Client, GroupedDocs, UserCtx) ->
266266
% duplicate documents if the incoming groups are not sorted, so as a sanity
267267
% check we sort them again here. See COUCHDB-2735.
268268
Cmp = fun([#doc{id = A} | _], [#doc{id = B} | _]) -> A < B end,
269+
% couch_log:notice("~n s_a_t_g_d: GroupedDocs: ~p, UserCtx: ~p ~n", [GroupedDocs, UserCtx]),
269270
lists:map(
270271
fun(DocGroup) ->
271272
[{Client, maybe_tag_doc(D), UserCtx} || D <- DocGroup]
@@ -739,7 +740,7 @@ update_docs_int(Db, DocsList, LocalDocs, ReplicatedChanges) ->
739740
{DocsListValidated, OldDocInfosValidated} = validate_docs_access(
740741
Db, DocsList, OldDocInfos
741742
),
742-
743+
% couch_log:notice("~n~n u_d_i: DocsList: ~p~n, OldDocInfos: ~p~n, DocsListValidated: ~p~n, OldDocInfosValidated: ~p~n~n~n", [DocsList, OldDocInfos, DocsListValidated, OldDocInfosValidated]),
743744
{ok, AccOut} = merge_rev_trees(DocsListValidated, OldDocInfosValidated, AccIn),
744745
#merge_acc{
745746
add_infos = NewFullDocInfos,
@@ -791,7 +792,7 @@ validate_docs_access_int(Db, DocsList, OldDocInfos) ->
791792
validate_docs_access(_Db, [], [], DocsListValidated, OldDocInfosValidated) ->
792793
% TODO: check if need to reverse this? maybe this is the cause of the test reverse issue?
793794
% {lists:reverse(DocsListValidated), lists:reverse(OldDocInfosValidated)};
794-
{DocsListValidated, OldDocInfosValidated};
795+
{lists:reverse(DocsListValidated), lists:reverse(OldDocInfosValidated)};
795796
validate_docs_access(
796797
Db, [Docs | DocRest], [OldInfo | OldInfoRest], DocsListValidated, OldDocInfosValidated
797798
) ->
@@ -831,7 +832,7 @@ validate_docs_access(
831832
case length(NewDocs) of
832833
% we sent out all docs as invalid access, drop the old doc info associated with it
833834
0 ->
834-
{[NewDocs | DocsListValidated], OldDocInfosValidated};
835+
{DocsListValidated, OldDocInfosValidated};
835836
_ ->
836837
{[NewDocs | DocsListValidated], [OldInfo | OldDocInfosValidated]}
837838
end,

src/couch/test/eunit/couchdb_access_tests.erl

+3-46
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ access_test_() ->
8787
fun should_let_user_create_doc_for_themselves/2,
8888
fun should_not_let_user_create_doc_for_someone_else/2,
8989
fun should_let_user_create_access_ddoc/2,
90-
% fun access_ddoc_should_have_no_effects/2,
90+
fun access_ddoc_should_have_no_effects/2,
9191

9292
% Doc updates
9393
fun users_with_access_can_update_doc/2,
@@ -100,8 +100,6 @@ access_test_() ->
100100
fun user_with_access_can_read_doc/2,
101101
fun user_without_access_can_not_read_doc/2,
102102
fun user_can_not_read_doc_without_access/2,
103-
fun admin_with_access_can_read_conflicted_doc/2,
104-
% fun user_with_access_can_not_read_conflicted_doc/2,
105103

106104
% Doc deletes
107105
fun should_let_admin_delete_doc_with_access/2,
@@ -130,10 +128,8 @@ access_test_() ->
130128

131129
fun should_allow_user_to_replicate_from_access_to_access/2,
132130
fun should_allow_user_to_replicate_from_access_to_no_access/2,
133-
% TODO: find out why this is flakey
134-
% fun should_allow_user_to_replicate_from_no_access_to_access/2,
135-
136-
% fun should_allow_user_to_replicate_from_no_access_to_no_access/2,
131+
fun should_allow_user_to_replicate_from_no_access_to_access/2,
132+
fun should_allow_user_to_replicate_from_no_access_to_no_access/2,
137133

138134
% _revs_diff for docs you don’t have access to
139135
fun should_not_allow_user_to_revs_diff_other_docs/2
@@ -373,45 +369,6 @@ user_with_access_can_read_doc(_PortType, Url) ->
373369
),
374370
?_assertEqual(200, Code).
375371

376-
% TODO: induce conflict with two different _access users per rev
377-
% could be comiing from a split-brain scenario
378-
% whoever ends up winner can read the doc, but not the leaf
379-
% that doesn’t belong to them
380-
% whoever loses can only request their leaf
381-
% user_with_access_can_not_read_conflicted_doc(_PortType, Url) ->
382-
% {ok, 201, _, _} = test_request:put(
383-
% Url ++ "/db/a",
384-
% ?ADMIN_REQ_HEADERS,
385-
% "{\"_id\":\"f1\",\"a\":1,\"_access\":[\"x\"]}"
386-
% ),
387-
% {ok, 201, _, _} = test_request:put(
388-
% Url ++ "/db/a?new_edits=false",
389-
% ?ADMIN_REQ_HEADERS,
390-
% "{\"_id\":\"f1\",\"_rev\":\"7-XYZ\",\"a\":1,\"_access\":[\"x\"]}"
391-
% ),
392-
% {ok, Code, _, _} = test_request:get(
393-
% Url ++ "/db/a",
394-
% ?USERX_REQ_HEADERS
395-
% ),
396-
% ?_assertEqual(403, Code).
397-
398-
admin_with_access_can_read_conflicted_doc(_PortType, Url) ->
399-
{ok, 201, _, _} = test_request:put(
400-
Url ++ "/db/a",
401-
?ADMIN_REQ_HEADERS,
402-
"{\"_id\":\"a\",\"a\":1,\"_access\":[\"x\"]}"
403-
),
404-
{ok, 201, _, _} = test_request:put(
405-
Url ++ "/db/a?new_edits=false",
406-
?ADMIN_REQ_HEADERS,
407-
"{\"_id\":\"a\",\"_rev\":\"7-XYZ\",\"a\":1,\"_access\":[\"x\"]}"
408-
),
409-
{ok, Code, _, _} = test_request:get(
410-
Url ++ "/db/a",
411-
?ADMIN_REQ_HEADERS
412-
),
413-
?_assertEqual(200, Code).
414-
415372
user_without_access_can_not_read_doc(_PortType, Url) ->
416373
{ok, 201, _, _} = test_request:put(
417374
Url ++ "/db/a",

0 commit comments

Comments
 (0)