TDengine/source/dnode/mnode/impl/test/user/user.cpp

540 lines
16 KiB
C++
Raw Normal View History

2021-12-16 09:05:13 +00:00
/**
2021-12-16 12:16:35 +00:00
* @file user.cpp
2021-12-16 09:05:13 +00:00
* @author slguan (slguan@taosdata.com)
2022-01-04 09:17:25 +00:00
* @brief MNODE module user tests
* @version 1.0
2022-01-04 12:18:09 +00:00
* @date 2022-01-04
2021-12-07 12:14:22 +00:00
*
2022-01-04 12:18:09 +00:00
* @copyright Copyright (c) 2022
2021-12-07 12:14:22 +00:00
*
*/
2022-01-04 12:36:54 +00:00
#include "sut.h"
2021-12-07 12:14:22 +00:00
2022-01-04 12:36:54 +00:00
class MndTestUser : public ::testing::Test {
2021-12-07 12:14:22 +00:00
protected:
2022-01-04 09:17:25 +00:00
static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); }
2021-12-22 10:39:32 +00:00
static void TearDownTestSuite() { test.Cleanup(); }
2021-12-07 12:14:22 +00:00
2021-12-22 10:39:32 +00:00
static Testbase test;
2021-12-07 12:14:22 +00:00
2021-12-13 10:19:09 +00:00
public:
void SetUp() override {}
void TearDown() override {}
};
2022-01-04 12:36:54 +00:00
Testbase MndTestUser::test;
2021-12-13 10:19:09 +00:00
2022-01-04 12:36:54 +00:00
TEST_F(MndTestUser, 01_Show_User) {
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
2021-12-07 12:14:22 +00:00
}
2022-01-04 12:36:54 +00:00
TEST_F(MndTestUser, 02_Create_User) {
2021-12-31 10:40:49 +00:00
{
2022-02-11 05:13:32 +00:00
SCreateUserReq createReq = {0};
strcpy(createReq.user, "");
strcpy(createReq.pass, "p1");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT);
2021-12-31 10:40:49 +00:00
}
{
2022-02-11 05:13:32 +00:00
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_PASS_FORMAT);
2021-12-31 10:40:49 +00:00
}
{
2022-02-11 05:13:32 +00:00
SCreateUserReq createReq = {0};
strcpy(createReq.user, "root");
strcpy(createReq.pass, "1");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_ALREADY_EXIST);
2021-12-31 10:40:49 +00:00
}
{
2022-02-11 05:13:32 +00:00
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "p1");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-02-11 06:09:03 +00:00
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2022-02-11 06:09:03 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
2021-12-31 10:40:49 +00:00
}
2022-02-11 06:09:03 +00:00
{
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u1");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSDropUserReq(pReq, contLen, &dropReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2022-02-11 06:09:03 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
}
{
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u2");
strcpy(createReq.pass, "p1");
createReq.superUser = 1;
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2022-02-11 06:09:03 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
}
{
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u2");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSDropUserReq(pReq, contLen, &dropReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2022-02-11 06:09:03 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
}
2021-12-31 10:40:49 +00:00
}
2022-01-04 12:36:54 +00:00
TEST_F(MndTestUser, 03_Alter_User) {
2022-02-11 06:09:03 +00:00
{
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u3");
strcpy(createReq.pass, "p1");
createReq.superUser = 1;
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2022-02-11 06:09:03 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
}
2021-12-31 10:40:49 +00:00
{
2022-02-11 05:13:32 +00:00
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "");
strcpy(alterReq.pass, "p1");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT);
2021-12-31 10:40:49 +00:00
}
{
2022-02-11 05:13:32 +00:00
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
2022-02-11 06:09:03 +00:00
strcpy(alterReq.user, "u3");
2022-02-11 05:13:32 +00:00
strcpy(alterReq.pass, "");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_PASS_FORMAT);
2021-12-31 10:40:49 +00:00
}
{
2022-02-11 05:13:32 +00:00
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "u4");
strcpy(alterReq.pass, "1");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_NOT_EXIST);
2021-12-31 10:40:49 +00:00
}
{
2022-02-11 05:13:32 +00:00
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
2022-02-11 06:09:03 +00:00
strcpy(alterReq.user, "u3");
strcpy(alterReq.pass, "1");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_SUPERUSER;
strcpy(alterReq.user, "u3");
strcpy(alterReq.pass, "1");
alterReq.superUser = 1;
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_REMOVE_ALL_DB;
2022-02-11 06:09:03 +00:00
strcpy(alterReq.user, "u3");
2022-02-11 05:13:32 +00:00
strcpy(alterReq.pass, "1");
strcpy(alterReq.dbname, "*");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-31 10:40:49 +00:00
}
2022-02-11 06:09:03 +00:00
{
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_REMOVE_ALL_DB;
2022-02-11 06:09:03 +00:00
strcpy(alterReq.user, "u3");
strcpy(alterReq.pass, "1");
strcpy(alterReq.dbname, "*");
2022-02-11 06:09:03 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_ADD_READ_DB;
strcpy(alterReq.user, "u3");
strcpy(alterReq.pass, "1");
strcpy(alterReq.dbname, "d1");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_DB_NOT_EXIST);
}
{
2022-02-12 09:14:33 +00:00
SCreateDbReq createReq = {0};
strcpy(createReq.db, "1.d2");
createReq.numOfVgroups = 2;
2022-04-25 13:12:03 +00:00
createReq.buffer = -1;
createReq.pageSize = -1;
createReq.pages = -1;
2022-04-28 07:30:23 +00:00
createReq.daysPerFile = 10 * 1440;
createReq.daysToKeep0 = 3650 * 1440;
createReq.daysToKeep1 = 3650 * 1440;
createReq.daysToKeep2 = 3650 * 1440;
2022-02-12 09:14:33 +00:00
createReq.minRows = 100;
createReq.maxRows = 4096;
createReq.fsyncPeriod = 3000;
createReq.walLevel = 1;
createReq.precision = 0;
createReq.compression = 2;
createReq.replications = 1;
2022-04-20 01:47:38 +00:00
createReq.strict = 1;
2022-02-12 09:14:33 +00:00
createReq.cacheLastRow = 0;
createReq.ignoreExist = 1;
int32_t contLen = tSerializeSCreateDbReq(NULL, 0, &createReq);
void* pReq = rpcMallocCont(contLen);
tSerializeSCreateDbReq(pReq, contLen, &createReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_DB, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_ADD_READ_DB;
strcpy(alterReq.user, "u3");
strcpy(alterReq.pass, "1");
strcpy(alterReq.dbname, "1.d2");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_ADD_READ_DB;
strcpy(alterReq.user, "u3");
strcpy(alterReq.pass, "1");
strcpy(alterReq.dbname, "1.d2");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
2022-02-11 07:20:27 +00:00
{
SGetUserAuthReq authReq = {0};
strcpy(authReq.user, "u3");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSGetUserAuthReq(NULL, 0, &authReq);
2022-02-11 07:20:27 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSGetUserAuthReq(pReq, contLen, &authReq);
2022-02-11 07:20:27 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_GET_USER_AUTH, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
SGetUserAuthRsp authRsp = {0};
2022-02-11 09:48:26 +00:00
tDeserializeSGetUserAuthRsp(pRsp->pCont, pRsp->contLen, &authRsp);
2022-02-11 07:20:27 +00:00
EXPECT_STREQ(authRsp.user, "u3");
EXPECT_EQ(authRsp.superAuth, 1);
int32_t numOfReadDbs = taosHashGetSize(authRsp.readDbs);
int32_t numOfWriteDbs = taosHashGetSize(authRsp.writeDbs);
EXPECT_EQ(numOfReadDbs, 1);
EXPECT_EQ(numOfWriteDbs, 0);
2022-05-09 12:35:59 +00:00
char* dbname = (char*)taosHashGet(authRsp.readDbs, "1.d2", 4);
EXPECT_TRUE(dbname != NULL);
2022-02-11 07:20:27 +00:00
taosHashCleanup(authRsp.readDbs);
taosHashCleanup(authRsp.writeDbs);
}
2022-02-11 06:09:03 +00:00
{
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_REMOVE_READ_DB;
strcpy(alterReq.user, "u3");
strcpy(alterReq.pass, "1");
strcpy(alterReq.dbname, "1.d2");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
{
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u3");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSDropUserReq(pReq, contLen, &dropReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2022-02-11 06:09:03 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
}
2021-12-31 10:40:49 +00:00
}
2022-02-11 06:09:03 +00:00
TEST_F(MndTestUser, 05_Drop_User) {
2021-12-31 10:40:49 +00:00
{
2022-02-11 05:13:32 +00:00
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSDropUserReq(pReq, contLen, &dropReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_INVALID_USER_FORMAT);
2021-12-31 10:40:49 +00:00
}
{
2022-02-11 05:13:32 +00:00
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u4");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSDropUserReq(pReq, contLen, &dropReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, TSDB_CODE_MND_USER_NOT_EXIST);
2021-12-31 10:40:49 +00:00
}
2022-02-11 06:09:03 +00:00
{
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "p1");
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 06:09:03 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2022-02-11 06:09:03 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
}
2021-12-31 10:40:49 +00:00
{
2022-02-11 05:13:32 +00:00
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u1");
2021-12-31 10:40:49 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSDropUserReq(pReq, contLen, &dropReq);
2021-12-31 10:40:49 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-31 10:40:49 +00:00
}
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2021-12-31 10:40:49 +00:00
EXPECT_EQ(test.GetShowRows(), 1);
}
2022-02-11 06:09:03 +00:00
TEST_F(MndTestUser, 06_Create_Drop_Alter_User) {
2021-12-13 11:02:26 +00:00
{
2022-02-11 05:13:32 +00:00
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u1");
strcpy(createReq.pass, "p1");
2021-12-22 10:39:32 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2021-12-13 11:02:26 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-13 11:02:26 +00:00
}
2021-12-07 12:14:22 +00:00
2021-12-13 11:02:26 +00:00
{
2022-02-11 05:13:32 +00:00
SCreateUserReq createReq = {0};
strcpy(createReq.user, "u2");
strcpy(createReq.pass, "p2");
2021-12-22 10:39:32 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSCreateUserReq(NULL, 0, &createReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSCreateUserReq(pReq, contLen, &createReq);
2021-12-07 12:14:22 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_CREATE_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-13 11:02:26 +00:00
}
2021-12-07 12:14:22 +00:00
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 3);
2021-12-16 06:02:39 +00:00
{
2022-02-11 05:13:32 +00:00
SAlterUserReq alterReq = {0};
alterReq.alterType = TSDB_ALTER_USER_PASSWD;
strcpy(alterReq.user, "u1");
strcpy(alterReq.pass, "p2");
2021-12-22 10:39:32 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSAlterUserReq(pReq, contLen, &alterReq);
2021-12-07 13:10:36 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_ALTER_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-16 06:02:39 +00:00
}
2021-12-22 10:39:32 +00:00
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 3);
2021-12-16 06:02:39 +00:00
{
2022-02-11 05:13:32 +00:00
SDropUserReq dropReq = {0};
strcpy(dropReq.user, "u1");
2021-12-07 12:14:22 +00:00
2022-02-11 09:48:26 +00:00
int32_t contLen = tSerializeSDropUserReq(NULL, 0, &dropReq);
2022-02-11 05:13:32 +00:00
void* pReq = rpcMallocCont(contLen);
2022-02-11 09:48:26 +00:00
tSerializeSDropUserReq(pReq, contLen, &dropReq);
2021-12-07 12:14:22 +00:00
2022-01-05 12:18:56 +00:00
SRpcMsg* pRsp = test.SendReq(TDMT_MND_DROP_USER, pReq, contLen);
ASSERT_NE(pRsp, nullptr);
ASSERT_EQ(pRsp->code, 0);
2021-12-16 06:02:39 +00:00
}
2021-12-22 10:39:32 +00:00
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
2021-12-16 06:02:39 +00:00
// restart
2021-12-22 10:39:32 +00:00
test.Restart();
2021-12-13 11:02:26 +00:00
2022-02-20 16:11:35 +00:00
taosMsleep(1000);
2022-04-15 05:31:08 +00:00
test.SendShowReq(TSDB_MGMT_TABLE_USER, "user_users", "");
2021-12-22 10:39:32 +00:00
EXPECT_EQ(test.GetShowRows(), 2);
2022-02-20 16:11:35 +00:00
}