You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2015/07/01 15:22:03 UTC

[1/3] couch-mrview commit: updated refs/heads/master to 1c10f21

Repository: couchdb-couch-mrview
Updated Branches:
  refs/heads/master 19737b758 -> 1c10f21cf


Validate named reduce function against whitelist

COUCHDB-537


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

Branch: refs/heads/master
Commit: edb2c8517485a701ac38ebc8c4de2cd4df5a12a0
Parents: 19737b7
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Tue Jun 30 20:55:05 2015 -0400
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Tue Jun 30 20:55:05 2015 -0400

----------------------------------------------------------------------
 src/couch_mrview.erl | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/edb2c851/src/couch_mrview.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview.erl b/src/couch_mrview.erl
index 5583f1f..5d56af8 100644
--- a/src/couch_mrview.erl
+++ b/src/couch_mrview.erl
@@ -64,8 +64,15 @@ validate(DbName, DDoc) ->
     ValidateView = fun(Proc, #mrview{def=MapSrc, reduce_funs=Reds}=View) ->
         couch_query_servers:try_compile(Proc, map, GetName(View), MapSrc),
         lists:foreach(fun
-            ({_RedName, <<"_", _/binary>>}) ->
+            ({_RedName, <<"_sum", _/binary>>}) ->
                 ok;
+            ({_RedName, <<"_count", _/binary>>}) ->
+                ok;
+            ({_RedName, <<"_stats", _/binary>>}) ->
+                ok;
+            ({_RedName, <<"_", _/binary>> = Bad}) ->
+                Msg = ["`", Bad, "` is not a supported reduce function."],
+                throw({invalid_design_doc, Msg});
             ({RedName, RedSrc}) ->
                 couch_query_servers:try_compile(Proc, reduce, RedName, RedSrc)
         end, Reds)


[3/3] couch-mrview commit: updated refs/heads/master to 1c10f21

Posted by ko...@apache.org.
Merge branch '537-whitelist-builtin-reduce-funs'


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

Branch: refs/heads/master
Commit: 1c10f21cfcb1d9d58be89c98782873c3a893fd11
Parents: 19737b7 6343efd
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Wed Jul 1 09:21:55 2015 -0400
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Wed Jul 1 09:21:55 2015 -0400

----------------------------------------------------------------------
 src/couch_mrview.erl                        |  9 ++-
 test/couch_mrview_ddoc_validation_tests.erl | 78 ++++++++++++++++++++++++
 2 files changed, 86 insertions(+), 1 deletion(-)
----------------------------------------------------------------------



[2/3] couch-mrview commit: updated refs/heads/master to 1c10f21

Posted by ko...@apache.org.
Add tests for design document validations

COUCHDB-537


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

Branch: refs/heads/master
Commit: 6343efd6768a3d4d4ff2c6e1b22200f4e4aaca3f
Parents: edb2c85
Author: Adam Kocoloski <ad...@cloudant.com>
Authored: Tue Jun 30 21:27:41 2015 -0400
Committer: Adam Kocoloski <ad...@cloudant.com>
Committed: Tue Jun 30 21:32:17 2015 -0400

----------------------------------------------------------------------
 test/couch_mrview_ddoc_validation_tests.erl | 78 ++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/6343efd6/test/couch_mrview_ddoc_validation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_ddoc_validation_tests.erl b/test/couch_mrview_ddoc_validation_tests.erl
new file mode 100644
index 0000000..17cd4d3
--- /dev/null
+++ b/test/couch_mrview_ddoc_validation_tests.erl
@@ -0,0 +1,78 @@
+% 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(couch_mrview_ddoc_validation_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+setup() ->
+    {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), map),
+    Db.
+
+teardown(Db) ->
+    couch_db:close(Db),
+    couch_server:delete(Db#db.name, [?ADMIN_CTX]),
+    ok.
+
+ddoc_validation_test_() ->
+    {
+        "ddoc validation tests",
+        {
+            setup,
+            fun test_util:start_couch/0, fun test_util:stop_couch/1,
+            {
+                foreach,
+                fun setup/0, fun teardown/1,
+                [
+                    fun should_reject_invalid_js_map/1,
+                    fun should_reject_invalid_js_reduce/1,
+                    fun should_reject_invalid_builtin_reduce/1
+                ]
+            }
+        }
+    }.
+
+should_reject_invalid_js_map(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_reject_invalid_js_map">>},
+        {<<"views">>, {[
+            {<<"foo">>, {[
+                {<<"map">>, <<"function(doc) }{">>}
+            ]}}
+        ]}}
+    ]}),
+    ?_assertThrow({compilation_error, _}, couch_db:update_doc(Db, Doc, [])).
+
+should_reject_invalid_js_reduce(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_reject_invalid_js_reduce">>},
+        {<<"views">>, {[
+            {<<"foo">>, {[
+                {<<"map">>, <<"function(doc) { emit(null); }">>},
+                {<<"reduce">>, <<"function(k, v, r) }{}">>}
+            ]}}
+        ]}}
+    ]}),
+    ?_assertThrow({compilation_error, _}, couch_db:update_doc(Db, Doc, [])).
+
+should_reject_invalid_builtin_reduce(Db) ->
+    Doc = couch_doc:from_json_obj({[
+        {<<"_id">>, <<"_design/should_reject_invalid_builtin_reduce">>},
+        {<<"views">>, {[
+            {<<"foo">>, {[
+                {<<"map">>, <<"function(doc) { emit(null); }">>},
+                {<<"reduce">>, <<"_foobar">>}
+            ]}}
+        ]}}
+    ]}),
+    ?_assertThrow({invalid_design_doc, _}, couch_db:update_doc(Db, Doc, [])).