Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DB3E7200B4C for ; Fri, 22 Jul 2016 20:49:21 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id D9DD6160A91; Fri, 22 Jul 2016 18:49:21 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2DD4D160A5A for ; Fri, 22 Jul 2016 20:49:21 +0200 (CEST) Received: (qmail 60001 invoked by uid 500); 22 Jul 2016 18:49:20 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 59992 invoked by uid 99); 22 Jul 2016 18:49:20 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jul 2016 18:49:20 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id EE01AE058E; Fri, 22 Jul 2016 18:49:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: vatamane@apache.org To: commits@couchdb.apache.org Message-Id: <186944fbbbed47bca2e708ad20ffc03e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: chttpd commit: updated refs/heads/master to 5b6d1b1 Date: Fri, 22 Jul 2016 18:49:19 +0000 (UTC) archived-at: Fri, 22 Jul 2016 18:49:22 -0000 Repository: couchdb-chttpd Updated Branches: refs/heads/master ccaa4429c -> 5b6d1b1dc In a multi-query view request, set view type for each query Namely, a default `reduce` view type can be overridden to behave like a `map`, if user explicitly sets `reduce=false`. Previously this didn't happen. For example, a query like this: ``` { "queries": [{ "include_docs": true, "reduce": false }] } ``` would fail with: ``` {"error":"query_parse_error","reason":"`include_docs` is invalid for reduce"} ``` but it shouldn't, because user explicitly disabled `reduce` and now `include_docs` is valid for a map view. To fix, make sure to call `set_view_type` for each query's args. Jira: COUCHDB-3070 Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/5b6d1b1d Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/5b6d1b1d Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/5b6d1b1d Branch: refs/heads/master Commit: 5b6d1b1dc2809af464fc11385d558631593f0614 Parents: ccaa442 Author: Nick Vatamaniuc Authored: Thu Jul 21 17:48:15 2016 -0400 Committer: Nick Vatamaniuc Committed: Fri Jul 22 14:48:42 2016 -0400 ---------------------------------------------------------------------- src/chttpd_view.erl | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/5b6d1b1d/src/chttpd_view.erl ---------------------------------------------------------------------- diff --git a/src/chttpd_view.erl b/src/chttpd_view.erl index 4889b65..32b6469 100644 --- a/src/chttpd_view.erl +++ b/src/chttpd_view.erl @@ -23,7 +23,8 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) -> ArgQueries = lists:map(fun({Query}) -> QueryArg = couch_mrview_http:parse_params(Query, undefined, Args1, [decoded]), - couch_mrview_util:validate_args(QueryArg) + QueryArg1 = couch_mrview_util:set_view_type(QueryArg, ViewName, Views), + couch_mrview_util:validate_args(QueryArg1) end, Queries), VAcc0 = #vacc{db=Db, req=Req, prepend="\r\n"}, FirstChunk = "{\"results\":[", @@ -78,3 +79,55 @@ handle_view_req(Req, _Db, _DDoc) -> handle_temp_view_req(Req, _Db) -> Msg = <<"Temporary views are not supported in CouchDB">>, chttpd:send_error(Req, 403, forbidden, Msg). + + + +-ifdef(TEST). + +-include_lib("eunit/include/eunit.hrl"). + + +check_multi_query_reduce_view_overrides_test_() -> + { + foreach, + fun setup/0, + fun teardown/1, + [ + t_check_include_docs_throw_validation_error(), + t_check_user_can_override_individual_query_type() + ] + }. + + +t_check_include_docs_throw_validation_error() -> + ?_test(begin + Req = #httpd{qs = []}, + Query = {[{<<"include_docs">>, true}]}, + Throw = {query_parse_error, <<"`include_docs` is invalid for reduce">>}, + ?assertThrow(Throw, multi_query_view(Req, db, ddoc, <<"v">>, [Query])) + end). + + +t_check_user_can_override_individual_query_type() -> + ?_test(begin + Req = #httpd{qs = []}, + Query = {[{<<"include_docs">>, true}, {<<"reduce">>, false}]}, + multi_query_view(Req, db, ddoc, <<"v">>, [Query]), + ?assertEqual(1, meck:num_calls(chttpd, start_delayed_json_response, '_')) + end). + + +setup() -> + Views = [#mrview{reduce_funs = [{<<"v">>, <<"_count">>}]}], + meck:expect(couch_mrview_util, ddoc_to_mrst, 2, {ok, #mrst{views = Views}}), + meck:expect(chttpd, start_delayed_json_response, 4, {ok, resp}), + meck:expect(fabric, query_view, 6, {ok, #vacc{}}), + meck:expect(chttpd, send_delayed_chunk, 2, {ok, resp}), + meck:expect(chttpd, end_delayed_json_response, 1, ok). + + +teardown(_) -> + meck:unload(). + + +-endif.