Tarantool development patches archive
 help / color / mirror / Atom feed
From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@dev.tarantool.org
Subject: [Tarantool-patches] [PATCH 2/3] user: don't throw C++ exception from user_find_by_name
Date: Thu, 31 Oct 2019 22:42:33 +0100	[thread overview]
Message-ID: <9a689ea853eacdac07dba2aa426cf096cba86a49.1572558071.git.v.shpilevoy@tarantool.org> (raw)
In-Reply-To: <cover.1572558071.git.v.shpilevoy@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)

  parent reply	other threads:[~2019-10-31 21:37 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-31 21:42 [Tarantool-patches] [PATCH 0/3] Credentials follow up Vladislav Shpilevoy
2019-10-31 21:42 ` [Tarantool-patches] [PATCH 1/3] test: fix flaky box/access_sysview.test.lua Vladislav Shpilevoy
2019-11-04 17:20   ` Konstantin Osipov
2019-10-31 21:42 ` Vladislav Shpilevoy [this message]
2019-11-04 17:22   ` [Tarantool-patches] [PATCH 2/3] user: don't throw C++ exception from user_find_by_name Konstantin Osipov
2019-11-05  9:44     ` Vladislav Shpilevoy
2019-10-31 21:42 ` [Tarantool-patches] [PATCH 3/3] session: su left dangling credentials object on stack Vladislav Shpilevoy
2019-11-04 17:23   ` Konstantin Osipov
2019-11-01 13:54 ` [Tarantool-patches] [PATCH 0/3] Credentials follow up Kirill Yukhin
2019-11-04 17:23   ` Konstantin Osipov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9a689ea853eacdac07dba2aa426cf096cba86a49.1572558071.git.v.shpilevoy@tarantool.org \
    --to=v.shpilevoy@tarantool.org \
    --cc=tarantool-patches@dev.tarantool.org \
    --subject='Re: [Tarantool-patches] [PATCH 2/3] user: don'\''t throw C++ exception from user_find_by_name' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox