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 <fcntl.h>
17 #include <gtest/gtest.h>
18 #include <string>
19 #include <system_ability_definition.h>
20 #include <sys/stat.h>
21 #include <vector>
22
23 #define private public
24 #include "bundle_manager_proxy.h"
25 #undef private
26 #include "directory_ex.h"
27 #include "edm_sys_manager_mock.h"
28 #include "enterprise_device_mgr_stub_mock.h"
29 #include "install_param.h"
30 #include "policy_type.h"
31 #include "func_code.h"
32 #include "utils.h"
33
34 using namespace testing::ext;
35 using namespace testing;
36
37 namespace OHOS {
38 namespace EDM {
39 namespace TEST {
40 const std::string ADMIN_PACKAGENAME = "com.edm.test.demo";
41 const std::string TEST_PACKAGE_PATH = "/data/test/resource/enterprise_device_management/hap/right.hap";
42 const std::string TEST_TARGET_PATH = "/data/service/el1/public/edm/test.txt";
43 const int32_t APP_DISTRIBUTION_TYPE1 = 1;
44 const int32_t APP_DISTRIBUTION_TYPE2 = 2;
45 class BundleManagerProxyTest : public testing::Test {
46 protected:
47 void SetUp() override;
48
49 void TearDown() override;
50
51 static void TearDownTestSuite(void);
52 std::shared_ptr<BundleManagerProxy> bundleManagerProxy = nullptr;
53 std::shared_ptr<EdmSysManager> edmSysManager_ = nullptr;
54 sptr<EnterpriseDeviceMgrStubMock> object_ = nullptr;
55 };
56
SetUp()57 void BundleManagerProxyTest::SetUp()
58 {
59 bundleManagerProxy = BundleManagerProxy::GetBundleManagerProxy();
60 edmSysManager_ = std::make_shared<EdmSysManager>();
61 object_ = new (std::nothrow) EnterpriseDeviceMgrStubMock();
62 edmSysManager_->RegisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID, object_);
63 Utils::SetEdmServiceEnable();
64 }
65
TearDown()66 void BundleManagerProxyTest::TearDown()
67 {
68 bundleManagerProxy.reset();
69 edmSysManager_->UnregisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID);
70 object_ = nullptr;
71 Utils::SetEdmServiceDisable();
72 }
73
TearDownTestSuite()74 void BundleManagerProxyTest::TearDownTestSuite()
75 {
76 ASSERT_TRUE(OHOS::RemoveFile(TEST_TARGET_PATH));
77 ASSERT_FALSE(Utils::GetEdmServiceState());
78 std::cout << "EdmServiceState : " << Utils::GetEdmServiceState() << std::endl;
79 }
80
81 /**
82 * @tc.name: TestAddAllowedInstallBundlesSuc
83 * @tc.desc: Test AddAllowedInstallBundles success func.
84 * @tc.type: FUNC
85 */
86 HWTEST_F(BundleManagerProxyTest, AddAllowedInstallBundlesSuc, TestSize.Level1)
87 {
88 OHOS::AppExecFwk::ElementName admin;
89 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
90 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
91 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
92 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
93 .Times(1)
94 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
95 ErrCode ret = bundleManagerProxy->AddBundlesByPolicyType(admin, bundles, DEFAULT_USER_ID, policyType);
96 ASSERT_TRUE(ret == ERR_OK);
97 }
98 }
99
100 /**
101 * @tc.name: TestAddAllowedInstallBundlesFail
102 * @tc.desc: Test AddAllowedInstallBundles without enable edm service func.
103 * @tc.type: FUNC
104 */
105 HWTEST_F(BundleManagerProxyTest, AddAllowedInstallBundlesFail, TestSize.Level1)
106 {
107 Utils::SetEdmServiceDisable();
108 OHOS::AppExecFwk::ElementName admin;
109 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
110 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
111 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
112 ErrCode ret = bundleManagerProxy->AddBundlesByPolicyType(admin, bundles, DEFAULT_USER_ID, policyType);
113 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
114 }
115 }
116
117 /**
118 * @tc.name: TestRemoveAllowedInstallBundlesSuc
119 * @tc.desc: Test RemoveAllowedInstallBundles success func.
120 * @tc.type: FUNC
121 */
122 HWTEST_F(BundleManagerProxyTest, RemoveAllowedInstallBundlesSuc, TestSize.Level1)
123 {
124 OHOS::AppExecFwk::ElementName admin;
125 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
126 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
127 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
128 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
129 .Times(1)
130 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
131 ErrCode ret = bundleManagerProxy->RemoveBundlesByPolicyType(admin, bundles, DEFAULT_USER_ID, policyType);
132 ASSERT_TRUE(ret == ERR_OK);
133 }
134 }
135
136 /**
137 * @tc.name: TestRemoveAllowedInstallBundlesFail
138 * @tc.desc: Test RemoveAllowedInstallBundles without enable edm service func.
139 * @tc.type: FUNC
140 */
141 HWTEST_F(BundleManagerProxyTest, RemoveAllowedInstallBundlesFail, TestSize.Level1)
142 {
143 Utils::SetEdmServiceDisable();
144 OHOS::AppExecFwk::ElementName admin;
145 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
146 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
147 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
148 ErrCode ret = bundleManagerProxy->RemoveBundlesByPolicyType(admin, bundles, DEFAULT_USER_ID, policyType);
149 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
150 }
151 }
152
153 /**
154 * @tc.name: TestGetAllowedInstallBundlesSuc
155 * @tc.desc: Test GetAllowedInstallBundles success func.
156 * @tc.type: FUNC
157 */
158 HWTEST_F(BundleManagerProxyTest, GetAllowedInstallBundlesSuc, TestSize.Level1)
159 {
160 OHOS::AppExecFwk::ElementName admin;
161 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
162 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
163 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
164 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
165 .Times(1)
166 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
167 ErrCode ret = bundleManagerProxy->GetBundlesByPolicyType(admin, DEFAULT_USER_ID, bundles, policyType);
168 ASSERT_TRUE(ret == ERR_OK);
169 ASSERT_TRUE(bundles.size() == 1);
170 ASSERT_TRUE(bundles[0] == RETURN_STRING);
171 }
172 }
173
174 /**
175 * @tc.name: TestGetAllowedInstallBundlesFail
176 * @tc.desc: Test GetAllowedInstallBundles fail func.
177 * @tc.type: FUNC
178 */
179 HWTEST_F(BundleManagerProxyTest, TestGetAllowedInstallBundlesFail, TestSize.Level1)
180 {
181 OHOS::AppExecFwk::ElementName admin;
182 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
183 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
184 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
185 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
186 .Times(1)
187 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetErrPolicy));
188 ErrCode ret = bundleManagerProxy->GetBundlesByPolicyType(admin, DEFAULT_USER_ID, bundles, policyType);
189 ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY);
190 }
191 }
192
193 /**
194 * @tc.name: TestGetAllowedInstallBundlesFailWithMax
195 * @tc.desc: Test GetAllowedInstallBundles fail func.
196 * @tc.type: FUNC
197 */
198 HWTEST_F(BundleManagerProxyTest, TestGetAllowedInstallBundlesFailWithMax, TestSize.Level1)
199 {
200 OHOS::AppExecFwk::ElementName admin;
201 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
202 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
203 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
204 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
205 .Times(1)
206 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyExceedsMax));
207 ErrCode ret = bundleManagerProxy->GetBundlesByPolicyType(admin, DEFAULT_USER_ID, bundles, policyType);
208 ASSERT_TRUE(ret == ERR_OK);
209 }
210 }
211
212 /**
213 * @tc.name: TestGetAllowedInstallBundlesFail
214 * @tc.desc: Test GetAllowedInstallBundles without enable edm service func.
215 * @tc.type: FUNC
216 */
217 HWTEST_F(BundleManagerProxyTest, GetAllowedInstallBundlesFail, TestSize.Level1)
218 {
219 Utils::SetEdmServiceDisable();
220 OHOS::AppExecFwk::ElementName admin;
221 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
222 for (int32_t policyType = static_cast<int32_t>(PolicyType::ALLOW_INSTALL);
223 policyType <= static_cast<int32_t>(PolicyType::DISALLOW_UNINSTALL); policyType++) {
224 ErrCode ret = bundleManagerProxy->GetBundlesByPolicyType(admin, DEFAULT_USER_ID, bundles, policyType);
225 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
226 }
227 }
228
229 /**
230 * @tc.name: TestInstallBundlesInvalidType
231 * @tc.desc: Test Add remove get BundlesByPolicyType with invalid policy type.
232 * @tc.type: FUNC
233 */
234 HWTEST_F(BundleManagerProxyTest, InstallBundlesInvalidType, TestSize.Level1)
235 {
236 Utils::SetEdmServiceDisable();
237 OHOS::AppExecFwk::ElementName admin;
238 std::vector<std::string> bundles = {ADMIN_PACKAGENAME};
239 int32_t policyType = static_cast<int32_t>(PolicyType::INVALID_TYPE);
240 ErrCode ret = bundleManagerProxy->AddBundlesByPolicyType(admin, bundles, DEFAULT_USER_ID, policyType);
241 ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
242
243 ret = bundleManagerProxy->RemoveBundlesByPolicyType(admin, bundles, DEFAULT_USER_ID, policyType);
244 ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
245
246 ret = bundleManagerProxy->GetBundlesByPolicyType(admin, DEFAULT_USER_ID, bundles, policyType);
247 ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
248 }
249
250 /**
251 * @tc.name: TestUninstallParamErr
252 * @tc.desc: Test Uninsatll method with param error.
253 * @tc.type: FUNC
254 */
255 HWTEST_F(BundleManagerProxyTest, TestUninstallParamErr, TestSize.Level1)
256 {
257 OHOS::AppExecFwk::ElementName admin;
258 std::string retMsg;
259 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
260 .Times(1)
261 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestParamError));
262 ErrCode ret = bundleManagerProxy->Uninstall(admin, ADMIN_PACKAGENAME, DEFAULT_USER_ID, false, retMsg);
263 ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
264 ASSERT_TRUE(retMsg == RETURN_STRING);
265 }
266
267 /**
268 * @tc.name: TestUninstallSuc
269 * @tc.desc: Test Uninsatll method success.
270 * @tc.type: FUNC
271 */
272 HWTEST_F(BundleManagerProxyTest, TestUninstallSuc, TestSize.Level1)
273 {
274 OHOS::AppExecFwk::ElementName admin;
275 std::string retMsg;
276 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
277 .Times(1)
278 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
279 ErrCode ret = bundleManagerProxy->Uninstall(admin, ADMIN_PACKAGENAME, DEFAULT_USER_ID, false, retMsg);
280 ASSERT_TRUE(ret == ERR_OK);
281 }
282
283 /**
284 * @tc.name: TestWriteFileToStreamFailWithPathNull
285 * @tc.desc: Test WriteFileToStream method when file path is null.
286 * @tc.type: FUNC
287 */
288 HWTEST_F(BundleManagerProxyTest, TestWriteFileToStreamFailWithPathNull, TestSize.Level1)
289 {
290 OHOS::AppExecFwk::ElementName admin;
291 std::string hapFilePath;
292 std::vector<std::string> realPaths;
293 string errMessage;
294 ErrCode ret = bundleManagerProxy->WriteFileToStream(admin, hapFilePath, realPaths, errMessage);
295 ASSERT_TRUE(ret == EdmReturnErrCode::APPLICATION_INSTALL_FAILED);
296 ASSERT_TRUE(errMessage == "install failed due to invalid hapFilePaths");
297 }
298
299 /**
300 * @tc.name: TestWriteFileToStreamSuc
301 * @tc.desc: Test WriteFileToStream method when file path is valid.
302 * @tc.type: FUNC
303 */
304 HWTEST_F(BundleManagerProxyTest, TestWriteFileToStreamSuc, TestSize.Level1)
305 {
306 OHOS::AppExecFwk::ElementName admin;
307 std::string hapFilePath = TEST_PACKAGE_PATH;
308 std::vector<std::string> realPaths;
309 string errMessage;
310 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
311 .Times(1).WillOnce(Invoke(object_.GetRefPtr(),
312 &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyForWriteFileToStream));
313 ErrCode ret = bundleManagerProxy->WriteFileToStream(admin, hapFilePath, realPaths, errMessage);
314 ASSERT_TRUE(ret == ERR_OK);
315 }
316
317 /**
318 * @tc.name: TestWriteFileToStreamFailWithGetPolicyErr
319 * @tc.desc: Test WriteFileToStream method when file path is valid.
320 * @tc.type: FUNC
321 */
322 HWTEST_F(BundleManagerProxyTest, TestWriteFileToStreamFailWithGetPolicyErr, TestSize.Level1)
323 {
324 OHOS::AppExecFwk::ElementName admin;
325 std::string hapFilePath = TEST_PACKAGE_PATH;
326 std::vector<std::string> realPaths;
327 string errMessage;
328 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
329 .Times(1)
330 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetErrPolicy));
331 ErrCode ret = bundleManagerProxy->WriteFileToStream(admin, hapFilePath, realPaths, errMessage);
332 ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY);
333 }
334
335 /**
336 * @tc.name: TestInstallFailWithEmptyPath
337 * @tc.desc: Test Insatll method with empty hapFilePaths.
338 * @tc.type: FUNC
339 */
340 HWTEST_F(BundleManagerProxyTest, TestInstallFailWithEmptyPath, TestSize.Level1)
341 {
342 OHOS::AppExecFwk::ElementName admin;
343 std::vector<std::string> hapFilePaths;
344 AppExecFwk::InstallParam installParam;
345 std::string retMsg;
346 ErrCode ret = bundleManagerProxy->Install(admin, hapFilePaths, installParam, retMsg);
347 ASSERT_TRUE(ret == EdmReturnErrCode::PARAM_ERROR);
348 }
349
350 /**
351 * @tc.name: TestInstallSuc
352 * @tc.desc: Test Insatll method with one hapFilePaths.
353 * @tc.type: FUNC
354 */
355 HWTEST_F(BundleManagerProxyTest, TestInstallSuc, TestSize.Level1)
356 {
357 OHOS::AppExecFwk::ElementName admin;
358 std::vector<std::string> hapFilePaths = { TEST_PACKAGE_PATH };
359 AppExecFwk::InstallParam installParam;
360 std::string retMsg;
361 std::uint32_t funcCodeGet = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::GET, EdmInterfaceCode::INSTALL);
362 std::uint32_t funcCodeSet = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::INSTALL);
363 EXPECT_CALL(*object_, SendRequest(funcCodeGet, _, _, _))
364 .Times(1).WillOnce(Invoke(object_.GetRefPtr(),
365 &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyForWriteFileToStream));
366 EXPECT_CALL(*object_, SendRequest(funcCodeSet, _, _, _))
367 .Times(1).WillOnce(Invoke(object_.GetRefPtr(),
368 &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
369 ErrCode ret = bundleManagerProxy->Install(admin, hapFilePaths, installParam, retMsg);
370 ASSERT_TRUE(ret == ERR_OK);
371 }
372
373 /**
374 * @tc.name: TestInstallFail
375 * @tc.desc: Test Insatll method with one hapFilePaths.
376 * @tc.type: FUNC
377 */
378 HWTEST_F(BundleManagerProxyTest, TestInstallFail, TestSize.Level1)
379 {
380 OHOS::AppExecFwk::ElementName admin;
381 std::vector<std::string> hapFilePaths = { TEST_PACKAGE_PATH };
382 AppExecFwk::InstallParam installParam;
383 std::string retMsg;
384 std::uint32_t funcCodeGet = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::GET, EdmInterfaceCode::INSTALL);
385 std::uint32_t funcCodeSet = POLICY_FUNC_CODE((std::uint32_t)FuncOperateType::SET, EdmInterfaceCode::INSTALL);
386 EXPECT_CALL(*object_, SendRequest(funcCodeGet, _, _, _))
387 .Times(1).WillOnce(Invoke(object_.GetRefPtr(),
388 &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetPolicyForWriteFileToStream));
389 EXPECT_CALL(*object_, SendRequest(funcCodeSet, _, _, _))
390 .Times(1).WillOnce(Invoke(object_.GetRefPtr(),
391 &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicyInstallFail));
392 ErrCode ret = bundleManagerProxy->Install(admin, hapFilePaths, installParam, retMsg);
393 ASSERT_TRUE(ret == EdmReturnErrCode::APPLICATION_INSTALL_FAILED);
394 }
395
396 /**
397 * @tc.name: TestWriteFileToInnerFail
398 * @tc.desc: Test Insatll method with invalid hap file paths.
399 * @tc.type: FUNC
400 */
401 HWTEST_F(BundleManagerProxyTest, TestWriteFileToInnerFail, TestSize.Level1)
402 {
403 MessageParcel reply;
404 reply.WriteFileDescriptor(-1);
405 std::string hapFilePaths;
406 std::vector<std::string> realPaths;
407 std::string retMsg;
408 ErrCode ret = bundleManagerProxy->WriteFileToInner(reply, hapFilePaths, realPaths, retMsg);
409 ASSERT_TRUE(ret == EdmReturnErrCode::APPLICATION_INSTALL_FAILED);
410 ASSERT_TRUE(retMsg == "write file to stream failed due to invalid file descriptor");
411 }
412
413 /**
414 * @tc.name: TestWriteFileToInnerSuc
415 * @tc.desc: Test Insatll method with hap file paths.
416 * @tc.type: FUNC
417 */
418 HWTEST_F(BundleManagerProxyTest, TestWriteFileToInnerSuc, TestSize.Level1)
419 {
420 int32_t fd = open(TEST_TARGET_PATH.c_str(), O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
421 MessageParcel reply;
422 reply.WriteFileDescriptor(fd);
423 std::string hapFilePaths = { TEST_PACKAGE_PATH };
424 std::vector<std::string> realPaths;
425 std::string retMsg;
426 ErrCode ret = bundleManagerProxy->WriteFileToInner(reply, hapFilePaths, realPaths, retMsg);
427 ASSERT_TRUE(ret == ERR_OK);
428 }
429
430 /**
431 * @tc.name: GetInstalledBundleInfoListFailed
432 * @tc.desc: Test GetInstalledBundleInfoList reply error
433 * @tc.type: FUNC
434 */
435 HWTEST_F(BundleManagerProxyTest, GetInstalledBundleInfoListFailed, TestSize.Level1)
436 {
437 OHOS::AppExecFwk::ElementName admin;
438 std::vector<EdmBundleInfo> bundleInfos;
439 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
440 .Times(1)
441 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetErrPolicy));
442 ErrCode ret = bundleManagerProxy->GetInstalledBundleInfoList(admin, DEFAULT_USER_ID, bundleInfos);
443 ASSERT_TRUE(ret == EdmReturnErrCode::SYSTEM_ABNORMALLY);
444 ASSERT_TRUE(bundleInfos.size() == 0);
445 }
446
447 /**
448 * @tc.name: GetInstalledBundleInfoListSuccess
449 * @tc.desc: Test GetInstalledBundleInfoList reply OK
450 * @tc.type: FUNC
451 */
452 HWTEST_F(BundleManagerProxyTest, GetInstalledBundleInfoListSuccess, TestSize.Level1)
453 {
454 OHOS::AppExecFwk::ElementName admin;
455 std::vector<EdmBundleInfo> bundleInfos;
456 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
457 .Times(1)
458 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestGetInstalledBundleList));
459 ErrCode ret = bundleManagerProxy->GetInstalledBundleInfoList(admin, DEFAULT_USER_ID, bundleInfos);
460 ASSERT_TRUE(ret == ERR_OK);
461 ASSERT_TRUE(bundleInfos.size() == 1);
462 }
463
464 /**
465 * @tc.name: TestAddInstallationAllowedAppDistributionTypesSuc
466 * @tc.desc: Test AddInstallationAllowedAppDistributionTypes success func.
467 * @tc.type: FUNC
468 */
469 HWTEST_F(BundleManagerProxyTest, TestAddInstallationAllowedAppDistributionTypesSuc, TestSize.Level1)
470 {
471 MessageParcel data;
472 OHOS::AppExecFwk::ElementName admin;
473 admin.SetBundleName(ADMIN_PACKAGENAME);
474 data.WriteParcelable(&admin);
475 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
476 .Times(1)
477 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
478 std::vector<int32_t> inputData;
479 inputData.push_back(APP_DISTRIBUTION_TYPE1);
480 inputData.push_back(APP_DISTRIBUTION_TYPE2);
481 data.WriteInt32Vector(inputData);
482
483 int32_t ret = bundleManagerProxy->AddOrRemoveInstallationAllowedAppDistributionTypes(data, FuncOperateType::SET);
484 ASSERT_TRUE(ret == ERR_OK);
485 }
486
487 /**
488 * @tc.name: TestAddInstallationAllowedAppDistributionTypesFail
489 * @tc.desc: Test AddInstallationAllowedAppDistributionTypes without enable edm service func.
490 * @tc.type: FUNC
491 */
492 HWTEST_F(BundleManagerProxyTest, TestAddInstallationAllowedAppDistributionTypesFail, TestSize.Level1)
493 {
494 Utils::SetEdmServiceDisable();
495 MessageParcel data;
496 OHOS::AppExecFwk::ElementName admin;
497 admin.SetBundleName(ADMIN_PACKAGENAME);
498 data.WriteParcelable(&admin);
499 std::vector<int32_t> inputData;
500 inputData.push_back(APP_DISTRIBUTION_TYPE1);
501 inputData.push_back(APP_DISTRIBUTION_TYPE2);
502 data.WriteInt32Vector(inputData);
503
504 int32_t ret = bundleManagerProxy->AddOrRemoveInstallationAllowedAppDistributionTypes(data, FuncOperateType::SET);
505 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
506 }
507
508 /**
509 * @tc.name: TestRemoveInstallationAllowedAppDistributionTypesSuc
510 * @tc.desc: Test RemoveInstallationAllowedAppDistributionTypes success func.
511 * @tc.type: FUNC
512 */
513 HWTEST_F(BundleManagerProxyTest, TestRemoveInstallationAllowedAppDistributionTypesSuc, TestSize.Level1)
514 {
515 MessageParcel data;
516 OHOS::AppExecFwk::ElementName admin;
517 admin.SetBundleName(ADMIN_PACKAGENAME);
518 data.WriteParcelable(&admin);
519 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
520 .Times(1)
521 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
522 std::vector<int32_t> inputData;
523 inputData.push_back(APP_DISTRIBUTION_TYPE1);
524 inputData.push_back(APP_DISTRIBUTION_TYPE2);
525 data.WriteInt32Vector(inputData);
526
527 int32_t ret = bundleManagerProxy->AddOrRemoveInstallationAllowedAppDistributionTypes(data, FuncOperateType::REMOVE);
528 ASSERT_TRUE(ret == ERR_OK);
529 }
530
531 /**
532 * @tc.name: TestRemoveInstallationAllowedAppDistributionTypesFail
533 * @tc.desc: Test RemoveInstallationAllowedAppDistributionTypes without enable edm service func.
534 * @tc.type: FUNC
535 */
536 HWTEST_F(BundleManagerProxyTest, TestRemoveInstallationAllowedAppDistributionTypesFail, TestSize.Level1)
537 {
538 Utils::SetEdmServiceDisable();
539 MessageParcel data;
540 OHOS::AppExecFwk::ElementName admin;
541 admin.SetBundleName(ADMIN_PACKAGENAME);
542 data.WriteParcelable(&admin);
543 std::vector<int32_t> inputData;
544 inputData.push_back(APP_DISTRIBUTION_TYPE1);
545 inputData.push_back(APP_DISTRIBUTION_TYPE2);
546 data.WriteInt32Vector(inputData);
547
548 int32_t ret = bundleManagerProxy->AddOrRemoveInstallationAllowedAppDistributionTypes(data, FuncOperateType::REMOVE);
549 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
550 }
551
552 /**
553 * @tc.name: TestGetInstallationAllowedAppDistributionTypesSuc
554 * @tc.desc: Test GetInstallationAllowedAppDistributionTypes func.
555 * @tc.type: FUNC
556 */
557 HWTEST_F(BundleManagerProxyTest, TestGetInstallationAllowedAppDistributionTypesSuc, TestSize.Level1)
558 {
559 MessageParcel data;
560 OHOS::AppExecFwk::ElementName admin;
561 admin.SetBundleName(ADMIN_PACKAGENAME);
562 data.WriteParcelable(&admin);
563 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
564 .Times(1)
565 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayIntSendRequestGetPolicy));
566 std::vector<int32_t> allowedAppDistributionTypes;
567 int32_t ret = bundleManagerProxy->GetInstallationAllowedAppDistributionTypes(data, allowedAppDistributionTypes);
568 ASSERT_TRUE(ret == ERR_OK);
569 ASSERT_TRUE(allowedAppDistributionTypes.size() == 2);
570 }
571
572 /**
573 * @tc.name: TestGetInstallationAllowedAppDistributionTypesFail
574 * @tc.desc: Test GetInstallationAllowedAppDistributionTypes func without enable edm service.
575 * @tc.type: FUNC
576 */
577 HWTEST_F(BundleManagerProxyTest, TestGetInstallationAllowedAppDistributionTypesFail, TestSize.Level1)
578 {
579 Utils::SetEdmServiceDisable();
580 MessageParcel data;
581 OHOS::AppExecFwk::ElementName admin;
582 admin.SetBundleName(ADMIN_PACKAGENAME);
583 data.WriteParcelable(&admin);
584
585 std::vector<int32_t> allowedAppDistributionTypes;
586 int32_t ret = bundleManagerProxy->GetInstallationAllowedAppDistributionTypes(data, allowedAppDistributionTypes);
587 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
588 ASSERT_TRUE(allowedAppDistributionTypes.empty());
589 }
590 } // namespace TEST
591 } // namespace EDM
592 } // namespace OHOS
593