couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject couch-replicator commit: updated refs/heads/3118-validate-_replicate-payload to b9232c8
Date Thu, 01 Sep 2016 19:05:12 GMT
Repository: couchdb-couch-replicator
Updated Branches:
  refs/heads/3118-validate-_replicate-payload [created] b9232c8d4


Validate boolean parameters in /_replicate payload


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

Branch: refs/heads/3118-validate-_replicate-payload
Commit: b9232c8d410d529d65030896e075c4b4327631b0
Parents: 0248d23
Author: Eric Avdey <eiri@eiri.ca>
Authored: Thu Sep 1 15:59:13 2016 -0300
Committer: Eric Avdey <eiri@eiri.ca>
Committed: Thu Sep 1 15:59:13 2016 -0300

----------------------------------------------------------------------
 src/couch_replicator_utils.erl | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/b9232c8d/src/couch_replicator_utils.erl
----------------------------------------------------------------------
diff --git a/src/couch_replicator_utils.erl b/src/couch_replicator_utils.erl
index 76bc8e1..223bac8 100644
--- a/src/couch_replicator_utils.erl
+++ b/src/couch_replicator_utils.erl
@@ -278,14 +278,20 @@ make_options(Props) ->
 
 convert_options([])->
     [];
+convert_options([{<<"cancel">>, V} | _R]) when not is_boolean(V)->
+    throw({bad_request, <<"parameter `cancel` must be a boolean">>});
 convert_options([{<<"cancel">>, V} | R]) ->
     [{cancel, V} | convert_options(R)];
 convert_options([{IdOpt, V} | R]) when IdOpt =:= <<"_local_id">>;
         IdOpt =:= <<"replication_id">>; IdOpt =:= <<"id">> ->
     Id = lists:splitwith(fun(X) -> X =/= $+ end, ?b2l(V)),
     [{id, Id} | convert_options(R)];
+convert_options([{<<"create_target">>, V} | _R]) when not is_boolean(V)->
+    throw({bad_request, <<"parameter `create_target` must be a boolean">>});
 convert_options([{<<"create_target">>, V} | R]) ->
     [{create_target, V} | convert_options(R)];
+convert_options([{<<"continuous">>, V} | _R]) when not is_boolean(V)->
+    throw({bad_request, <<"parameter `continuous` must be a boolean">>});
 convert_options([{<<"continuous">>, V} | R]) ->
     [{continuous, V} | convert_options(R)];
 convert_options([{<<"filter">>, V} | R]) ->
@@ -541,4 +547,30 @@ check_options_fail_values_test() ->
     ?assertThrow({bad_request, _},
         check_options([{doc_ids, x}, {selector, y}, {filter, z}])).
 
+check_convert_options_pass_test() ->
+    ?assertEqual([], convert_options([])),
+    ?assertEqual([], convert_options([{<<"random">>, 42}])),
+    ?assertEqual([{cancel, true}],
+        convert_options([{<<"cancel">>, true}])),
+    ?assertEqual([{create_target, true}],
+        convert_options([{<<"create_target">>, true}])),
+    ?assertEqual([{continuous, true}],
+        convert_options([{<<"continuous">>, true}])),
+    ?assertEqual([{doc_ids, [<<"id">>]}],
+        convert_options([{<<"doc_ids">>, [<<"id">>]}])),
+    ?assertEqual([{selector, {key, value}}],
+        convert_options([{<<"selector">>, {key, value}}])).
+
+check_convert_options_fail_test() ->
+    ?assertThrow({bad_request, _},
+        convert_options([{<<"cancel">>, <<"true">>}])),
+    ?assertThrow({bad_request, _},
+        convert_options([{<<"create_target">>, <<"true">>}])),
+    ?assertThrow({bad_request, _},
+        convert_options([{<<"continuous">>, <<"true">>}])),
+    ?assertThrow({bad_request, _},
+        convert_options([{<<"doc_ids">>, not_a_list}])),
+    ?assertThrow({bad_request, _},
+        convert_options([{<<"selector">>, [{key, value}]}])).
+
 -endif.


Mime
View raw message