diff --git a/test/unittest/BUILD.gn b/test/unittest/BUILD.gn index 0b608f03e6d5023f0129602174f517606b5b0f28..de353c5b7bd12f102d0f6ea31f19f320a12c6025 100644 --- a/test/unittest/BUILD.gn +++ b/test/unittest/BUILD.gn @@ -45,6 +45,7 @@ group("unittest") { ":UTTest_dm_auth_manager_first", ":UTTest_dm_auth_manager_second", ":UTTest_dm_auth_manager_third", + ":UTTest_dm_auth_message_processor", ":UTTest_dm_comm_tool", ":UTTest_dm_common_event_manager", ":UTTest_dm_credential_manager", @@ -2018,6 +2019,33 @@ ohos_unittest("UTTest_auth_pin_auth_state") { ## UnitTest UTTest_auth_pin_auth_state }}} +## UnitTest UTTest_dm_auth_message_processor {{{ + +ohos_unittest("UTTest_dm_auth_message_processor") { + module_out_path = module_out_path + + include_dirs = [] + + sources = [ + "${devicemanager_path}/test/unittest/UTTest_dm_auth_message_processor.cpp", + ] + + deps = [ ":device_manager_test_common" ] + + external_deps = [ + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "googletest:gmock", + "googletest:gmock_main", + "hilog:libhilog", + ] +} + +## UnitTest UTTest_dm_auth_message_processor }}} + ## UnitTest UTTest_auth_credential_state {{{ ohos_unittest("UTTest_auth_credential_state") { diff --git a/test/unittest/UTTest_auth_pin_auth_state.cpp b/test/unittest/UTTest_auth_pin_auth_state.cpp index c12e596601c892a0ca06dc4a21cff2ff60d82ac1..4026349e169a047c43e9a3cb40fafbea8a8b421d 100644 --- a/test/unittest/UTTest_auth_pin_auth_state.cpp +++ b/test/unittest/UTTest_auth_pin_auth_state.cpp @@ -417,5 +417,255 @@ HWTEST_F(AuthPinAuthStateTest, AuthSinkPinAuthDoneState_002, testing::ext::TestS EXPECT_EQ(authState->Action(context), DM_OK); } + +HWTEST_F(AuthPinAuthStateTest, AuthSrcReverseUltrasonicStartState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SRC_REVERSE_ULTRASONIC_START_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcReverseUltrasonicStartState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcReverseUltrasonicDoneState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SRC_REVERSE_ULTRASONIC_DONE_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcReverseUltrasonicDoneState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, AuthCredentialPinCode(_, _, _)) + .WillOnce(Return(ERR_DM_FAILED)); + EXPECT_EQ(authState->Action(context), ERR_DM_FAILED); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcReverseUltrasonicDoneState_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, AuthCredentialPinCode(_, _, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_TRANSMIT)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcReverseUltrasonicDoneState_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, AuthCredentialPinCode(_, _, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_SESSION_KEY_RETURNED)); + EXPECT_EQ(authState->Action(context), STOP_BIND); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicStartState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SRC_FORWARD_ULTRASONIC_START_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicStartState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicDoneState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SRC_FORWARD_ULTRASONIC_DONE_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicDoneState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ULTRASONIC_PIN_CHANGED)); + EXPECT_CALL(*hiChainAuthConnectorMock, AuthCredentialPinCode(_, _, _)) + .WillOnce(Return(ERR_DM_FAILED)); + EXPECT_EQ(authState->Action(context), STOP_BIND); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicDoneState_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ULTRASONIC_PIN_CHANGED)) + .WillOnce(Return(ON_TRANSMIT)); + EXPECT_CALL(*hiChainAuthConnectorMock, AuthCredentialPinCode(_, _, _)) + .WillOnce(Return(DM_OK)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicDoneState_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ULTRASONIC_PIN_CHANGED)) + .WillOnce(Return(ON_ERROR)); + EXPECT_CALL(*hiChainAuthConnectorMock, AuthCredentialPinCode(_, _, _)) + .WillOnce(Return(DM_OK)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicDoneState_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ULTRASONIC_PIN_TIMEOUT)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSrcForwardUltrasonicDoneState_006, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_SESSION_KEY_RETURNED)); + EXPECT_EQ(authState->Action(context), STOP_BIND); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicStartState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SINK_REVERSE_ULTRASONIC_START_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicStartState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ULTRASONIC_PIN_CHANGED)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicStartState_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ULTRASONIC_PIN_TIMEOUT)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicStartState_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_SESSION_KEY_RETURNED)); + EXPECT_EQ(authState->Action(context), STOP_BIND); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicDoneState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SINK_REVERSE_ULTRASONIC_DONE_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicDoneState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(ERR_DM_FAILED)); + EXPECT_EQ(authState->Action(context), ERR_DM_FAILED); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicDoneState_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_TRANSMIT)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicDoneState_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ERROR)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkReverseUltrasonicDoneState_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_SESSION_KEY_RETURNED)); + EXPECT_EQ(authState->Action(context), STOP_BIND); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkForwardUltrasonicStartState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SINK_FORWARD_ULTRASONIC_START_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkForwardUltrasonicStartState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkForwardUltrasonicDoneState_001, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = + std::make_shared(); + EXPECT_EQ(authState->GetStateType(), DmAuthStateType::AUTH_SINK_FORWARD_ULTRASONIC_DONE_STATE); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkForwardUltrasonicDoneState_002, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(ERR_DM_FAILED)); + EXPECT_EQ(authState->Action(context), ERR_DM_FAILED); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkForwardUltrasonicDoneState_003, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_TRANSMIT)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkForwardUltrasonicDoneState_004, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_ERROR)); + EXPECT_EQ(authState->Action(context), DM_OK); +} + +HWTEST_F(AuthPinAuthStateTest, AuthSinkForwardUltrasonicDoneState_005, testing::ext::TestSize.Level1) +{ + std::shared_ptr authState = std::make_shared(); + EXPECT_CALL(*hiChainAuthConnectorMock, ProcessCredData(_, _)) + .WillOnce(Return(DM_OK)); + EXPECT_CALL(*DmAuthStateMachineMock::dmAuthStateMachineMock, WaitExpectEvent(_)) + .WillOnce(Return(ON_SESSION_KEY_RETURNED)); + EXPECT_EQ(authState->Action(context), STOP_BIND); +} } } \ No newline at end of file diff --git a/test/unittest/UTTest_device_manager_service_impl.cpp b/test/unittest/UTTest_device_manager_service_impl.cpp index f08ba99a9c1c9dea9e509424aefd84b09cd4fb92..e160833a61347e3b1d89a4cb9ea9fc6a96084433 100644 --- a/test/unittest/UTTest_device_manager_service_impl.cpp +++ b/test/unittest/UTTest_device_manager_service_impl.cpp @@ -2053,6 +2053,21 @@ HWTEST_F(DeviceManagerServiceImplTest, DeleteCredential_010, testing::ext::TestS EXPECT_CALL(*deviceProfileConnectorMock_, GetAllAccessControlProfile()).WillOnce(Return(profiles)); deviceManagerServiceImpl_->CheckDeleteCredential(remoteUdid, remoteUserId); } + +HWTEST_F(DeviceManagerServiceImplTest, ChangeUltrasonicTypeToPin_001, testing::ext::TestSize.Level1) +{ + std::map bindParam; + int32_t ret = deviceManagerServiceImpl_->ChangeUltrasonicTypeToPin(bindParam); + EXPECT_EQ(ret, ERR_DM_AUTH_FAILED); +} + +HWTEST_F(DeviceManagerServiceImplTest, ChangeUltrasonicTypeToPin_002, testing::ext::TestSize.Level1) +{ + std::map bindParam; + bindParam["AUTH_TYPE"] = "1"; + int32_t ret = deviceManagerServiceImpl_->ChangeUltrasonicTypeToPin(bindParam); + EXPECT_EQ(ret, DM_OK); +} } // namespace } // namespace DistributedHardware } // namespace OHOS diff --git a/test/unittest/UTTest_dm_auth_message_processor.cpp b/test/unittest/UTTest_dm_auth_message_processor.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fe1f00860193618424d97bb483144db218fb8f0f --- /dev/null +++ b/test/unittest/UTTest_dm_auth_message_processor.cpp @@ -0,0 +1,116 @@ +/* + * Copyright (c) 2022-2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#include "dm_log.h" +#include "dm_anonymous.h" +#include "dm_constants.h" +#include "dm_auth_message_processor.h" +#include "dm_auth_context.h" +#include "dm_auth_state_machine.h" +#include "UTTest_dm_auth_message_processor.h" + +using namespace testing; +namespace OHOS { +namespace DistributedHardware { + +void DmAuthMessageProcessorTest::SetUpTestCase() +{ +} + +void DmAuthMessageProcessorTest::TearDownTestCase() +{ +} + +void DmAuthMessageProcessorTest::SetUp() +{ +} + +void DmAuthMessageProcessorTest::TearDown() +{ +} + +HWTEST_F(DmAuthMessageProcessorTest, CreateMessageForwardUltrasonicStart_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + std::shared_ptr context = std::make_shared(); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->CreateMessageForwardUltrasonicStart(context, json), DM_OK); +} + +HWTEST_F(DmAuthMessageProcessorTest, CreateMessageReverseUltrasonicDone_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + std::shared_ptr context = std::make_shared(); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->CreateMessageReverseUltrasonicDone(context, json), DM_OK); +} + +HWTEST_F(DmAuthMessageProcessorTest, CreateMessageReverseUltrasonicStart_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + std::shared_ptr context = std::make_shared(); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->CreateMessageReverseUltrasonicStart(context, json), DM_OK); +} + +HWTEST_F(DmAuthMessageProcessorTest, CreateMessageForwardUltrasonicNegotiate_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + std::shared_ptr context = std::make_shared(); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->CreateMessageForwardUltrasonicNegotiate(context, json), DM_OK); +} + +HWTEST_F(DmAuthMessageProcessorTest, ParseMessageReverseUltrasonicStart_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + std::shared_ptr context = std::make_shared(); + context->authStateMachine = std::make_shared(context); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->ParseMessageReverseUltrasonicStart(json, context), DM_OK); +} + +HWTEST_F(DmAuthMessageProcessorTest, ParseMessageReverseUltrasonicDone_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + json["REPLY"] = "1"; + std::shared_ptr context = std::make_shared(); + context->reply = DM_OK; + context->authStateMachine = std::make_shared(context); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->ParseMessageReverseUltrasonicDone(json, context), DM_OK); +} + +HWTEST_F(DmAuthMessageProcessorTest, ParseMessageForwardUltrasonicStart_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + std::shared_ptr context = std::make_shared(); + context->authStateMachine = std::make_shared(context); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->ParseMessageForwardUltrasonicStart(json, context), DM_OK); +} + +HWTEST_F(DmAuthMessageProcessorTest, ParseMessageForwardUltrasonicNegotiate_001, testing::ext::TestSize.Level1) +{ + JsonObject json; + std::shared_ptr context = std::make_shared(); + context->authStateMachine = std::make_shared(context); + std::shared_ptr processor = std::make_shared(); + EXPECT_EQ(processor->ParseMessageForwardUltrasonicNegotiate(json, context), DM_OK); +} + +} // namespace DistributedHardware +} // namespace OHOS + \ No newline at end of file diff --git a/test/unittest/UTTest_dm_auth_message_processor.h b/test/unittest/UTTest_dm_auth_message_processor.h new file mode 100644 index 0000000000000000000000000000000000000000..ff63a0967e5b59de77386ca752d71cecf7f14b45 --- /dev/null +++ b/test/unittest/UTTest_dm_auth_message_processor.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + +#ifndef OHOS_DM_AUTH_MESSAGE_PROCESSOR_TEST_H +#define OHOS_DM_AUTH_MESSAGE_PROCESSOR_TEST_H + +#include +#include +#include +#include "json_object.h" +#include "crypto_mgr_mock.h" + +namespace OHOS { +namespace DistributedHardware { +class DmAuthMessageProcessorTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_AUTH_MESSAGE_PROCESSOR_TEST_H + \ No newline at end of file