From 402a4c3d60bc4885aba47948484d06d95073a6d0 Mon Sep 17 00:00:00 2001 From: slzhou Date: Wed, 30 Aug 2023 15:13:43 +0800 Subject: [PATCH] enhance: add test case --- source/libs/parser/src/parAstCreater.c | 32 +++++++++++++------------- tests/parallel_test/cases.task | 1 + tests/script/tsim/user/whitelist.sim | 28 ++++++++++++++++++++++ 3 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 tests/script/tsim/user/whitelist.sim diff --git a/source/libs/parser/src/parAstCreater.c b/source/libs/parser/src/parAstCreater.c index 1eb36de093..151249a46d 100644 --- a/source/libs/parser/src/parAstCreater.c +++ b/source/libs/parser/src/parAstCreater.c @@ -1652,20 +1652,6 @@ SNode* createShowTableTagsStmt(SAstCreateContext* pCxt, SNode* pTbName, SNode* p return (SNode*)pStmt; } -SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo) { - CHECK_PARSER_STATUS(pCxt); - char password[TSDB_USET_PASSWORD_LEN + 3] = {0}; - if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) { - return NULL; - } - SCreateUserStmt* pStmt = (SCreateUserStmt*)nodesMakeNode(QUERY_NODE_CREATE_USER_STMT); - CHECK_OUT_OF_MEM(pStmt); - COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName); - strcpy(pStmt->password, password); - pStmt->sysinfo = sysinfo; - return (SNode*)pStmt; -} - static int32_t getIpV4RangeFromWhitelistItem(char* ipRange, SIpV4Range* pIpRange) { struct in_addr addr; @@ -1738,6 +1724,20 @@ SNode* addCreateUserStmtWhiteList(SAstCreateContext* pCxt, SNode* pCreateUserStm return pCreateUserStmt; } +SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword, int8_t sysinfo) { + CHECK_PARSER_STATUS(pCxt); + char password[TSDB_USET_PASSWORD_LEN + 3] = {0}; + if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) { + return NULL; + } + SCreateUserStmt* pStmt = (SCreateUserStmt*)nodesMakeNode(QUERY_NODE_CREATE_USER_STMT); + CHECK_OUT_OF_MEM(pStmt); + COPY_STRING_FORM_ID_TOKEN(pStmt->userName, pUserName); + strcpy(pStmt->password, password); + pStmt->sysinfo = sysinfo; + return (SNode*)pStmt; +} + SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t alterType, void* pAlterInfo) { CHECK_PARSER_STATUS(pCxt); if (!checkUserName(pCxt, pUserName)) { @@ -1775,13 +1775,13 @@ SNode* createAlterUserStmt(SAstCreateContext* pCxt, SToken* pUserName, int8_t al pStmt->pIpRanges = taosMemoryMalloc(pStmt->numIpRanges * sizeof(SIpV4Range)); if (NULL == pStmt->pIpRanges) { pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; - nodesDestroyNode(pStmt); + nodesDestroyNode((SNode*)pStmt); return NULL; } int32_t code = fillIpRangesFromWhiteList(pCxt, pIpRangesNodeList, pStmt->pIpRanges); if (TSDB_CODE_SUCCESS != code) { - nodesDestroyNode(pStmt); + nodesDestroyNode((SNode*)pStmt); return NULL; } break; diff --git a/tests/parallel_test/cases.task b/tests/parallel_test/cases.task index 17d24c12b6..f30c6c5314 100644 --- a/tests/parallel_test/cases.task +++ b/tests/parallel_test/cases.task @@ -808,6 +808,7 @@ ,,y,script,./test.sh -f tsim/user/basic.sim ,,y,script,./test.sh -f tsim/user/password.sim +,,y,script,./test.sh -f tsim/user/whitelist.sim ,,y,script,./test.sh -f tsim/user/privilege_db.sim ,,y,script,./test.sh -f tsim/user/privilege_sysinfo.sim ,,y,script,./test.sh -f tsim/user/privilege_topic.sim diff --git a/tests/script/tsim/user/whitelist.sim b/tests/script/tsim/user/whitelist.sim new file mode 100644 index 0000000000..53f16a90bb --- /dev/null +++ b/tests/script/tsim/user/whitelist.sim @@ -0,0 +1,28 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sql connect + +print ============= step1 +sql create user u_read pass 'taosdata1' host '127.0.0.1/24','192.168.1.0/24' +sql create user u_write pass 'taosdata1' host '127.0.0.1','192.168.1.0' + +sql alter user u_read add host '3.3.3.4/24' +sql alter user u_write drop host '4.4.4.5/25' + +sql show users +if $rows != 3 then + return -1 +endi + +print ============= step2 +sql_error create user read1 pass 'taosdata1' host '127.0.0/24' +sql_error create user write1 pass 'taosdata1' host '4.4.4.4/33' + +sql show users +if $rows != 3 then + return -1 +endi + + +system sh/exec.sh -n dnode1 -s stop -x SIGINT