• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <string>
18 #include <vector>
19 #include "cmd_utils.h"
20 #include "enterprise_device_mgr_proxy.h"
21 #include "func_code.h"
22 #include "policy_info.h"
23 
24 using namespace testing::ext;
25 
26 namespace OHOS {
27 namespace EDM {
28 namespace TEST {
29 constexpr int32_t DEFAULT_USERID = 100;
30 class EnterpriseDeviceMgrProxyTest : public testing::Test {
31 protected:
32     void SetUp() override;
33 
34     void TearDown() override;
35 
36     std::shared_ptr<EnterpriseDeviceMgrProxy> enterpriseDeviceMgrProxyTest;
37 };
38 
SetUp()39 void EnterpriseDeviceMgrProxyTest::SetUp()
40 {
41     enterpriseDeviceMgrProxyTest = EnterpriseDeviceMgrProxy::GetInstance();
42 }
43 
TearDown()44 void EnterpriseDeviceMgrProxyTest::TearDown()
45 {
46     EnterpriseDeviceMgrProxy::DestroyInstance();
47 }
48 
49 /**
50  * @tc.name: TestDisableAdmin
51  * @tc.desc: Test DisableAdmin func.
52  * @tc.type: FUNC
53  */
54 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableAdmin, TestSize.Level1)
55 {
56     AppExecFwk::ElementName admin;
57     admin.SetBundleName("com.edm.test.demo");
58     admin.SetAbilityName("com.edm.test.demo.Ability");
59 
60     EntInfo entInfo("test", "this is test");
61 
62     ErrCode errVal = enterpriseDeviceMgrProxyTest->EnableAdmin(admin, entInfo, AdminType::NORMAL, DEFAULT_USERID);
63     EXPECT_TRUE(errVal != ERR_OK);
64 
65     errVal = enterpriseDeviceMgrProxyTest->SetEnterpriseInfo(admin, entInfo);
66     EXPECT_TRUE(errVal != ERR_OK);
67 
68     EntInfo entInfo1;
69     enterpriseDeviceMgrProxyTest->GetEnterpriseInfo(admin, entInfo1);
70     EXPECT_TRUE(entInfo1.enterpriseName.size() == 0);
71     EXPECT_TRUE(entInfo1.description.size() == 0);
72 
73     bool ret = enterpriseDeviceMgrProxyTest->IsAdminEnabled(admin, DEFAULT_USERID);
74     EXPECT_FALSE(ret);
75 
76 
77     std::vector<std::string> enabledAdminList;
78     enterpriseDeviceMgrProxyTest->GetEnabledAdmins(enabledAdminList);
79     EXPECT_TRUE(enabledAdminList.empty());
80 
81     std::vector<std::u16string> enabledAdminList1;
82     enterpriseDeviceMgrProxyTest->GetEnabledAdmin(AdminType::NORMAL, enabledAdminList1);
83     EXPECT_TRUE(enabledAdminList1.empty());
84 
85     int funcCode = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, SET_DATETIME);
86     bool isDisabled;
87     enterpriseDeviceMgrProxyTest->IsPolicyDisable(funcCode, isDisabled);
88     EXPECT_FALSE(isDisabled);
89 
90 
91     errVal = enterpriseDeviceMgrProxyTest->DisableAdmin(admin, DEFAULT_USERID);
92     EXPECT_TRUE(errVal != ERR_OK);
93 }
94 
95 /**
96  * @tc.name: TestDisableSuperAdmin
97  * @tc.desc: Test DisableSuperAdmin func.
98  * @tc.type: FUNC
99  */
100 HWTEST_F(EnterpriseDeviceMgrProxyTest, TestDisableSuperAdmin, TestSize.Level1)
101 {
102     AppExecFwk::ElementName admin;
103     admin.SetBundleName("com.edm.test.demo");
104     admin.SetAbilityName("com.edm.test.demo.Ability");
105 
106     EntInfo entInfo("test", "this is test");
107 
108     ErrCode errVal = enterpriseDeviceMgrProxyTest->EnableAdmin(admin, entInfo, AdminType::ENT, DEFAULT_USERID);
109     EXPECT_TRUE(errVal != ERR_OK);
110 
111     bool ret = enterpriseDeviceMgrProxyTest->IsSuperAdmin("com.edm.test.demo");
112     EXPECT_FALSE(ret);
113 
114     std::string enabledAdmin;
115     enterpriseDeviceMgrProxyTest->GetEnabledSuperAdmin(enabledAdmin);
116     EXPECT_TRUE(enabledAdmin.size() == 0);
117 
118     ret = enterpriseDeviceMgrProxyTest->IsSuperAdminExist();
119     EXPECT_FALSE(ret);
120 
121     errVal = enterpriseDeviceMgrProxyTest->DisableSuperAdmin("com.edm.test.demo");
122     EXPECT_TRUE(errVal != ERR_OK);
123 }
124 } // namespace TEST
125 } // namespace EDM
126 } // namespace OHOS
127