diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index a2124ae27128f8252eb9e7dc5350e57997f2b544..1ad9e4cde4ad6e8e20d48f313ef057755a4e1e97 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -85,6 +85,7 @@ enum { DM_AUTH_NOT_AUTH, DM_AUTH_DONT_AUTH, DM_AUTH_NOT_START, + DM_MESSAGE_NOT_COMPLETE, DM_SOFTBUS_FAILED = 3000, DM_SOFTBUS_CREATE_SESSION_SERVER_FAILED, DM_HICHAIN_FAILED = 4000, diff --git a/services/devicemanagerservice/include/authentication/auth_message_processor.h b/services/devicemanagerservice/include/authentication/auth_message_processor.h index ec545b81c2dc8a7d9a9eeaa0fb71b573a7badaf9..2802690493974369eb366888d8e7b78640f76abf 100644 --- a/services/devicemanagerservice/include/authentication/auth_message_processor.h +++ b/services/devicemanagerservice/include/authentication/auth_message_processor.h @@ -47,7 +47,7 @@ private: void CreateSyncGroupMessage(nlohmann::json &json); void CreateResponseAuthMessage(nlohmann::json &json); void ParseAuthResponseMessage(nlohmann::json &json); - int32_t ParseAuthRequestMessage(); + int32_t ParseAuthRequestMessage(nlohmann::json &json); void ParseNegotiateMessage(const nlohmann::json &json); void CreateResponseFinishMessage(nlohmann::json &json); void ParseResponseFinishMessage(nlohmann::json &json); diff --git a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp index 486aa989e6c62a87af01be034263cd8d0e3bb92d..b8f538e81b4c7e2dca2786ae2940afdf32f217b4 100644 --- a/services/devicemanagerservice/src/authentication/auth_message_processor.cpp +++ b/services/devicemanagerservice/src/authentication/auth_message_processor.cpp @@ -164,33 +164,15 @@ int32_t AuthMessageProcessor::ParseMessage(const std::string &message) LOGE("err json string, first time"); return DM_FAILED; } - int32_t sliceNum = 0; int32_t msgType = jsonObject[TAG_TYPE]; authResponseContext_->msgType = msgType; - LOGI("AuthMessageProcessor::ParseAuthRequestMessage======== %d", authResponseContext_->msgType); + LOGI("AuthMessageProcessor::ParseMessage message type %d", authResponseContext_->msgType); switch (msgType) { case MSG_TYPE_NEGOTIATE: ParseNegotiateMessage(jsonObject); break; case MSG_TYPE_REQ_AUTH: - if (!jsonObject.contains(TAG_INDEX) || !jsonObject.contains(TAG_DEVICE_ID) || - !jsonObject.contains(TAG_SLICE_NUM)) { - LOGE("err json string, first time"); - return DM_FAILED; - } - authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID]; - authResponseContext_->authType = jsonObject[TAG_AUTH_TYPE]; - authResponseContext_->appDesc = jsonObject[TAG_APP_DESCRIPTION]; - authResponseContext_->token = jsonObject[TAG_TOKEN]; - authResponseContext_->targetPkgName = jsonObject[TAG_TARGET]; - authResponseContext_->appName = jsonObject[TAG_APP_NAME]; - LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str()); - sliceNum = jsonObject[TAG_SLICE_NUM]; - if ((int32_t)authSplitJsonList_.size() < sliceNum) { - authSplitJsonList_.push_back(message); - } else { - ParseAuthRequestMessage(); - } + return ParseAuthRequestMessage(jsonObject); break; case MSG_TYPE_RESP_AUTH: ParseAuthResponseMessage(jsonObject); @@ -209,6 +191,37 @@ void AuthMessageProcessor::ParseResponseFinishMessage(nlohmann::json &json) authResponseContext_->reply = json[TAG_REPLY]; } +int32_t AuthMessageProcessor::ParseAuthRequestMessage(nlohmann::json &json) +{ + LOGE("start ParseAuthRequestMessage"); + int32_t sliceNum = 0; + int32_t idx = 0; + if (!json.contains(TAG_INDEX) || !json.contains(TAG_DEVICE_ID) || + !json.contains(TAG_SLICE_NUM)) { + LOGE("err json string, first time"); + return DM_FAILED; + } + + idx = json[TAG_INDEX]; + sliceNum = json[TAG_SLICE_NUM]; + if (idx == 0) { + authResponseContext_->deviceId = json[TAG_DEVICE_ID]; + authResponseContext_->authType = json[TAG_AUTH_TYPE]; + authResponseContext_->appDesc = json[TAG_APP_DESCRIPTION]; + authResponseContext_->token = json[TAG_TOKEN]; + authResponseContext_->targetPkgName = json[TAG_TARGET]; + authResponseContext_->appName = json[TAG_APP_NAME]; + authResponseContext_->appThumbnail = ""; + } + + if (idx < sliceNum && json.contains(TAG_APP_THUMBNAIL)) { + std::string appSliceThumbnail = json[TAG_APP_THUMBNAIL]; + authResponseContext_->appThumbnail = authResponseContext_->appThumbnail + appSliceThumbnail; + return DM_MESSAGE_NOT_COMPLETE; + } + return DM_OK; +} + void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) { LOGI("AuthMessageProcessor::ParseAuthResponseMessage "); @@ -227,25 +240,6 @@ void AuthMessageProcessor::ParseAuthResponseMessage(nlohmann::json &json) LOGI("AuthMessageProcessor::ParseAuthResponseMessage "); } -int32_t AuthMessageProcessor::ParseAuthRequestMessage() -{ - nlohmann::json jsonObject = authSplitJsonList_.front(); - authResponseContext_->deviceId = jsonObject[TAG_DEVICE_ID]; - authResponseContext_->reply = jsonObject[TAG_REPLY]; - authResponseContext_->authType = jsonObject[TAG_AUTH_TYPE]; - LOGI("AuthMessageProcessor::ParseAuthResponseMessage %d", authResponseContext_->reply); - LOGI("AuthMessageProcessor::ParseAuthResponseMessage %s", authResponseContext_->deviceId.c_str()); - if (authResponseContext_->reply == AUTH_REPLY_ACCEPT) { - authResponseContext_->networkId = jsonObject[TAG_NET_ID]; - authResponseContext_->groupId = jsonObject[TAG_GROUP_ID]; - authResponseContext_->groupName = jsonObject[TAG_GROUP_NAME]; - authResponseContext_->requestId = jsonObject[TAG_REQUEST_ID]; - return DM_FAILED; - } - authSplitJsonList_.clear(); - return DM_OK; -} - void AuthMessageProcessor::ParseNegotiateMessage(const nlohmann::json &json) { if (json.contains(TAG_CRYPTO_SUPPORT)) { diff --git a/test/unittest/UTTest_auth_message_processor.cpp b/test/unittest/UTTest_auth_message_processor.cpp index df185bac18826ec399446e2edb3c853427305be1..c484f6a33496397c81311fbaf27c25d7e77b8578 100644 --- a/test/unittest/UTTest_auth_message_processor.cpp +++ b/test/unittest/UTTest_auth_message_processor.cpp @@ -267,7 +267,6 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); - nlohmann::json json; nlohmann::json jsonThumbnail; authResponseContext->deviceId = "123"; authResponseContext->reply = 0; @@ -283,8 +282,7 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_001, testing::ext::Te jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId; jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName; jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId; - authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); - int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); + int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail); ASSERT_EQ(ret, DM_FAILED); } @@ -302,24 +300,16 @@ HWTEST_F(AuthMessageProcessorTest, ParseAuthRequestMessage_002, testing::ext::Te std::shared_ptr authMessageProcessor = std::make_shared(data); std::shared_ptr authResponseContext = std::make_shared(); authMessageProcessor->SetResponseContext(authResponseContext); - nlohmann::json json; nlohmann::json jsonThumbnail; - authResponseContext->deviceId = "123"; - authResponseContext->reply = 1; - authResponseContext->authType = 222; - authResponseContext->networkId = "234"; - authResponseContext->groupId = "345"; - authResponseContext->groupName = "456"; - authResponseContext->requestId = 2333; - jsonThumbnail[TAG_DEVICE_ID] = authResponseContext->deviceId; - jsonThumbnail[TAG_REPLY] = authResponseContext->reply; - jsonThumbnail[TAG_AUTH_TYPE] = authResponseContext->authType; - jsonThumbnail[TAG_NET_ID] = authResponseContext->networkId; - jsonThumbnail[TAG_GROUP_ID] = authResponseContext->groupId; - jsonThumbnail[TAG_GROUP_NAME] = authResponseContext->groupName; - jsonThumbnail[TAG_REQUEST_ID] = authResponseContext->requestId; - authMessageProcessor->authSplitJsonList_.push_back(jsonThumbnail); - int32_t ret = authMessageProcessor->ParseAuthRequestMessage(); + jsonThumbnail[TAG_SLICE_NUM] = 1; + jsonThumbnail[TAG_INDEX] = 0; + jsonThumbnail[TAG_DEVICE_ID] = "123"; + jsonThumbnail[TAG_AUTH_TYPE] = 1; + jsonThumbnail[TAG_APP_DESCRIPTION] = "123"; + jsonThumbnail[TAG_TOKEN] = "1234"; + jsonThumbnail[TAG_TARGET] = "12345"; + jsonThumbnail[TAG_APP_NAME] = "123456"; + int32_t ret = authMessageProcessor->ParseAuthRequestMessage(jsonThumbnail); ASSERT_EQ(ret, DM_OK); }