unitest for create user
This commit is contained in:
parent
65acb7dfe2
commit
97df31ebad
|
@ -354,9 +354,9 @@ typedef struct SEpSet {
|
|||
} SEpSet;
|
||||
|
||||
static FORCE_INLINE int taosEncodeSEpSet(void** buf, const SEpSet* pEp) {
|
||||
if(buf == NULL) return sizeof(SEpSet);
|
||||
if (buf == NULL) return sizeof(SEpSet);
|
||||
memcpy(buf, pEp, sizeof(SEpSet));
|
||||
//TODO: endian conversion
|
||||
// TODO: endian conversion
|
||||
return sizeof(SEpSet);
|
||||
}
|
||||
|
||||
|
@ -370,7 +370,7 @@ typedef struct {
|
|||
int64_t clusterId;
|
||||
int32_t connId;
|
||||
int8_t superUser;
|
||||
int8_t reserved[5];
|
||||
int8_t align[3];
|
||||
SEpSet epSet;
|
||||
} SConnectRsp;
|
||||
|
||||
|
@ -383,20 +383,17 @@ typedef struct {
|
|||
int32_t maxStreams;
|
||||
int32_t accessState; // Configured only by command
|
||||
int64_t maxStorage; // In unit of GB
|
||||
int32_t reserve[8];
|
||||
} SCreateAcctMsg, SAlterAcctMsg;
|
||||
|
||||
typedef struct {
|
||||
char user[TSDB_USER_LEN];
|
||||
int32_t reserve[8];
|
||||
char user[TSDB_USER_LEN];
|
||||
} SDropUserMsg, SDropAcctMsg;
|
||||
|
||||
typedef struct {
|
||||
int8_t type;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
int8_t superUser; // denote if it is a super user or not
|
||||
int32_t reserve[8];
|
||||
int8_t type;
|
||||
char user[TSDB_USER_LEN];
|
||||
char pass[TSDB_PASSWORD_LEN];
|
||||
int8_t superUser; // denote if it is a super user or not
|
||||
} SCreateUserMsg, SAlterUserMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -585,7 +582,6 @@ typedef struct {
|
|||
int8_t update;
|
||||
int8_t cacheLastRow;
|
||||
int8_t ignoreExist;
|
||||
int32_t reserve[8];
|
||||
} SCreateDbMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -598,29 +594,24 @@ typedef struct {
|
|||
int8_t walLevel;
|
||||
int8_t quorum;
|
||||
int8_t cacheLastRow;
|
||||
int32_t reserve[8];
|
||||
} SAlterDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t ignoreNotExists;
|
||||
int32_t reserve[8];
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t ignoreNotExists;
|
||||
} SDropDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t vgVersion;
|
||||
int32_t reserve[8];
|
||||
} SUseDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t reserve[8];
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
} SSyncDbMsg;
|
||||
|
||||
typedef struct {
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
int32_t reserve[8];
|
||||
char db[TSDB_TABLE_FNAME_LEN];
|
||||
} SCompactDbMsg;
|
||||
|
||||
typedef struct {
|
||||
|
@ -676,7 +667,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t vgId;
|
||||
int8_t role;
|
||||
int8_t reserved[3];
|
||||
int8_t align[3];
|
||||
int64_t totalStorage;
|
||||
int64_t compStorage;
|
||||
int64_t pointsWritten;
|
||||
|
@ -713,7 +704,7 @@ typedef struct {
|
|||
typedef struct {
|
||||
int32_t id;
|
||||
int8_t isMnode;
|
||||
int8_t reserved;
|
||||
int8_t align;
|
||||
uint16_t port;
|
||||
char fqdn[TSDB_FQDN_LEN];
|
||||
} SDnodeEp;
|
||||
|
@ -947,7 +938,7 @@ typedef struct {
|
|||
int32_t totalDnodes;
|
||||
int32_t onlineDnodes;
|
||||
int8_t killConnection;
|
||||
int8_t reserved[3];
|
||||
int8_t align[3];
|
||||
SEpSet epSet;
|
||||
} SHeartBeatRsp;
|
||||
|
||||
|
@ -975,7 +966,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int8_t finished;
|
||||
int8_t reserved1[7];
|
||||
int8_t align[7];
|
||||
char name[TSDB_STEP_NAME_LEN];
|
||||
char desc[TSDB_STEP_DESC_LEN];
|
||||
} SStartupMsg;
|
||||
|
@ -1118,10 +1109,10 @@ typedef struct STaskDropRsp {
|
|||
} STaskDropRsp;
|
||||
|
||||
typedef struct {
|
||||
int8_t igExists;
|
||||
char* name;
|
||||
char* physicalPlan;
|
||||
char* logicalPlan;
|
||||
int8_t igExists;
|
||||
char* name;
|
||||
char* physicalPlan;
|
||||
char* logicalPlan;
|
||||
} SCMCreateTopicReq;
|
||||
|
||||
static FORCE_INLINE int tSerializeSCMCreateTopicReq(void** buf, const SCMCreateTopicReq* pReq) {
|
||||
|
@ -1157,8 +1148,8 @@ static FORCE_INLINE void* tDeserializeSCMCreateTopicRsp(void* buf, SCMCreateTopi
|
|||
}
|
||||
|
||||
typedef struct {
|
||||
char* topicName;
|
||||
char* consumerGroup;
|
||||
char* topicName;
|
||||
char* consumerGroup;
|
||||
int64_t consumerId;
|
||||
} SCMSubscribeReq;
|
||||
|
||||
|
@ -1179,7 +1170,7 @@ static FORCE_INLINE void* tDeserializeSCMSubscribeReq(void* buf, SCMSubscribeReq
|
|||
|
||||
typedef struct {
|
||||
int32_t vgId;
|
||||
SEpSet pEpSet;
|
||||
SEpSet pEpSet;
|
||||
} SCMSubscribeRsp;
|
||||
|
||||
static FORCE_INLINE int tSerializeSCMSubscribeRsp(void** buf, const SCMSubscribeRsp* pRsp) {
|
||||
|
|
|
@ -160,8 +160,8 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
|||
|
||||
DndMsgFp fp = pMgmt->msgFp[TMSG_INDEX(msgType)];
|
||||
if (fp != NULL) {
|
||||
dTrace("RPC %p, rsp:%s will be processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF);
|
||||
(*fp)(pDnode, pMsg, pEpSet);
|
||||
dTrace("RPC %p, rsp:%s is processed, code:0x%x", pMsg->handle, TMSG_INFO(msgType), pMsg->code & 0XFFFF);
|
||||
} else {
|
||||
dError("RPC %p, rsp:%s not processed", pMsg->handle, TMSG_INFO(msgType));
|
||||
rpcFreeCont(pMsg->pCont);
|
||||
|
|
|
@ -43,6 +43,153 @@ TEST_F(DndTestUser, 01_ShowUser) {
|
|||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 02_Create_User) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "");
|
||||
strcpy(pReq->pass, "p1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "root");
|
||||
strcpy(pReq->pass, "1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_ALREADY_EXIST);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
||||
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "p1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 2);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 03_Alter_User) {
|
||||
{
|
||||
int32_t contLen = sizeof(SAlterUserMsg);
|
||||
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "");
|
||||
strcpy(pReq->pass, "p1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SAlterUserMsg);
|
||||
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_PASS_FORMAT);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SAlterUserMsg);
|
||||
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u4");
|
||||
strcpy(pReq->pass, "1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SAlterUserMsg);
|
||||
|
||||
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
strcpy(pReq->pass, "1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_ALTER_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 04_Drop_User) {
|
||||
{
|
||||
int32_t contLen = sizeof(SDropUserMsg);
|
||||
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_INVALID_USER_FORMAT);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropUserMsg);
|
||||
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u4");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, TSDB_CODE_MND_USER_NOT_EXIST);
|
||||
}
|
||||
|
||||
{
|
||||
int32_t contLen = sizeof(SDropUserMsg);
|
||||
|
||||
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(contLen);
|
||||
strcpy(pReq->user, "u1");
|
||||
|
||||
SRpcMsg* pMsg = test.SendMsg(TDMT_MND_DROP_USER, pReq, contLen);
|
||||
ASSERT_NE(pMsg, nullptr);
|
||||
ASSERT_EQ(pMsg->code, 0);
|
||||
}
|
||||
|
||||
test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, "");
|
||||
CHECK_META("show users", 4);
|
||||
|
||||
test.SendShowRetrieveMsg();
|
||||
EXPECT_EQ(test.GetShowRows(), 1);
|
||||
}
|
||||
|
||||
TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
||||
{
|
||||
int32_t contLen = sizeof(SCreateUserMsg);
|
||||
|
@ -161,4 +308,4 @@ TEST_F(DndTestUser, 02_Create_Drop_Alter_User) {
|
|||
CheckTimestamp();
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
CheckBinary("root", TSDB_USER_LEN);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue