1 /*
2  * Copyright (c) 2023 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 "disallow_add_local_account_plugin_test.h"
17 #include "disallow_add_local_account_plugin.h"
18 #include "utils.h"
19 
20 using namespace testing::ext;
21 
22 namespace OHOS {
23 namespace EDM {
24 namespace TEST {
SetUpTestSuite(void)25 void DisallowAddLocalAccountPluginTest::SetUpTestSuite(void)
26 {
27     Utils::SetEdmInitialEnv();
28 }
29 
TearDownTestSuite(void)30 void DisallowAddLocalAccountPluginTest::TearDownTestSuite(void)
31 {
32     Utils::ResetTokenTypeAndUid();
33     ASSERT_TRUE(Utils::IsOriginalUTEnv());
34     std::cout << "now ut process is orignal ut env : " << Utils::IsOriginalUTEnv() << std::endl;
35 }
36 
37 /**
38  * @tc.name: TestDisallowAddLocalAccountPlugin
39  * @tc.desc: Test DisallowAddLocalAccountPlugin::OnSetPolicy function and remove policy.
40  * @tc.type: FUNC
41  */
42 HWTEST_F(DisallowAddLocalAccountPluginTest, TestDisallowAddLocalAccountPlugin, TestSize.Level1)
43 {
44     DisallowAddLocalAccountPlugin plugin;
45     bool data = true;
46     ErrCode ret = plugin.OnSetPolicy(data);
47     ASSERT_TRUE(ret == ERR_OK && data);
48 
49     string adminName{"testAdminName"};
50     bool allowAddLocalAccount = true;
51     ret = plugin.OnAdminRemove(adminName, allowAddLocalAccount, DEFAULT_USER_ID);
52     ASSERT_TRUE(ret == ERR_OK);
53 }
54 
55 /**
56  * @tc.name: TestDisallowAddLocalAccountPluginGet
57  * @tc.desc: Test DisallowAddLocalAccountPlugin::OnGetPolicy function.
58  * @tc.type: FUNC
59  */
60     HWTEST_F(DisallowAddLocalAccountPluginTest, TestDisallowAddLocalAccountPluginGet, TestSize.Level1)
61 {
62     std::shared_ptr<IPlugin> plugin = DisallowAddLocalAccountPlugin::GetPlugin();
63     std::string policyData{"false"};
64     MessageParcel data;
65     MessageParcel reply;
66     ErrCode ret = plugin->OnGetPolicy(policyData, data, reply, DEFAULT_USER_ID);
67     int32_t flag = ERR_INVALID_VALUE;
68     ASSERT_TRUE(reply.ReadInt32(flag) && (flag == ERR_OK));
69     bool result = false;
70     reply.ReadBool(result);
71     ASSERT_TRUE(ret == ERR_OK);
72     ASSERT_FALSE(result);
73 }
74 } // namespace TEST
75 } // namespace EDM
76 } // namespace OHOS