|
|
|
@ -17,43 +17,40 @@
|
|
|
|
|
|
|
|
|
|
class DndTestUser : public ::testing::Test {
|
|
|
|
|
protected:
|
|
|
|
|
void SetUp() override {}
|
|
|
|
|
void TearDown() override {}
|
|
|
|
|
static SServer* CreateServer(const char* path, const char* fqdn, uint16_t port, const char* firstEp) {
|
|
|
|
|
SServer* pServer = createServer(path, fqdn, port, firstEp);
|
|
|
|
|
ASSERT(pServer);
|
|
|
|
|
return pServer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void SetUpTestSuite() {
|
|
|
|
|
const char* user = "root";
|
|
|
|
|
const char* pass = "taosdata";
|
|
|
|
|
const char* path = "/tmp/dndTestUser";
|
|
|
|
|
const char* fqdn = "localhost";
|
|
|
|
|
uint16_t port = 9524;
|
|
|
|
|
const char* firstEp = "localhost:9524";
|
|
|
|
|
initLog("/tmp/dndTestUser");
|
|
|
|
|
|
|
|
|
|
pServer = createServer(path, fqdn, port, firstEp);
|
|
|
|
|
ASSERT(pServer);
|
|
|
|
|
pClient = createClient(user, pass, fqdn, port);
|
|
|
|
|
const char* fqdn = "localhost";
|
|
|
|
|
const char* firstEp = "localhost:9530";
|
|
|
|
|
pServer = CreateServer("/tmp/dndTestUser", fqdn, 9530, firstEp);
|
|
|
|
|
pClient = createClient("root", "taosdata", fqdn, 9530);
|
|
|
|
|
taosMsleep(300);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void TearDownTestSuite() {
|
|
|
|
|
stopServer(pServer);
|
|
|
|
|
dropClient(pClient);
|
|
|
|
|
pServer = NULL;
|
|
|
|
|
pClient = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SServer* pServer;
|
|
|
|
|
static SClient* pClient;
|
|
|
|
|
static int32_t connId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SServer* DndTestUser::pServer;
|
|
|
|
|
SClient* DndTestUser::pClient;
|
|
|
|
|
int32_t DndTestUser::connId;
|
|
|
|
|
public:
|
|
|
|
|
void SetUp() override {}
|
|
|
|
|
void TearDown() override {}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
TEST_F(DndTestUser, ShowUser) {
|
|
|
|
|
int32_t showId = 0;
|
|
|
|
|
|
|
|
|
|
//--- meta ---
|
|
|
|
|
void SendTheCheckShowMetaMsg(int8_t showType, const char* showName, int32_t columns) {
|
|
|
|
|
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
|
|
|
|
pShow->type = TSDB_MGMT_TABLE_USER;
|
|
|
|
|
pShow->type = showType;
|
|
|
|
|
strcpy(pShow->db, "");
|
|
|
|
|
|
|
|
|
|
SRpcMsg showRpcMsg = {0};
|
|
|
|
@ -63,66 +60,45 @@ TEST_F(DndTestUser, ShowUser) {
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &showRpcMsg);
|
|
|
|
|
ASSERT_NE(pClient->pRsp, nullptr);
|
|
|
|
|
ASSERT_EQ(pClient->pRsp->code, 0);
|
|
|
|
|
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
|
|
|
|
|
|
|
|
|
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
|
|
|
|
ASSERT_NE(pShowRsp, nullptr);
|
|
|
|
|
pShowRsp->showId = htonl(pShowRsp->showId);
|
|
|
|
|
STableMetaMsg* pMeta = &pShowRsp->tableMeta;
|
|
|
|
|
pMeta->contLen = htonl(pMeta->contLen);
|
|
|
|
|
pMeta = &pShowRsp->tableMeta;
|
|
|
|
|
pMeta->numOfTags = htons(pMeta->numOfTags);
|
|
|
|
|
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
|
|
|
|
pMeta->sversion = htons(pMeta->sversion);
|
|
|
|
|
pMeta->tversion = htons(pMeta->tversion);
|
|
|
|
|
pMeta->tid = htonl(pMeta->tid);
|
|
|
|
|
pMeta->uid = htobe64(pMeta->uid);
|
|
|
|
|
pMeta->tuid = htobe64(pMeta->tuid);
|
|
|
|
|
pMeta->suid = htobe64(pMeta->suid);
|
|
|
|
|
|
|
|
|
|
showId = pShowRsp->showId;
|
|
|
|
|
|
|
|
|
|
EXPECT_NE(pShowRsp->showId, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->contLen, 0);
|
|
|
|
|
EXPECT_STREQ(pMeta->tbFname, "show users");
|
|
|
|
|
EXPECT_STREQ(pMeta->tbFname, showName);
|
|
|
|
|
EXPECT_EQ(pMeta->numOfTags, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->numOfColumns, columns);
|
|
|
|
|
EXPECT_EQ(pMeta->precision, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->tableType, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->numOfColumns, 4);
|
|
|
|
|
EXPECT_EQ(pMeta->update, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->sversion, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->tversion, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->tid, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->uid, 0);
|
|
|
|
|
EXPECT_STREQ(pMeta->sTableName, "");
|
|
|
|
|
EXPECT_EQ(pMeta->tuid, 0);
|
|
|
|
|
EXPECT_EQ(pMeta->suid, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SSchema* pSchema = NULL;
|
|
|
|
|
|
|
|
|
|
pSchema = &pMeta->pSchema[0];
|
|
|
|
|
void CheckSchema(int32_t index, int8_t type, int32_t bytes, const char* name) {
|
|
|
|
|
SSchema* pSchema = &pMeta->pSchema[index];
|
|
|
|
|
pSchema->bytes = htons(pSchema->bytes);
|
|
|
|
|
EXPECT_EQ(pSchema->colId, 0);
|
|
|
|
|
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
|
|
|
|
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
|
|
|
|
EXPECT_STREQ(pSchema->name, "name");
|
|
|
|
|
EXPECT_EQ(pSchema->type, type);
|
|
|
|
|
EXPECT_EQ(pSchema->bytes, bytes);
|
|
|
|
|
EXPECT_STREQ(pSchema->name, name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pSchema = &pMeta->pSchema[1];
|
|
|
|
|
pSchema->bytes = htons(pSchema->bytes);
|
|
|
|
|
EXPECT_EQ(pSchema->colId, 0);
|
|
|
|
|
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
|
|
|
|
EXPECT_EQ(pSchema->bytes, 10 + VARSTR_HEADER_SIZE);
|
|
|
|
|
EXPECT_STREQ(pSchema->name, "privilege");
|
|
|
|
|
|
|
|
|
|
pSchema = &pMeta->pSchema[2];
|
|
|
|
|
pSchema->bytes = htons(pSchema->bytes);
|
|
|
|
|
EXPECT_EQ(pSchema->colId, 0);
|
|
|
|
|
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_TIMESTAMP);
|
|
|
|
|
EXPECT_EQ(pSchema->bytes, 8);
|
|
|
|
|
EXPECT_STREQ(pSchema->name, "create_time");
|
|
|
|
|
|
|
|
|
|
pSchema = &pMeta->pSchema[3];
|
|
|
|
|
pSchema->bytes = htons(pSchema->bytes);
|
|
|
|
|
EXPECT_EQ(pSchema->colId, 0);
|
|
|
|
|
EXPECT_EQ(pSchema->type, TSDB_DATA_TYPE_BINARY);
|
|
|
|
|
EXPECT_EQ(pSchema->bytes, TSDB_USER_LEN + VARSTR_HEADER_SIZE);
|
|
|
|
|
EXPECT_STREQ(pSchema->name, "account");
|
|
|
|
|
|
|
|
|
|
//--- retrieve ---
|
|
|
|
|
void SendThenCheckShowRetrieveMsg(int32_t rows) {
|
|
|
|
|
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
|
|
|
|
pRetrieve->showId = htonl(showId);
|
|
|
|
|
pRetrieve->free = 0;
|
|
|
|
@ -133,86 +109,83 @@ TEST_F(DndTestUser, ShowUser) {
|
|
|
|
|
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &retrieveRpcMsg);
|
|
|
|
|
|
|
|
|
|
ASSERT_NE(pClient->pRsp, nullptr);
|
|
|
|
|
ASSERT_EQ(pClient->pRsp->code, 0);
|
|
|
|
|
ASSERT_NE(pClient->pRsp->pCont, nullptr);
|
|
|
|
|
|
|
|
|
|
SRetrieveTableRsp* pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
|
|
|
|
pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
|
|
|
|
ASSERT_NE(pRetrieveRsp, nullptr);
|
|
|
|
|
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
|
|
|
|
pRetrieveRsp->offset = htobe64(pRetrieveRsp->offset);
|
|
|
|
|
pRetrieveRsp->useconds = htobe64(pRetrieveRsp->useconds);
|
|
|
|
|
pRetrieveRsp->compLen = htonl(pRetrieveRsp->compLen);
|
|
|
|
|
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->numOfRows, 2);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->numOfRows, rows);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->offset, 0);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->useconds, 0);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->completed, 1);
|
|
|
|
|
// EXPECT_EQ(pRetrieveRsp->completed, completed);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->precision, TSDB_TIME_PRECISION_MILLI);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->compressed, 0);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->reserved, 0);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->compLen, 0);
|
|
|
|
|
|
|
|
|
|
char* pData = pRetrieveRsp->data;
|
|
|
|
|
int32_t pos = 0;
|
|
|
|
|
char* strVal = NULL;
|
|
|
|
|
int64_t int64Val = 0;
|
|
|
|
|
|
|
|
|
|
//--- name ---
|
|
|
|
|
{
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "root");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "_root");
|
|
|
|
|
pData = pRetrieveRsp->data;
|
|
|
|
|
pos = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--- privilege ---
|
|
|
|
|
{
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += 10;
|
|
|
|
|
EXPECT_STREQ(strVal, "super");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += 10;
|
|
|
|
|
EXPECT_STREQ(strVal, "writable");
|
|
|
|
|
void CheckInt16(int16_t val) {
|
|
|
|
|
int16_t data = *((int16_t*)(pData + pos));
|
|
|
|
|
pos += sizeof(int16_t);
|
|
|
|
|
EXPECT_EQ(data, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--- create_time ---
|
|
|
|
|
{
|
|
|
|
|
int64Val = *((int64_t*)(pData + pos));
|
|
|
|
|
void CheckInt64(int64_t val) {
|
|
|
|
|
int64_t data = *((int64_t*)(pData + pos));
|
|
|
|
|
pos += sizeof(int64_t);
|
|
|
|
|
EXPECT_GT(int64Val, 0);
|
|
|
|
|
EXPECT_EQ(data, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64Val = *((int64_t*)(pData + pos));
|
|
|
|
|
void CheckTimestamp() {
|
|
|
|
|
int64_t data = *((int64_t*)(pData + pos));
|
|
|
|
|
pos += sizeof(int64_t);
|
|
|
|
|
EXPECT_GT(int64Val, 0);
|
|
|
|
|
EXPECT_GT(data, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--- account ---
|
|
|
|
|
{
|
|
|
|
|
void CheckBinary(const char* val, int32_t len) {
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "root");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "root");
|
|
|
|
|
char* data = (char*)(pData + pos);
|
|
|
|
|
pos += len;
|
|
|
|
|
EXPECT_STREQ(data, val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int32_t showId;
|
|
|
|
|
STableMetaMsg* pMeta;
|
|
|
|
|
SRetrieveTableRsp* pRetrieveRsp;
|
|
|
|
|
char* pData;
|
|
|
|
|
int32_t pos;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
SServer* DndTestUser::pServer;
|
|
|
|
|
SClient* DndTestUser::pClient;
|
|
|
|
|
int32_t DndTestUser::connId;
|
|
|
|
|
|
|
|
|
|
TEST_F(DndTestUser, ShowUser) {
|
|
|
|
|
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
|
|
|
CheckSchema(0, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "name");
|
|
|
|
|
CheckSchema(1, TSDB_DATA_TYPE_BINARY, 10 + VARSTR_HEADER_SIZE, "privilege");
|
|
|
|
|
CheckSchema(2, TSDB_DATA_TYPE_TIMESTAMP, 8, "create time");
|
|
|
|
|
CheckSchema(3, TSDB_DATA_TYPE_BINARY, TSDB_USER_LEN + VARSTR_HEADER_SIZE, "account");
|
|
|
|
|
|
|
|
|
|
SendThenCheckShowRetrieveMsg(1);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("super", 10);
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
TEST_F(DndTestUser, CreateUser_01) {
|
|
|
|
|
ASSERT_NE(pClient, nullptr);
|
|
|
|
|
|
|
|
|
|
//--- create user ---
|
|
|
|
|
{
|
|
|
|
|
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
|
|
|
|
strcpy(pReq->user, "u1");
|
|
|
|
|
strcpy(pReq->pass, "p1");
|
|
|
|
@ -226,61 +199,41 @@ TEST_F(DndTestUser, CreateUser_01) {
|
|
|
|
|
SRpcMsg* pMsg = pClient->pRsp;
|
|
|
|
|
ASSERT_NE(pMsg, nullptr);
|
|
|
|
|
ASSERT_EQ(pMsg->code, 0);
|
|
|
|
|
|
|
|
|
|
//--- meta ---
|
|
|
|
|
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
|
|
|
|
pShow->type = TSDB_MGMT_TABLE_USER;
|
|
|
|
|
SRpcMsg showRpcMsg = {0};
|
|
|
|
|
showRpcMsg.pCont = pShow;
|
|
|
|
|
showRpcMsg.contLen = sizeof(SShowMsg);
|
|
|
|
|
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &showRpcMsg);
|
|
|
|
|
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
|
|
|
|
STableMetaMsg* pMeta = &pShowRsp->tableMeta;
|
|
|
|
|
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
|
|
|
|
EXPECT_EQ(pMeta->numOfColumns, 4);
|
|
|
|
|
|
|
|
|
|
//--- retrieve ---
|
|
|
|
|
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
|
|
|
|
pRetrieve->showId = pShowRsp->showId;
|
|
|
|
|
SRpcMsg retrieveRpcMsg = {0};
|
|
|
|
|
retrieveRpcMsg.pCont = pRetrieve;
|
|
|
|
|
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
|
|
|
|
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &retrieveRpcMsg);
|
|
|
|
|
SRetrieveTableRsp* pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
|
|
|
|
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->numOfRows, 3);
|
|
|
|
|
|
|
|
|
|
char* pData = pRetrieveRsp->data;
|
|
|
|
|
int32_t pos = 0;
|
|
|
|
|
char* strVal = NULL;
|
|
|
|
|
|
|
|
|
|
//--- name ---
|
|
|
|
|
{
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "u1");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "root");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "_root");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(sizeof(SCreateUserMsg));
|
|
|
|
|
strcpy(pReq->user, "u2");
|
|
|
|
|
strcpy(pReq->pass, "p2");
|
|
|
|
|
|
|
|
|
|
SRpcMsg rpcMsg = {0};
|
|
|
|
|
rpcMsg.pCont = pReq;
|
|
|
|
|
rpcMsg.contLen = sizeof(SCreateUserMsg);
|
|
|
|
|
rpcMsg.msgType = TSDB_MSG_TYPE_CREATE_USER;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &rpcMsg);
|
|
|
|
|
SRpcMsg* pMsg = pClient->pRsp;
|
|
|
|
|
ASSERT_NE(pMsg, nullptr);
|
|
|
|
|
ASSERT_EQ(pMsg->code, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
|
|
|
SendThenCheckShowRetrieveMsg(3);
|
|
|
|
|
CheckBinary("u1", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("u2", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("normal", 10);
|
|
|
|
|
CheckBinary("super", 10);
|
|
|
|
|
CheckBinary("normal", 10);
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DndTestUser, AlterUser_01) {
|
|
|
|
|
ASSERT_NE(pClient, nullptr);
|
|
|
|
|
|
|
|
|
|
//--- drop user ---
|
|
|
|
|
SAlterUserMsg* pReq = (SAlterUserMsg*)rpcMallocCont(sizeof(SAlterUserMsg));
|
|
|
|
|
strcpy(pReq->user, "u1");
|
|
|
|
|
strcpy(pReq->pass, "p2");
|
|
|
|
@ -295,60 +248,23 @@ TEST_F(DndTestUser, AlterUser_01) {
|
|
|
|
|
ASSERT_NE(pMsg, nullptr);
|
|
|
|
|
ASSERT_EQ(pMsg->code, 0);
|
|
|
|
|
|
|
|
|
|
//--- meta ---
|
|
|
|
|
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
|
|
|
|
pShow->type = TSDB_MGMT_TABLE_USER;
|
|
|
|
|
SRpcMsg showRpcMsg = {0};
|
|
|
|
|
showRpcMsg.pCont = pShow;
|
|
|
|
|
showRpcMsg.contLen = sizeof(SShowMsg);
|
|
|
|
|
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &showRpcMsg);
|
|
|
|
|
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
|
|
|
|
STableMetaMsg* pMeta = &pShowRsp->tableMeta;
|
|
|
|
|
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
|
|
|
|
EXPECT_EQ(pMeta->numOfColumns, 4);
|
|
|
|
|
|
|
|
|
|
//--- retrieve ---
|
|
|
|
|
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
|
|
|
|
pRetrieve->showId = pShowRsp->showId;
|
|
|
|
|
SRpcMsg retrieveRpcMsg = {0};
|
|
|
|
|
retrieveRpcMsg.pCont = pRetrieve;
|
|
|
|
|
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
|
|
|
|
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &retrieveRpcMsg);
|
|
|
|
|
SRetrieveTableRsp* pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
|
|
|
|
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->numOfRows, 3);
|
|
|
|
|
|
|
|
|
|
char* pData = pRetrieveRsp->data;
|
|
|
|
|
int32_t pos = 0;
|
|
|
|
|
char* strVal = NULL;
|
|
|
|
|
|
|
|
|
|
//--- name ---
|
|
|
|
|
{
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "u1");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "root");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "_root");
|
|
|
|
|
}
|
|
|
|
|
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
|
|
|
SendThenCheckShowRetrieveMsg(3);
|
|
|
|
|
CheckBinary("u1", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("u2", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("normal", 10);
|
|
|
|
|
CheckBinary("super", 10);
|
|
|
|
|
CheckBinary("normal", 10);
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DndTestUser, DropUser_01) {
|
|
|
|
|
ASSERT_NE(pClient, nullptr);
|
|
|
|
|
|
|
|
|
|
//--- drop user ---
|
|
|
|
|
SDropUserMsg* pReq = (SDropUserMsg*)rpcMallocCont(sizeof(SDropUserMsg));
|
|
|
|
|
strcpy(pReq->user, "u1");
|
|
|
|
|
|
|
|
|
@ -362,47 +278,38 @@ TEST_F(DndTestUser, DropUser_01) {
|
|
|
|
|
ASSERT_NE(pMsg, nullptr);
|
|
|
|
|
ASSERT_EQ(pMsg->code, 0);
|
|
|
|
|
|
|
|
|
|
//--- meta ---
|
|
|
|
|
SShowMsg* pShow = (SShowMsg*)rpcMallocCont(sizeof(SShowMsg));
|
|
|
|
|
pShow->type = TSDB_MGMT_TABLE_USER;
|
|
|
|
|
SRpcMsg showRpcMsg = {0};
|
|
|
|
|
showRpcMsg.pCont = pShow;
|
|
|
|
|
showRpcMsg.contLen = sizeof(SShowMsg);
|
|
|
|
|
showRpcMsg.msgType = TSDB_MSG_TYPE_SHOW;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &showRpcMsg);
|
|
|
|
|
SShowRsp* pShowRsp = (SShowRsp*)pClient->pRsp->pCont;
|
|
|
|
|
STableMetaMsg* pMeta = &pShowRsp->tableMeta;
|
|
|
|
|
pMeta->numOfColumns = htons(pMeta->numOfColumns);
|
|
|
|
|
EXPECT_EQ(pMeta->numOfColumns, 4);
|
|
|
|
|
|
|
|
|
|
//--- retrieve ---
|
|
|
|
|
SRetrieveTableMsg* pRetrieve = (SRetrieveTableMsg*)rpcMallocCont(sizeof(SRetrieveTableMsg));
|
|
|
|
|
pRetrieve->showId = pShowRsp->showId;
|
|
|
|
|
SRpcMsg retrieveRpcMsg = {0};
|
|
|
|
|
retrieveRpcMsg.pCont = pRetrieve;
|
|
|
|
|
retrieveRpcMsg.contLen = sizeof(SRetrieveTableMsg);
|
|
|
|
|
retrieveRpcMsg.msgType = TSDB_MSG_TYPE_SHOW_RETRIEVE;
|
|
|
|
|
|
|
|
|
|
sendMsg(pClient, &retrieveRpcMsg);
|
|
|
|
|
SRetrieveTableRsp* pRetrieveRsp = (SRetrieveTableRsp*)pClient->pRsp->pCont;
|
|
|
|
|
pRetrieveRsp->numOfRows = htonl(pRetrieveRsp->numOfRows);
|
|
|
|
|
EXPECT_EQ(pRetrieveRsp->numOfRows, 2);
|
|
|
|
|
|
|
|
|
|
char* pData = pRetrieveRsp->data;
|
|
|
|
|
int32_t pos = 0;
|
|
|
|
|
char* strVal = NULL;
|
|
|
|
|
|
|
|
|
|
//--- name ---
|
|
|
|
|
{
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "root");
|
|
|
|
|
|
|
|
|
|
pos += sizeof(VarDataLenT);
|
|
|
|
|
strVal = (char*)(pData + pos);
|
|
|
|
|
pos += TSDB_USER_LEN;
|
|
|
|
|
EXPECT_STREQ(strVal, "_root");
|
|
|
|
|
}
|
|
|
|
|
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
|
|
|
SendThenCheckShowRetrieveMsg(2);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("u2", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("super", 10);
|
|
|
|
|
CheckBinary("normal", 10);
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(DndTestUser, RestartDnode) {
|
|
|
|
|
stopServer(pServer);
|
|
|
|
|
pServer = NULL;
|
|
|
|
|
|
|
|
|
|
uInfo("start all server");
|
|
|
|
|
|
|
|
|
|
const char* fqdn = "localhost";
|
|
|
|
|
const char* firstEp = "localhost:9530";
|
|
|
|
|
pServer = startServer("/tmp/dndTestUser", fqdn, 9530, firstEp);
|
|
|
|
|
|
|
|
|
|
uInfo("all server is running");
|
|
|
|
|
|
|
|
|
|
SendTheCheckShowMetaMsg(TSDB_MGMT_TABLE_USER, "show users", 4);
|
|
|
|
|
SendThenCheckShowRetrieveMsg(2);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("u2", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("super", 10);
|
|
|
|
|
CheckBinary("normal", 10);
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckTimestamp();
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
CheckBinary("root", TSDB_USER_LEN);
|
|
|
|
|
}
|