This is an automated email from the ASF dual-hosted git repository.

hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git


The following commit(s) were added to refs/heads/unstable by this push:
     new add1a78  Fix should forbid to create the default namespace (#772)
add1a78 is described below

commit add1a788ceea391f7d88384869ccfaf67f1dab92
Author: mathspanda <[email protected]>
AuthorDate: Sun Aug 7 23:44:05 2022 +0800

    Fix should forbid to create the default namespace (#772)
---
 src/config.cc                | 3 +++
 src/redis_cmd.cc             | 2 ++
 tests/cppunit/config_test.cc | 4 ++++
 3 files changed, 9 insertions(+)

diff --git a/src/config.cc b/src/config.cc
index 4151620..2dae8aa 100644
--- a/src/config.cc
+++ b/src/config.cc
@@ -742,6 +742,9 @@ Status Config::AddNamespace(const std::string &ns, const 
std::string &token) {
   if (cluster_enabled) {
     return Status(Status::NotOK, "forbidden to add namespace when cluster mode 
was enabled");
   }
+  if (ns == kDefaultNamespace) {
+    return Status(Status::NotOK, "forbidden to add the default namespace");
+  }
   auto s = isNamespaceLegal(ns);
   if (!s.IsOK()) return s;
   if (tokens.find(token) != tokens.end()) {
diff --git a/src/redis_cmd.cc b/src/redis_cmd.cc
index 018f689..886613b 100644
--- a/src/redis_cmd.cc
+++ b/src/redis_cmd.cc
@@ -112,6 +112,8 @@ class CommandNamespace : public Commander {
           namespaces.emplace_back(iter->second);  // namespace
           namespaces.emplace_back(iter->first);   // token
         }
+        namespaces.emplace_back(kDefaultNamespace);
+        namespaces.emplace_back(config->requirepass);
         *output = Redis::MultiBulkString(namespaces, false);
       } else {
         std::string token;
diff --git a/tests/cppunit/config_test.cc b/tests/cppunit/config_test.cc
index 74f31a7..7efc056 100644
--- a/tests/cppunit/config_test.cc
+++ b/tests/cppunit/config_test.cc
@@ -179,6 +179,10 @@ TEST(Namespace, Add) {
   auto s = config.AddNamespace("n1", "t0");
   EXPECT_FALSE(s.IsOK());
   EXPECT_EQ(s.Msg(), "the namespace has already exists");
+
+  s = config.AddNamespace(kDefaultNamespace, "mytoken");
+  EXPECT_FALSE(s.IsOK());
+  EXPECT_EQ(s.Msg(), "forbidden to add the default namespace");
   unlink(path);
 }
 

Reply via email to