From 7a78b225eada79430640e7215a5609d72dd18092 Mon Sep 17 00:00:00 2001 From: jerry Date: Wed, 13 Dec 2023 11:35:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=BE=E5=A4=87=E5=85=B3=E6=9C=BA=20?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E9=87=8D=E5=90=AF=E5=8A=9F=E8=83=BDUT?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E4=BD=BF=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E5=85=B3=E6=9C=BA=E9=87=8D=E5=90=AF=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: jerry Change-Id: Iafd0b21c5c958e7f0baad17e4bdebf3eeb997b15 --- test/unittest/edm_plugin/src/reboot_plugin_test.cpp | 6 +++++- test/unittest/edm_plugin/src/shutdown_plugin_test.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/test/unittest/edm_plugin/src/reboot_plugin_test.cpp b/test/unittest/edm_plugin/src/reboot_plugin_test.cpp index 49a9a575a..83aa69655 100644 --- a/test/unittest/edm_plugin/src/reboot_plugin_test.cpp +++ b/test/unittest/edm_plugin/src/reboot_plugin_test.cpp @@ -26,6 +26,7 @@ namespace EDM { namespace TEST { void RebootPluginTest::SetUpTestSuite(void) { + Utils::SetEdmInitialEnv(); } void RebootPluginTest::TearDownTestSuite(void) @@ -42,7 +43,9 @@ void RebootPluginTest::TearDownTestSuite(void) */ HWTEST_F(RebootPluginTest, TestReboot, TestSize.Level1) { - Utils::ResetTokenTypeAndUid(); + // 通过设置无效TokenID 或者取消非ROOT用户的授权 阻止设备重启UT测试用例执行成功 + uint64_t selfTokenId = GetSelfTokenID(); + SetSelfTokenID(0); std::shared_ptr plugin = RebootPlugin::GetPlugin(); bool isChanged = false; uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::REBOOT); @@ -51,6 +54,7 @@ HWTEST_F(RebootPluginTest, TestReboot, TestSize.Level1) MessageParcel reply; ErrCode ret = plugin->OnHandlePolicy(code, data, reply, policyData, isChanged, DEFAULT_USER_ID); ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY); + SetSelfTokenID(selfTokenId); } } // namespace TEST } // namespace EDM diff --git a/test/unittest/edm_plugin/src/shutdown_plugin_test.cpp b/test/unittest/edm_plugin/src/shutdown_plugin_test.cpp index 7e00d2d66..c393b5549 100644 --- a/test/unittest/edm_plugin/src/shutdown_plugin_test.cpp +++ b/test/unittest/edm_plugin/src/shutdown_plugin_test.cpp @@ -26,6 +26,7 @@ namespace EDM { namespace TEST { void ShutdownPluginTest::SetUpTestSuite(void) { + Utils::SetEdmInitialEnv(); } void ShutdownPluginTest::TearDownTestSuite(void) @@ -42,7 +43,9 @@ void ShutdownPluginTest::TearDownTestSuite(void) */ HWTEST_F(ShutdownPluginTest, TestShutdown, TestSize.Level1) { - Utils::ResetTokenTypeAndUid(); + // 通过设置无效TokenID 或者取消非ROOT用户的授权 阻止设备关机UT测试用例执行成功 + uint64_t selfTokenId = GetSelfTokenID(); + SetSelfTokenID(0); std::shared_ptr plugin = ShutdownPlugin::GetPlugin(); bool isChanged = false; uint32_t code = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::SHUTDOWN); @@ -51,6 +54,7 @@ HWTEST_F(ShutdownPluginTest, TestShutdown, TestSize.Level1) MessageParcel reply; ErrCode ret = plugin->OnHandlePolicy(code, data, reply, policyData, isChanged, DEFAULT_USER_ID); ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY); + SetSelfTokenID(selfTokenId); } } // namespace TEST } // namespace EDM -- Gitee