• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <gtest/gtest.h>
17 #include "disallow_export_recovery_key_plugin.h"
18 #include "edm_constants.h"
19 #include "edm_ipc_interface_code.h"
20 #include "iplugin_manager.h"
21 #include "plugin_singleton.h"
22 #include "utils.h"
23 
24 using namespace testing::ext;
25 using namespace testing;
26 
27 namespace OHOS {
28 namespace EDM {
29 namespace TEST {
30 const std::string TEST_BUNDLE_NAME = "testBundleName";
31 class DisallowExportRecoveryKeyPluginTest : public testing::Test {
32 protected:
33     static void SetUpTestSuite(void);
34 
35     static void TearDownTestSuite(void);
36 };
37 
SetUpTestSuite(void)38 void DisallowExportRecoveryKeyPluginTest::SetUpTestSuite(void)
39 {
40     Utils::SetEdmInitialEnv();
41 }
42 
TearDownTestSuite(void)43 void DisallowExportRecoveryKeyPluginTest::TearDownTestSuite(void)
44 {
45     Utils::ResetTokenTypeAndUid();
46     ASSERT_TRUE(Utils::IsOriginalUTEnv());
47     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
48 }
49 
50 /**
51  * @tc.name: DisallowExportRecoveryKeyOnSetPolicy
52  * @tc.desc: Test DisallowExportRecoveryKeyPlugin::OnSetPolicy function.
53  * @tc.type: FUNC
54  */
55 HWTEST_F(DisallowExportRecoveryKeyPluginTest, DisallowExportRecoveryKeyOnSetPolicy, TestSize.Level1)
56 {
57     DisallowExportRecoveryKeyPlugin plugin;
58     bool data = true;
59     bool currentData;
60     bool mergeData;
61     ErrCode ret = plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
62     ASSERT_TRUE(ret == ERR_OK);
63     data = false;
64     ret = plugin.OnSetPolicy(data, currentData, mergeData, DEFAULT_USER_ID);
65     ASSERT_TRUE(ret == ERR_OK);
66 }
67 
68 /**
69  * @tc.name: DisallowExportRecoveryKeyAdminRemove
70  * @tc.desc: Test DisallowExportRecoveryKeyPlugin::OnAdminRemove function.
71  * @tc.type: FUNC
72  */
73 HWTEST_F(DisallowExportRecoveryKeyPluginTest, DisallowExportRecoveryKeyAdminRemove, TestSize.Level1)
74 {
75     DisallowExportRecoveryKeyPlugin plugin;
76     bool data = false;
77     bool mergeData = true;
78     ErrCode ret = plugin.OnAdminRemove(TEST_BUNDLE_NAME, data, mergeData, DEFAULT_USER_ID);
79     ASSERT_TRUE(ret == ERR_OK);
80     data = true;
81     mergeData = false;
82     ret = plugin.OnAdminRemove(TEST_BUNDLE_NAME, data, mergeData, DEFAULT_USER_ID);
83     ASSERT_TRUE(ret == ERR_OK);
84 }
85 } // namespace TEST
86 } // namespace EDM
87 } // namespace OHOS