From a8788ec3a6f532ab70e2ebe58a2ea45561ec3101 Mon Sep 17 00:00:00 2001 From: kailixu Date: Fri, 7 Jun 2024 13:30:10 +0800 Subject: [PATCH] enh: check range for user enable/sysinfo/createdb --- source/libs/parser/src/parTranslater.c | 4 ++-- tests/script/tsim/user/basic.sim | 12 ++++++++++++ tests/system-test/0-others/user_control.py | 17 ++++++++++++++++- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/source/libs/parser/src/parTranslater.c b/source/libs/parser/src/parTranslater.c index cb5c31183e..e246efc54f 100644 --- a/source/libs/parser/src/parTranslater.c +++ b/source/libs/parser/src/parTranslater.c @@ -6579,9 +6579,9 @@ static int32_t buildCreateDbReq(STranslateContext* pCxt, SCreateDatabaseStmt* pS static int32_t checkRangeOption(STranslateContext* pCxt, int32_t code, const char* pName, int64_t val, int64_t minVal, int64_t maxVal) { - if (val >= 0 && (val < minVal || val > maxVal)) { + if (val < minVal || val > maxVal) { return generateSyntaxErrMsgExt(&pCxt->msgBuf, code, - "Invalid option: %s %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]", pName, + "Invalid option %s: %" PRId64 ", valid range: [%" PRId64 ", %" PRId64 "]", pName, val, minVal, maxVal); } return TSDB_CODE_SUCCESS; diff --git a/tests/script/tsim/user/basic.sim b/tests/script/tsim/user/basic.sim index 6502123b73..353e1d080a 100644 --- a/tests/script/tsim/user/basic.sim +++ b/tests/script/tsim/user/basic.sim @@ -214,5 +214,17 @@ if $data(u2)[4] != 0 then return -1 endi +sql_error CREATE USER u100 PASS 'taosdata' SYSINFO -1; +sql_error CREATE USER u101 PASS 'taosdata' SYSINFO 2; +sql_error CREATE USER u102 PASS 'taosdata' SYSINFO 20000; +sql_error ALTER USER u1 enable -1 +sql_error ALTER USER u1 enable 2 +sql_error ALTER USER u1 enable 10000 +sql_error ALTER USER u1 sysinfo -1 +sql_error ALTER USER u1 sysinfo 2 +sql_error ALTER USER u1 sysinfo -20000 +sql_error ALTER USER u1 createdb -1 +sql_error ALTER USER u1 createdb 3 +sql_error ALTER USER u1 createdb 100000 system sh/exec.sh -n dnode1 -s stop -x SIGINT \ No newline at end of file diff --git a/tests/system-test/0-others/user_control.py b/tests/system-test/0-others/user_control.py index 7dfc53ca6b..c29170e112 100644 --- a/tests/system-test/0-others/user_control.py +++ b/tests/system-test/0-others/user_control.py @@ -512,6 +512,17 @@ class TDTestCase: else: tdLog.exit("connect successfully, except error not occrued!") + def test_alter_user(self): + options = ["enable", "sysinfo", "createdb"] + optionErrVals = [-10000, -128, -1, 2, 127, 10000] + for optionErrVal in optionErrVals: + tdSql.error("create user user_alter pass 'taosdata' sysinfo %d" % optionErrVal) + tdSql.execute("create user user_alter pass 'taosdata'") + for option in options: + for optionErrVal in optionErrVals: + tdSql.error("alter user user_alter %s %d" % (option, optionErrVal)) + tdSql.execute("drop user user_alter") + def __drop_user(self, user): return f"DROP USER {user}" @@ -720,8 +731,12 @@ class TDTestCase: else: tdLog.info("taos 4 query except error occured, sysinfo == 0, can not show dnode/vgroups") + # alter 用户测试 + tdLog.printNoPrefix("==========step7: alter ordinary user") + self.test_alter_user() + # root删除用户测试 - tdLog.printNoPrefix("==========step7: super user drop normal user") + tdLog.printNoPrefix("==========step8: super user drop normal user") self.test_drop_user() tdSql.query("show users")