From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp15.mail.ru (smtp15.mail.ru [94.100.176.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id D7252452566 for ; Fri, 1 Nov 2019 00:37:01 +0300 (MSK) From: Vladislav Shpilevoy Date: Thu, 31 Oct 2019 22:42:33 +0100 Message-Id: <9a689ea853eacdac07dba2aa426cf096cba86a49.1572558071.git.v.shpilevoy@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [Tarantool-patches] [PATCH 2/3] user: don't throw C++ exception from user_find_by_name List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: tarantool-patches@dev.tarantool.org This function is supposed to return NULL on an error. For exceptions there is user_find_by_name_xc. --- src/box/user.cc | 2 +- test/box/access.result | 11 +++++++++++ test/box/access.test.lua | 6 ++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/box/user.cc b/src/box/user.cc index 6b562b1f0..03b4b2e3b 100644 --- a/src/box/user.cc +++ b/src/box/user.cc @@ -519,7 +519,7 @@ user_find_by_name(const char *name, uint32_t len) { uint32_t uid; if (schema_find_id(BOX_USER_ID, 2, name, len, &uid) != 0) - diag_raise(); + return NULL; struct user *user = user_by_id(uid); if (user == NULL || user->def->type != SC_USER) { diag_set(ClientError, ER_NO_SUCH_USER, tt_cstr(name, len)); diff --git a/test/box/access.result b/test/box/access.result index 3976adfde..dc339038d 100644 --- a/test/box/access.result +++ b/test/box/access.result @@ -239,6 +239,17 @@ session.user() --- - admin ... +-- Invalid user. +session.su('does not exist') +--- +- error: User 'does not exist' is not found +... +-- The point of this test is to try a name > max +-- allowed name. +session.su(string.rep('a', 66000)) +--- +- error: name length 66000 is greater than BOX_NAME_MAX +... -------------------------------------------------------------------------------- -- Check if identifiers obey the common constraints -------------------------------------------------------------------------------- diff --git a/test/box/access.test.lua b/test/box/access.test.lua index 89a63c904..a9843d155 100644 --- a/test/box/access.test.lua +++ b/test/box/access.test.lua @@ -100,6 +100,12 @@ session.su('admin') box.schema.user.drop('tester') session.user() +-- Invalid user. +session.su('does not exist') +-- The point of this test is to try a name > max +-- allowed name. +session.su(string.rep('a', 66000)) + -------------------------------------------------------------------------------- -- Check if identifiers obey the common constraints -------------------------------------------------------------------------------- -- 2.21.0 (Apple Git-122.2)