From 2f67b7d229efc7440cd2c3974414ebfb90bcebae Mon Sep 17 00:00:00 2001 From: xxx Date: Thu, 24 Aug 2023 09:55:54 +0800 Subject: [PATCH] Description:modify unit test when enhance is not exist Match-id-34e2ec72766fe3d407856346a6fc78b39d2c2074 --- .../inner_api/security_component/test/BUILD.gn | 9 +++++++++ .../test/unittest/src/sec_comp_kit_test.cpp | 6 ++++++ .../unittest/src/sec_comp_register_callback_test.cpp | 12 ++++++++++++ security_component.gni | 7 +++++++ services/security_component_service/sa/test/BUILD.gn | 5 +++++ .../sa/test/unittest/src/sec_comp_entity_test.cpp | 4 ++++ .../sa/test/unittest/src/sec_comp_manager_test.cpp | 5 +++++ .../sa/test/unittest/src/sec_comp_service_test.cpp | 11 +++++++++++ 8 files changed, 59 insertions(+) diff --git a/interfaces/inner_api/security_component/test/BUILD.gn b/interfaces/inner_api/security_component/test/BUILD.gn index fdba91b..66892b6 100644 --- a/interfaces/inner_api/security_component/test/BUILD.gn +++ b/interfaces/inner_api/security_component/test/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("../../../../security_component.gni") sec_comp_root_dir = "../../../.." @@ -36,6 +37,10 @@ ohos_unittest("sec_comp_sdk_test") { configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] cflags_cc = [ "-DHILOG_ENABLE" ] + if (security_component_enhance_enable) { + cflags_cc += [ "-DSECURITY_COMPONENT_ENHANCE_ENABLE" ] + } + deps = [ "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", "${sec_comp_root_dir}/interfaces/inner_api/security_component:libsecurity_component_sdk", @@ -68,6 +73,10 @@ ohos_unittest("sec_comp_register_callback_test") { configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] cflags_cc = [ "-DHILOG_ENABLE" ] + if (security_component_enhance_enable) { + cflags_cc += [ "-DSECURITY_COMPONENT_ENHANCE_ENABLE" ] + } + deps = [ "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", diff --git a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp index 58dc275..ba3d51d 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_kit_test.cpp @@ -185,7 +185,13 @@ HWTEST_F(SecCompKitTest, RegisterWithoutCallback001, TestSize.Level1) std::string locationInfo = jsonRes.dump(); int32_t scId; +#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_ENHANCE_ERROR_CALLBACK_NOT_EXIST, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_EQ(-1, scId); +#else + ASSERT_EQ(SC_OK, + SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + ASSERT_NE(-1, scId); +#endif } diff --git a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp index b38dd25..9aee39d 100644 --- a/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp +++ b/interfaces/inner_api/security_component/test/unittest/src/sec_comp_register_callback_test.cpp @@ -103,9 +103,15 @@ HWTEST_F(SecCompRegisterCallbackTest, RegisterWithoutPreprocess001, TestSize.Lev SecCompEnhanceAdapter::InitEnhanceHandler(SEC_COMP_ENHANCE_CLIENT_INTERFACE); int32_t scId; +#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_ENHANCE_ERROR_CHALLENGE_CHECK_FAIL, SecCompClient::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_EQ(-1, scId); +#else + ASSERT_EQ(SC_OK, + SecCompClient::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + ASSERT_NE(-1, scId); +#endif } /** @@ -144,9 +150,15 @@ HWTEST_F(SecCompRegisterCallbackTest, Register002, TestSize.Level1) g_probe.mockRes = -1; int32_t scId; +#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_EQ(SC_ENHANCE_ERROR_CALLBACK_OPER_FAIL, SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); ASSERT_EQ(-1, scId); +#else + ASSERT_EQ(SC_OK, + SecCompKit::RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); + ASSERT_NE(-1, scId); +#endif } /** diff --git a/security_component.gni b/security_component.gni index f92bdb1..9d13f50 100644 --- a/security_component.gni +++ b/security_component.gni @@ -12,3 +12,10 @@ # limitations under the License. sec_comp_dir = "//base/security/security_component" + +if (!defined(global_parts_info) || + defined(global_parts_info.security_security_component_enhance)) { + security_component_enhance_enable = true +} else { + security_component_enhance_enable = false +} diff --git a/services/security_component_service/sa/test/BUILD.gn b/services/security_component_service/sa/test/BUILD.gn index 84cd54b..7e2e468 100644 --- a/services/security_component_service/sa/test/BUILD.gn +++ b/services/security_component_service/sa/test/BUILD.gn @@ -12,6 +12,7 @@ # limitations under the License. import("//build/test.gni") +import("../../../../security_component.gni") sec_comp_root_dir = "../../../.." @@ -56,6 +57,10 @@ ohos_unittest("sec_comp_service_test") { configs = [ "${sec_comp_root_dir}/config:coverage_flags" ] cflags_cc = [ "-DHILOG_ENABLE" ] + if (security_component_enhance_enable) { + cflags_cc += [ "-DSECURITY_COMPONENT_ENHANCE_ENABLE" ] + } + deps = [ "${sec_comp_root_dir}/frameworks:libsecurity_component_enhance_adapter", "${sec_comp_root_dir}/frameworks:libsecurity_component_framework", diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp index 8a9b861..f306dc5 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_entity_test.cpp @@ -152,5 +152,9 @@ HWTEST_F(SecCompEntityTest, CheckTouchInfo001, TestSize.Level1) entity_->componentInfo_->rect_.y_ = ServiceTestCommon::TEST_COORDINATE; touch.timestamp = static_cast( std::chrono::high_resolution_clock::now().time_since_epoch().count()) / ServiceTestCommon::TIME_CONVERSION_UNIT; +#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE ASSERT_FALSE(entity_->CheckTouchInfo(touch)); +#else + ASSERT_TRUE(entity_->CheckTouchInfo(touch)); +#endif } diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp index 5ad5d90..4e9e5f6 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_manager_test.cpp @@ -287,9 +287,14 @@ HWTEST_F(SecCompManagerTest, RegisterSecurityComponent001, TestSize.Level1) LocationButton buttonValid = BuildValidLocationComponent(); buttonValid.ToJson(jsonValid); +#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE // callback check failed ASSERT_EQ(SC_ENHANCE_ERROR_CALLBACK_NOT_EXIST, SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonValid, caller, scId)); +#else + ASSERT_EQ(SC_OK, + SecCompManager::GetInstance().RegisterSecurityComponent(LOCATION_COMPONENT, jsonValid, caller, scId)); +#endif SecCompManager::GetInstance().maliciousAppList_.clear(); } diff --git a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp index 3ca3a7f..8efe7c4 100644 --- a/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp +++ b/services/security_component_service/sa/test/unittest/src/sec_comp_service_test.cpp @@ -258,8 +258,13 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve }; secCompService_->appStateObserver_->AddProcessToForegroundSet(stateData); +#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE EXPECT_EQ(SC_ENHANCE_ERROR_CALLBACK_NOT_EXIST, secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); +#else + EXPECT_EQ(SC_OK, + secCompService_->RegisterSecurityComponent(LOCATION_COMPONENT, locationInfo, scId)); +#endif uint8_t data[16] = { 0 }; struct SecCompClickEvent touch = { .touchX = 100, @@ -269,8 +274,14 @@ HWTEST_F(SecCompServiceTest, ReportSecurityComponentClickEvent001, TestSize.Leve .extraInfo.data = data, .extraInfo.dataSize = 16, }; +#ifdef SECURITY_COMPONENT_ENHANCE_ENABLE EXPECT_EQ(SC_ENHANCE_ERROR_IN_MALICIOUS_LIST, secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr)); EXPECT_EQ(SC_SERVICE_ERROR_COMPONENT_NOT_EXIST, secCompService_->UnregisterSecurityComponent(scId)); +#else + EXPECT_EQ(SC_OK, + secCompService_->ReportSecurityComponentClickEvent(scId, locationInfo, touch, nullptr)); + EXPECT_EQ(SC_OK, secCompService_->UnregisterSecurityComponent(scId)); +#endif setuid(uid); }