From 9845dd792f13074df688174b6ecef8d3902804f3 Mon Sep 17 00:00:00 2001 From: Milittle Date: Mon, 20 Feb 2023 10:29:27 +0800 Subject: [PATCH] fix if user does not exist, `desc user xxx` will be raise "User not existed!" (#5345) --- .../user/AuthenticationProcessor.cpp | 15 +++++++- tests/tck/features/user/User.feature | 37 ++++++++----------- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/meta/processors/user/AuthenticationProcessor.cpp b/src/meta/processors/user/AuthenticationProcessor.cpp index e0c863b0995..5b783ab045f 100644 --- a/src/meta/processors/user/AuthenticationProcessor.cpp +++ b/src/meta/processors/user/AuthenticationProcessor.cpp @@ -324,10 +324,23 @@ void GetUserRolesProcessor::process(const cpp2::GetUserRolesReq& req) { folly::SharedMutex::ReadHolder holder(LockUtils::lock()); const auto& act = req.get_account(); + auto retCode = userExist(act); + if (retCode != nebula::cpp2::ErrorCode::SUCCEEDED) { + if (retCode == nebula::cpp2::ErrorCode::E_USER_NOT_FOUND) { + LOG(INFO) << "Get User Roles Failed: " << act << " not found."; + } else { + LOG(INFO) << "Get User Roles Failed, User " << act + << " error: " << apache::thrift::util::enumNameSafe(retCode); + } + handleErrorCode(retCode); + onFinished(); + return; + } + auto prefix = MetaKeyUtils::rolesPrefix(); auto ret = doPrefix(prefix); if (!nebula::ok(ret)) { - auto retCode = nebula::error(ret); + retCode = nebula::error(ret); LOG(INFO) << "Prefix roles failed, error: " << apache::thrift::util::enumNameSafe(retCode); handleErrorCode(retCode); onFinished(); diff --git a/tests/tck/features/user/User.feature b/tests/tck/features/user/User.feature index f2a228c5a81..c6508fc97cc 100644 --- a/tests/tck/features/user/User.feature +++ b/tests/tck/features/user/User.feature @@ -143,12 +143,11 @@ Feature: User & privilege Test DROP USER IF EXISTS u6; """ Then the execution should be successful - # TODO(shylock) fix it - # When executing query: - # """ - # DESC USER u6; - # """ - # Then a ExecutionError should be raised at runtime: User not existed! + When executing query: + """ + DESC USER u6; + """ + Then a ExecutionError should be raised at runtime: User not existed! When executing query: """ DROP USER IF EXISTS u6; @@ -186,12 +185,11 @@ Feature: User & privilege Test DROP USER user_mlt_roles; """ Then the execution should be successful - # TODO(shylock) fix me - # When executing query: - # """ - # DESC USER user_mlt_roles - # """ - # Then a ExecutionError should be raised at runtime: User not existed! + When executing query: + """ + DESC USER user_mlt_roles + """ + Then a ExecutionError should be raised at runtime: User not existed! When executing query: """ CREATE USER user_mlt_roles; @@ -731,8 +729,7 @@ Feature: User & privilege Test """ DESC USER user_not_exist """ - Then the result should be, in any order, with relax comparison: - | role | space | + Then a ExecutionError should be raised at runtime: User not existed! When executing query with user "user1" and password "pwd1": """ DESC USER user1 @@ -766,10 +763,8 @@ Feature: User & privilege Test DESC USER root """ Then a PermissionError should be raised at runtime: - -# TODO(shylock) fix it -# When executing query: -# """ -# DESCRIBE USER not_exists -# """ -# Then a ExecutionError should be raised at runtime: User not existed! + When executing query: + """ + DESCRIBE USER not_exists + """ + Then a ExecutionError should be raised at runtime: User not existed!