Skip to content

Commit

Permalink
Avoid drop root user. (#4885)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shylock-Hg authored Nov 18, 2022
1 parent 099c6f1 commit afaf442
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/graph/validator/ACLValidator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@

#include "graph/validator/ACLValidator.h"

#include "common/base/Status.h"
#include "graph/planner/plan/Admin.h"
#include "graph/service/PermissionManager.h"
#include "graph/validator/Validator.h"

namespace nebula {
namespace graph {
Expand Down Expand Up @@ -44,6 +46,16 @@ Status DropUserValidator::validateImpl() {
return Status::OK();
}

Status DropUserValidator::checkPermission() {
auto r = Validator::checkPermission();
NG_RETURN_IF_ERROR(r);
const auto *sentence = static_cast<const DropUserSentence *>(sentence_);
if (*sentence->getAccount() == "root") {
return Status::SemanticError("Can't drop root user.");
}
return Status::OK();
}

Status DropUserValidator::toPlan() {
auto sentence = static_cast<DropUserSentence *>(sentence_);
return genSingleNodePlan<DropUser>(sentence->getAccount(), sentence->ifExists());
Expand Down
2 changes: 2 additions & 0 deletions src/graph/validator/ACLValidator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ class DropUserValidator final : public Validator {
private:
Status validateImpl() override;

Status checkPermission() override;

Status toPlan() override;
};

Expand Down
12 changes: 12 additions & 0 deletions tests/tck/features/bugfix/DropRootUser.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright (c) 2022 vesoft inc. All rights reserved.
#
# This source code is licensed under Apache 2.0 License.
Feature: Test drop root user

# #4879
Scenario: Drop root user
When executing query:
"""
DROP USER root
"""
Then a SemanticError should be raised at runtime: Can't drop root user.

0 comments on commit afaf442

Please sign in to comment.