diff --git a/services/ans/test/unittest/advanced_notification_service_test.cpp b/services/ans/test/unittest/advanced_notification_service_test.cpp index f58b8f4e70b1f95b79deeea6b187cff60866e81f..5c51224506d6079253dbfdd5c602ba8b80591f3b 100644 --- a/services/ans/test/unittest/advanced_notification_service_test.cpp +++ b/services/ans/test/unittest/advanced_notification_service_test.cpp @@ -1602,6 +1602,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11000, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11100, Function | SmallTest | Level1) { + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); sptr req = new NotificationRequest(); EXPECT_NE(req, nullptr); req->SetSlotType(NotificationConstant::SlotType::OTHER); @@ -1617,6 +1618,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11100, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11200, Function | SmallTest | Level1) { + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); std::string label = "testLabel"; { @@ -1635,6 +1637,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11200, */ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11300, Function | SmallTest | Level1) { + IPCSkeleton::SetCallingTokenID(NATIVE_TOKEN); IPCSkeleton::SetCallingUid(SYSTEM_SERVICE_UID); std::string label = "testLabel"; { @@ -1643,7 +1646,7 @@ HWTEST_F(AdvancedNotificationServiceTest, AdvancedNotificationServiceTest_11300, req->SetLabel(label); EXPECT_EQ(advancedNotificationService_->PublishContinuousTaskNotification(req), (int)ERR_OK); } - IPCSkeleton::SetCallingUid(SYSTEM_APP_UID); + IPCSkeleton::SetCallingTokenID(NON_NATIVE_TOKEN); EXPECT_EQ( advancedNotificationService_->CancelContinuousTaskNotification(label, 1), (int)ERR_ANS_NOT_SYSTEM_SERVICE); } diff --git a/services/ans/test/unittest/ans_ut_constant.h b/services/ans/test/unittest/ans_ut_constant.h index 886634b712c7763886178d30c05387d834abc23d..8319782bca37da9f37decd85690011317dc3da1c 100644 --- a/services/ans/test/unittest/ans_ut_constant.h +++ b/services/ans/test/unittest/ans_ut_constant.h @@ -20,6 +20,8 @@ namespace OHOS { namespace Notification { +constexpr unsigned int NATIVE_TOKEN = 0; +constexpr unsigned int NON_NATIVE_TOKEN = 1; constexpr int SYSTEM_APP_UID = 100; constexpr int NON_SYSTEM_APP_UID = 1000; constexpr int NON_BUNDLE_NAME_UID = 2000; diff --git a/services/ans/test/unittest/mock/include/mock_ipc_skeleton.h b/services/ans/test/unittest/mock/include/mock_ipc_skeleton.h index aafcb863794e9ce7f188b80081f6ad94ff8626c3..9dba14229561113c7f1e8aa8261c6ef1decb2eee 100644 --- a/services/ans/test/unittest/mock/include/mock_ipc_skeleton.h +++ b/services/ans/test/unittest/mock/include/mock_ipc_skeleton.h @@ -16,6 +16,7 @@ #ifndef OHOS_IPC_IPC_SKELETON_H #define OHOS_IPC_IPC_SKELETON_H +#include "accesstoken_kit.h" #include "iremote_object.h" namespace OHOS { @@ -37,6 +38,8 @@ public: static pid_t GetCallingUid(); + static Security::AccessToken::AccessTokenID GetCallingTokenID(); + static std::string GetLocalDeviceID(); static std::string GetCallingDeviceID(); @@ -56,6 +59,8 @@ public: static bool SetCallingIdentity(std::string &identity); static void SetCallingUid(pid_t uid); + + static void SetCallingTokenID(Security::AccessToken::AccessTokenID callerToken); }; } // namespace OHOS #endif // OHOS_IPC_IPC_SKELETON_H diff --git a/services/ans/test/unittest/mock/mock_access_token_helper.cpp b/services/ans/test/unittest/mock/mock_access_token_helper.cpp index 51c2f039e007568d3be76eafd903af52e6383d50..0f3cba40f0988a31a08c6696fa5b944a7fb47d92 100644 --- a/services/ans/test/unittest/mock/mock_access_token_helper.cpp +++ b/services/ans/test/unittest/mock/mock_access_token_helper.cpp @@ -14,6 +14,7 @@ */ #include "access_token_helper.h" +#include "ans_ut_constant.h" namespace OHOS { namespace Notification { @@ -25,7 +26,7 @@ bool AccessTokenHelper::VerifyCallerPermission( bool AccessTokenHelper::VerifyNativeToken(const Security::AccessToken::AccessTokenID &callerToken) { - return true; + return callerToken == NATIVE_TOKEN; } } // namespace Notification } // namespace OHOS \ No newline at end of file diff --git a/services/ans/test/unittest/mock/mock_ipc.cpp b/services/ans/test/unittest/mock/mock_ipc.cpp index 6f08e07f8198df60e90bc15c8f55f0d7abab22bf..dc9c4065d7b82c824e9d8d2cf28417ac9dccb8f1 100644 --- a/services/ans/test/unittest/mock/mock_ipc.cpp +++ b/services/ans/test/unittest/mock/mock_ipc.cpp @@ -21,6 +21,7 @@ using namespace IPC_SINGLE; #endif pid_t uid_ = 1; +Security::AccessToken::AccessTokenID callerToken_ = 0; pid_t IPCSkeleton::GetCallingUid() { @@ -32,8 +33,18 @@ pid_t IPCSkeleton::GetCallingPid() return 1; } +Security::AccessToken::AccessTokenID IPCSkeleton::GetCallingTokenID() +{ + return callerToken_; +} + void IPCSkeleton::SetCallingUid(pid_t uid) { uid_ = uid; } + +void IPCSkeleton::SetCallingTokenID(Security::AccessToken::AccessTokenID callerToken) +{ + callerToken_ = callerToken; +} } // namespace OHOS diff --git a/services/distributed/test/unittest/BUILD.gn b/services/distributed/test/unittest/BUILD.gn index a44b608eab54e1c6cd078c3f563a7b8af8a7c687..216faf743bfeeb6d88be67aafc4630f4114f8657 100644 --- a/services/distributed/test/unittest/BUILD.gn +++ b/services/distributed/test/unittest/BUILD.gn @@ -50,8 +50,6 @@ ohos_unittest("ans_distributed_unit_test") { "${services_path}/distributed/test/unittest/mock/mock_change_notification.cpp", "${services_path}/distributed/test/unittest/mock/mock_distributed_kv_data_manager.cpp", "${services_path}/distributed/test/unittest/mock/mock_event_handler.cpp", - "${services_path}/distributed/test/unittest/mock/mock_event_runner.cpp", - "${services_path}/distributed/test/unittest/mock/mock_inner_event.cpp", ] configs = [ @@ -72,6 +70,7 @@ ohos_unittest("ans_distributed_unit_test") { "ability_base:zuri", "bundle_framework:appexecfwk_base", "distributeddatamgr:distributeddata_inner", + "eventhandler:libeventhandler", "hitrace_native:libhitrace", "hiviewdfx_hilog_native:libhilog", "ipc:ipc_core", diff --git a/services/distributed/test/unittest/mock/mock_event_runner.cpp b/services/distributed/test/unittest/mock/mock_event_runner.cpp deleted file mode 100644 index 4e3cdb37c2911ce62175b359e768353c26a80bc6..0000000000000000000000000000000000000000 --- a/services/distributed/test/unittest/mock/mock_event_runner.cpp +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2022 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 "event_runner.h" - -namespace OHOS { -namespace AppExecFwk { -EventRunner::EventRunner(bool deposit) : deposit_(deposit) -{} -EventRunner::~EventRunner() -{} - -std::shared_ptr EventRunner::Create(bool inNewThread) -{ - return std::shared_ptr(new EventRunner(false)); -} -} // namespace AppExecFwk -} // namespace OHOS diff --git a/services/distributed/test/unittest/mock/mock_inner_event.cpp b/services/distributed/test/unittest/mock/mock_inner_event.cpp deleted file mode 100644 index 857a69c73e490dce1d0a2bc840fcfcb3b747bb3b..0000000000000000000000000000000000000000 --- a/services/distributed/test/unittest/mock/mock_inner_event.cpp +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (c) 2022 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 "inner_event.h" - -namespace OHOS { -namespace AppExecFwk { -InnerEvent::Pointer InnerEvent::Get(const Callback &callback, const std::string &name) -{ - InnerEvent::Pointer pointer = InnerEvent::Pointer(new InnerEvent, [](InnerEvent *event) {}); - pointer->taskCallback_ = callback; - pointer->taskName_ = name; - return pointer; -} -} // namespace AppExecFwk -} // namespace OHOS \ No newline at end of file