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 4206D200D2F for ; Wed, 1 Nov 2017 08:03:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 40A65160BFE; Wed, 1 Nov 2017 07:03:01 +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 9130D160BEA for ; Wed, 1 Nov 2017 08:03:00 +0100 (CET) Received: (qmail 28474 invoked by uid 500); 1 Nov 2017 07:02:59 -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 28455 invoked by uid 99); 1 Nov 2017 07:02:59 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Nov 2017 07:02:59 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 75E8D8174D; Wed, 1 Nov 2017 07:02:56 +0000 (UTC) Date: Wed, 01 Nov 2017 07:02:57 +0000 To: "commits@couchdb.apache.org" Subject: [couchdb] 01/07: Return username on POST to /_session MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit From: jan@apache.org In-Reply-To: <150951977647.29233.8993470990220121823@gitbox.apache.org> References: <150951977647.29233.8993470990220121823@gitbox.apache.org> X-Git-Host: gitbox.apache.org X-Git-Repo: couchdb X-Git-Refname: refs/heads/1.x.x X-Git-Reftype: branch X-Git-Rev: 53dcb010623b2b6672f1cf379906b800ab1e53a8 X-Git-NotificationType: diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated Message-Id: <20171101070257.75E8D8174D@gitbox.apache.org> archived-at: Wed, 01 Nov 2017 07:03:01 -0000 This is an automated email from the ASF dual-hosted git repository. jan pushed a commit to branch 1.x.x in repository https://gitbox.apache.org/repos/asf/couchdb.git commit 53dcb010623b2b6672f1cf379906b800ab1e53a8 Author: Robert Kowalski AuthorDate: Sun Nov 23 16:34:58 2014 +0100 Return username on POST to /_session When logging in with admin credentials and no user doc is present, the name was `null`. Example: `{"ok":true,"name":null,"roles":["_admin"]}` closes COUCHDB-1356 --- share/doc/src/whatsnew/1.7.rst | 1 + src/couchdb/couch_httpd_auth.erl | 2 +- test/couchdb/Makefile.am | 1 + test/couchdb/couchdb_auth_tests.erl | 62 +++++++++++++++++++++++++++++++++++++ test/couchdb/eunit.ini | 4 +++ test/couchdb/test_request.erl | 5 +++ 6 files changed, 74 insertions(+), 1 deletion(-) diff --git a/share/doc/src/whatsnew/1.7.rst b/share/doc/src/whatsnew/1.7.rst index e16f150..fd6287a 100644 --- a/share/doc/src/whatsnew/1.7.rst +++ b/share/doc/src/whatsnew/1.7.rst @@ -28,6 +28,7 @@ Version 1.7.0 API Changes ----------- +- :issue:`1356`: Return username on :http:post:`/_session`. - :issue:`1876`: Fix duplicated Content-Type for show/update functions. Build diff --git a/src/couchdb/couch_httpd_auth.erl b/src/couchdb/couch_httpd_auth.erl index 3052832..df5e0f5 100644 --- a/src/couchdb/couch_httpd_auth.erl +++ b/src/couchdb/couch_httpd_auth.erl @@ -288,7 +288,7 @@ handle_session_req(#httpd{method='POST', mochi_req=MochiReq}=Req) -> send_json(Req#httpd{req_body=ReqBody}, Code, Headers, {[ {ok, true}, - {name, couch_util:get_value(<<"name">>, UserProps2, null)}, + {name, UserName}, {roles, couch_util:get_value(<<"roles">>, UserProps2, [])} ]}); _Else -> diff --git a/test/couchdb/Makefile.am b/test/couchdb/Makefile.am index eaac42f..43e3747 100644 --- a/test/couchdb/Makefile.am +++ b/test/couchdb/Makefile.am @@ -42,6 +42,7 @@ eunit_files = \ couch_uuids_tests.erl \ couch_work_queue_tests.erl \ couchdb_attachments_tests.erl \ + couchdb_auth_tests.erl \ couchdb_compaction_daemon.erl \ couchdb_cors_tests.erl \ couchdb_file_compression_tests.erl \ diff --git a/test/couchdb/couchdb_auth_tests.erl b/test/couchdb/couchdb_auth_tests.erl new file mode 100644 index 0000000..1bd7d3f --- /dev/null +++ b/test/couchdb/couchdb_auth_tests.erl @@ -0,0 +1,62 @@ +% 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(couchdb_auth_tests). + +-include("couch_eunit.hrl"). +-include_lib("couchdb/couch_db.hrl"). + + +start() -> + couch_server_sup:start_link(?CONFIG_CHAIN), + ok. + +stop(_) -> + couch_server_sup:stop(), + ok. + +setup() -> + Addr = couch_config:get("httpd", "bind_address", "127.0.0.1"), + Port = integer_to_list(mochiweb_socket_server:get(couch_httpd, port)), + lists:concat(["http://", Addr, ":", Port, "/_session"]). + +teardown(_) -> + ok. + + +auth_test_() -> + { + "Auth tests", + { + setup, + fun start/0, fun stop/1, + { + foreach, + fun setup/0, fun teardown/1, + [ + fun should_not_return_username_on_post_to_session/1 + ] + } + } + }. + + +should_not_return_username_on_post_to_session(Url) -> + ?_assertEqual(<<"rocko">>, + begin + ok = couch_config:set("admins", "rocko", "artischocko", false), + {ok, _, _, Body} = test_request:post(Url, + [{"Content-Type", "application/json"}], + "{\"name\":\"rocko\", \"password\":\"artischocko\"}"), + {Json} = ?JSON_DECODE(Body), + couch_util:get_value(<<"name">>, Json) + end). diff --git a/test/couchdb/eunit.ini b/test/couchdb/eunit.ini index 50024a3..a1a041c 100644 --- a/test/couchdb/eunit.ini +++ b/test/couchdb/eunit.ini @@ -26,3 +26,7 @@ port = 0 ; logging is disabled to remove unwanted noise in stdout from tests processing level = none include_sasl = false + +[couch_httpd_auth] +; time to relax! +secret = 74696d6520746f2072656c617821 diff --git a/test/couchdb/test_request.erl b/test/couchdb/test_request.erl index 68e4956..4d09b0c 100644 --- a/test/couchdb/test_request.erl +++ b/test/couchdb/test_request.erl @@ -13,6 +13,7 @@ -module(test_request). -export([get/1, get/2, get/3]). +-export([post/3]). -export([put/2, put/3]). -export([options/1, options/2, options/3]). -export([request/3, request/4]). @@ -26,6 +27,10 @@ get(Url, Headers, Opts) -> request(get, Url, Headers, [], Opts). +post(Url, Headers, Body) -> + request(post, Url, Headers, Body). + + put(Url, Body) -> request(put, Url, [], Body). -- To stop receiving notification emails like this one, please contact "commits@couchdb.apache.org" .