未验证 提交 a1e51102 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #11944 from taosdata/feature/dnode

test: add user test cases into ci
......@@ -438,6 +438,7 @@ typedef struct {
int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
int32_t tDeserializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp);
void tFreeSGetUserAuthRsp(SGetUserAuthRsp* pRsp);
typedef struct {
int16_t colId; // column id
......
......@@ -1302,6 +1302,11 @@ int32_t tDeserializeSGetUserAuthRsp(void *buf, int32_t bufLen, SGetUserAuthRsp *
return 0;
}
void tFreeSGetUserAuthRsp(SGetUserAuthRsp *pRsp) {
taosHashCleanup(pRsp->readDbs);
taosHashCleanup(pRsp->writeDbs);
}
int32_t tSerializeSCreateDropMQSBNodeReq(void *buf, int32_t bufLen, SMCreateQnodeReq *pReq) {
SCoder encoder = {0};
tCoderInit(&encoder, TD_LITTLE_ENDIAN, buf, bufLen, TD_ENCODER);
......
......@@ -164,7 +164,6 @@ static const SInfosTableSchema userUsersSchema[] = {
{.name = "name", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "privilege", .bytes = 10 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
{.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
{.name = "account", .bytes = TSDB_USER_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR},
};
static const SInfosTableSchema grantsSchema[] = {
......
......@@ -196,7 +196,7 @@ static int32_t mndProcessConnectReq(SNodeMsg *pReq) {
goto CONN_OVER;
}
if (0 != strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1)) {
mError("user:%s, failed to auth while acquire user\n %s \r\n %s", pReq->user, connReq.passwd, pUser->pass);
mError("user:%s, failed to auth while acquire user, input:%s saved:%s", pReq->user, connReq.passwd, pUser->pass);
code = TSDB_CODE_RPC_AUTH_FAILURE;
goto CONN_OVER;
}
......
......@@ -165,8 +165,9 @@ static SSdbRow *mndUserActionDecode(SSdbRaw *pRaw) {
int32_t numOfWriteDbs = 0;
SDB_GET_INT32(pRaw, dataPos, &numOfReadDbs, _OVER)
SDB_GET_INT32(pRaw, dataPos, &numOfWriteDbs, _OVER)
pUser->readDbs = taosHashInit(numOfReadDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true);
pUser->writeDbs = taosHashInit(numOfWriteDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true);
pUser->readDbs = taosHashInit(numOfReadDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
pUser->writeDbs =
taosHashInit(numOfWriteDbs, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if (pUser->readDbs == NULL || pUser->writeDbs == NULL) goto _OVER;
for (int32_t i = 0; i < numOfReadDbs; ++i) {
......@@ -340,13 +341,13 @@ _OVER:
return code;
}
static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) {
static int32_t mndAlterUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNodeMsg *pReq) {
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_ALTER_USER, &pReq->rpcMsg);
if (pTrans == NULL) {
mError("user:%s, failed to update since %s", pOld->user, terrstr());
mError("user:%s, failed to alter since %s", pOld->user, terrstr());
return -1;
}
mDebug("trans:%d, used to update user:%s", pTrans->id, pOld->user);
mDebug("trans:%d, used to alter user:%s", pTrans->id, pOld->user);
SSdbRaw *pRedoRaw = mndUserActionEncode(pNew);
if (pRedoRaw == NULL || mndTransAppendRedolog(pTrans, pRedoRaw) != 0) {
......@@ -367,7 +368,8 @@ static int32_t mndUpdateUser(SMnode *pMnode, SUserObj *pOld, SUserObj *pNew, SNo
}
static SHashObj *mndDupDbHash(SHashObj *pOld) {
SHashObj *pNew = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, true);
SHashObj *pNew =
taosHashInit(taosHashGetSize(pOld), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
if (pNew == NULL) {
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
......@@ -378,8 +380,8 @@ static SHashObj *mndDupDbHash(SHashObj *pOld) {
int32_t len = strlen(db) + 1;
if (taosHashPut(pNew, db, len, db, TSDB_DB_FNAME_LEN) != 0) {
taosHashCancelIterate(pOld, db);
terrno = TSDB_CODE_OUT_OF_MEMORY;
taosHashCleanup(pNew);
terrno = TSDB_CODE_OUT_OF_MEMORY;
return NULL;
}
db = taosHashIterate(pOld, db);
......@@ -439,7 +441,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
char pass[TSDB_PASSWORD_LEN + 1] = {0};
taosEncryptPass_c((uint8_t *)alterReq.pass, strlen(alterReq.pass), pass);
memcpy(pUser->pass, pass, TSDB_PASSWORD_LEN);
memcpy(newUser.pass, pass, TSDB_PASSWORD_LEN);
} else if (alterReq.alterType == TSDB_ALTER_USER_SUPERUSER) {
newUser.superUser = alterReq.superUser;
} else if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB) {
......@@ -485,7 +487,7 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
goto _OVER;
}
code = mndUpdateUser(pMnode, pUser, &newUser, pReq);
code = mndAlterUser(pMnode, pUser, &newUser, pReq);
if (code == 0) code = TSDB_CODE_MND_ACTION_IN_PROGRESS;
_OVER:
......@@ -632,8 +634,7 @@ static int32_t mndProcessGetUserAuthReq(SNodeMsg *pReq) {
_OVER:
mndReleaseUser(pMnode, pUser);
taosHashCleanup(authRsp.readDbs);
taosHashCleanup(authRsp.writeDbs);
tFreeSGetUserAuthRsp(&authRsp);
return code;
}
......@@ -670,11 +671,6 @@ static int32_t mndRetrieveUsers(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pB
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
colDataAppend(pColInfo, numOfRows, (const char *)&pUser->createdTime, false);
cols++;
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
STR_WITH_MAXSIZE_TO_VARSTR(name, pUser->acct, pShow->bytes[cols]);
colDataAppend(pColInfo, numOfRows, (const char *)name, false);
numOfRows++;
sdbRelease(pSdb, pUser);
}
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/exec.sh -n dnode1 -s start
sql connect
sleep 2000
print ============= step1
sql create user read pass 'taosdata'
sql create user write pass 'taosdata'
sql show users
if $rows != 5 then
return -1
endi
print ============= step2
sql close
sql connect read
sleep 2000
sql create database dread
sql show databases
if $rows != 1 then
return -1
endi
print ============= step3
sql close
sql connect write
sleep 2000
sql create database dwrite
sql show databases
if $rows != 2 then
return -1
endi
print ============ step4
sql close
sql connect
sleep 2000
sql show databases
if $row != 2 then
return -1
endi
print ============ step5
sql close
sql connect read
sleep 2000
sql drop database dread
sql drop database dwrite
sql close
sql connect
sql show databases
if $rows != 0 then
return -1
endi
sql close
sql connect
sleep 2000
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
sql connect
print =============== step1
sql show users
if $rows != 3 then
return -1
endi
sql create user read PASS 'pass123'
sql create user read PASS 'pass123' -x step1
return -1
step1:
sql show users
if $rows != 4 then
return -1
endi
sql alter user read PASS 'taosdata'
print =============== step2
sql close
sql connect read
sleep 2000
sql alter user read PASS 'taosdata'
print =============== step3
sql drop user read -x step31
return -1
step31:
sql drop user _root -x step32
return -1
step32:
sql drop user monitor -x step33
return -1
step33:
print =============== step4
sql close
sql connect
sleep 2000
sql alter user read privilege read
sql show users
print $data1_read
if $data1_read != readable then
return -1
endi
sql_error alter user read privilege super
sql show users
print $data1_read
if $data1_read != readable then
return -1
endi
sql alter user read privilege write
sql show users
print $data1_read
if $data1_read != writable then
return -1
endi
sql alter user read privilege 1 -x step43
return -1
step43:
sql drop user _root -x step41
return -1
step41:
sql drop user monitor -x step42
return -1
step42:
sql drop user read
system sh/exec.sh -n dnode1 -s stop -x SIGINT
\ No newline at end of file
......@@ -3,6 +3,9 @@
# ---- user
./test.sh -f tsim/user/basic1.sim
./test.sh -f tsim/user/pass_alter.sim
./test.sh -f tsim/user/pass_len.sim
./test.sh -f tsim/user/user_len.sim
# ---- db
./test.sh -f tsim/db/create_all_options.sim
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect
print ============= step1
......@@ -13,7 +11,7 @@ sql alter user read pass 'taosdata'
sql alter user write pass 'taosdata'
sql show users
if $rows != 5 then
if $rows != 3 then
return -1
endi
......@@ -27,11 +25,11 @@ sql alter user write pass 'taosdata1' -x step2
return -1
step2:
sql_error create user read pass 'taosdata1'
sql_error create user write pass 'taosdata1'
sql_error create user read1 pass 'taosdata1'
sql_error create user write1 pass 'taosdata1'
sql show users
if $rows != 5 then
if $rows != 3 then
return -1
endi
......@@ -41,27 +39,27 @@ sleep 2500
print user write login
sql connect write
sql_error create user read pass 'taosdata1'
sql_error create user write pass 'taosdata1'
sql_error create user read2 pass 'taosdata1'
sql_error create user write2 pass 'taosdata1'
sql alter user write pass 'taosdata'
sql alter user read pass 'taosdata' -x step3
return -1
step3:
sql show users
if $rows != 5 then
if $rows != 3 then
return -1
endi
print ============= step4
sql close
sleep 2500
print root write login
print user root login
sql connect
sql create user oroot pass 'taosdata'
sql show users
if $rows != 6 then
if $rows != 4 then
return -1
endi
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
sql connect
......@@ -50,15 +48,16 @@ step3:
sql create user $user PASS 'abc0123456789'
sql show users
if $rows != 3 then
if $rows != 4 then
return -1
endi
print =============== step4
$i = 3
$user = $userPrefix . $i
sql create user $user PASS 'abcd012345678901234567891234567890' -x step4
sql create user $user PASS 'abcd012345678901234567891234567890abcd012345678901234567891234567890abcd012345678901234567891234567890abcd012345678901234567891234567890123' -x step4
return -1
step4:
sql show users
if $rows != 4 then
......
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c wallevel -v 0
system sh/exec.sh -n dnode1 -s start
sleep 2000
sql connect
$i = 0
......@@ -24,7 +19,7 @@ sql create user PASS '123' -x step1
step1:
sql show users
if $rows != 3 then
if $rows != 1 then
return -1
endi
......@@ -33,13 +28,13 @@ sql drop user a -x step2
step2:
sql create user a PASS '123'
sql show users
if $rows != 4 then
if $rows != 2 then
return -1
endi
sql drop user a
sql show users
if $rows != 3 then
if $rows != 1 then
return -1
endi
......@@ -49,13 +44,13 @@ step3:
sql create user abc01234567890123456789 PASS '123'
sql show users
if $rows != 4 then
if $rows != 2 then
return -1
endi
sql drop user abc01234567890123456789
sql show users
if $rows != 3 then
if $rows != 1 then
return -1
endi
......@@ -64,7 +59,7 @@ sql create user abcd0123456789012345678901234567890111 PASS '123' -x step4
return -1
step4:
sql show users
if $rows != 3 then
if $rows != 1 then
return -1
endi
......@@ -77,13 +72,13 @@ step61:
sql create user a123 PASS '123'
sql show users
if $rows != 4 then
if $rows != 2 then
return -1
endi
sql drop user a123
sql show users
if $rows != 3 then
if $rows != 1 then
return -1
endi
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册