1 /*
2 * Copyright (c) 2023-2024 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 <system_ability_definition.h>
19
20 #include "restrictions_proxy.h"
21 #include "edm_sys_manager_mock.h"
22 #include "enterprise_device_mgr_stub_mock.h"
23 #include "utils.h"
24
25 using namespace testing::ext;
26 using namespace testing;
27
28 namespace OHOS {
29 namespace EDM {
30 namespace TEST {
31 const std::string ADMIN_PACKAGENAME = "com.edm.test.demo";
32 const std::string FEATURE_SNAPSHOT_SKIP = "snapshotSkip";
33 class RestrictionsProxyTest : public testing::Test {
34 protected:
35 void SetUp() override;
36
37 void TearDown() override;
38
39 static void TearDownTestSuite(void);
40 std::shared_ptr<RestrictionsProxy> proxy_ = nullptr;
41 std::shared_ptr<EdmSysManager> edmSysManager_ = nullptr;
42 sptr<EnterpriseDeviceMgrStubMock> object_ = nullptr;
43 };
44
SetUp()45 void RestrictionsProxyTest::SetUp()
46 {
47 proxy_ = RestrictionsProxy::GetRestrictionsProxy();
48 edmSysManager_ = std::make_shared<EdmSysManager>();
49 object_ = new (std::nothrow) EnterpriseDeviceMgrStubMock();
50 edmSysManager_->RegisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID, object_);
51 Utils::SetEdmServiceEnable();
52 }
53
TearDown()54 void RestrictionsProxyTest::TearDown()
55 {
56 proxy_.reset();
57 edmSysManager_->UnregisterSystemAbilityOfRemoteObject(ENTERPRISE_DEVICE_MANAGER_SA_ID);
58 object_ = nullptr;
59 Utils::SetEdmServiceDisable();
60 }
61
TearDownTestSuite()62 void RestrictionsProxyTest::TearDownTestSuite()
63 {
64 ASSERT_FALSE(Utils::GetEdmServiceState());
65 std::cout << "EdmServiceState : " << Utils::GetEdmServiceState() << std::endl;
66 }
67
68 /**
69 * @tc.name: TestSetDisallowedPolicySuc
70 * @tc.desc: Test SetDisallowedPolicy success func.
71 * @tc.type: FUNC
72 */
73 HWTEST_F(RestrictionsProxyTest, TestSetDisallowedPolicySuc, TestSize.Level1)
74 {
75 OHOS::AppExecFwk::ElementName admin;
76 admin.SetBundleName(ADMIN_PACKAGENAME);
77 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
78 .Times(1)
79 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
80 int32_t ret = proxy_->SetDisallowedPolicy(admin, true, EdmInterfaceCode::DISABLED_HDC);
81 ASSERT_TRUE(ret == ERR_OK);
82 }
83
84 /**
85 * @tc.name: TestSetDisallowedPolicySuc_01
86 * @tc.desc: Test SetDisallowedPolicy success func.
87 * @tc.type: FUNC
88 */
89 HWTEST_F(RestrictionsProxyTest, TestSetDisallowedPolicySuc_01, TestSize.Level1)
90 {
91 OHOS::AppExecFwk::ElementName admin;
92 admin.SetBundleName(ADMIN_PACKAGENAME);
93 MessageParcel data;
94 data.WriteParcelable(&admin);
95 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
96 .Times(1)
97 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
98 int32_t ret = proxy_->SetDisallowedPolicy(data, EdmInterfaceCode::DISABLED_HDC);
99 ASSERT_TRUE(ret == ERR_OK);
100 }
101
102 /**
103 * @tc.name: TestSetDisallowedPolicyFail
104 * @tc.desc: Test SetDisallowedPolicy without enable edm service func.
105 * @tc.type: FUNC
106 */
107 HWTEST_F(RestrictionsProxyTest, TestSetDisallowedPolicyFail, TestSize.Level1)
108 {
109 Utils::SetEdmServiceDisable();
110 OHOS::AppExecFwk::ElementName admin;
111 admin.SetBundleName(ADMIN_PACKAGENAME);
112 int32_t ret = proxy_->SetDisallowedPolicy(admin, true, EdmInterfaceCode::DISABLED_HDC);
113 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
114 }
115
116 /**
117 * @tc.name: TestSetDisallowedPolicyFail_01
118 * @tc.desc: Test SetDisallowedPolicy without enable edm service func.
119 * @tc.type: FUNC
120 */
121 HWTEST_F(RestrictionsProxyTest, TestSetDisallowedPolicyFail_01, TestSize.Level1)
122 {
123 Utils::SetEdmServiceDisable();
124 OHOS::AppExecFwk::ElementName admin;
125 admin.SetBundleName(ADMIN_PACKAGENAME);
126 MessageParcel data;
127 data.WriteParcelable(&admin);
128 int32_t ret = proxy_->SetDisallowedPolicy(data, EdmInterfaceCode::DISABLED_HDC);
129 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
130 }
131
132 /**
133 * @tc.name: TestGetDisallowedPolicySuc
134 * @tc.desc: Test GetDisallowedPolicy func.
135 * @tc.type: FUNC
136 */
137 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedPolicySuc, TestSize.Level1)
138 {
139 AppExecFwk::ElementName admin;
140 admin.SetBundleName(ADMIN_PACKAGENAME);
141 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
142 .Times(1)
143 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
144 bool result = false;
145 int32_t ret = proxy_->GetDisallowedPolicy(&admin, EdmInterfaceCode::DISABLED_HDC, result);
146 ASSERT_TRUE(ret == ERR_OK);
147 ASSERT_TRUE(result);
148 }
149
150 /**
151 * @tc.name: TestGetDisallowedPolicySuc_01
152 * @tc.desc: Test GetDisallowedPolicy func.
153 * @tc.type: FUNC
154 */
155 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedPolicySuc_01, TestSize.Level1)
156 {
157 AppExecFwk::ElementName admin;
158 admin.SetBundleName(ADMIN_PACKAGENAME);
159 MessageParcel data;
160 data.WriteParcelable(&admin);
161 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
162 .Times(1)
163 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
164 bool result = false;
165 int32_t ret = proxy_->GetDisallowedPolicy(data, EdmInterfaceCode::DISABLED_HDC, result);
166 ASSERT_TRUE(ret == ERR_OK);
167 ASSERT_TRUE(result);
168 }
169
170 /**
171 * @tc.name: TestGetDisallowedPolicyFail
172 * @tc.desc: Test GetDisallowedPolicy func.
173 * @tc.type: FUNC
174 */
175 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedPolicyFail, TestSize.Level1)
176 {
177 Utils::SetEdmServiceDisable();
178 AppExecFwk::ElementName admin;
179 admin.SetBundleName(ADMIN_PACKAGENAME);
180 bool result = false;
181 int32_t ret = proxy_->GetDisallowedPolicy(&admin, EdmInterfaceCode::DISABLED_HDC, result);
182 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
183 }
184
185 /**
186 * @tc.name: TestGetDisallowedPolicyFail_01
187 * @tc.desc: Test GetDisallowedPolicy func.
188 * @tc.type: FUNC
189 */
190 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedPolicyFail_01, TestSize.Level1)
191 {
192 Utils::SetEdmServiceDisable();
193 AppExecFwk::ElementName admin;
194 admin.SetBundleName(ADMIN_PACKAGENAME);
195 MessageParcel data;
196 data.WriteParcelable(&admin);
197 bool result = false;
198 int32_t ret = proxy_->GetDisallowedPolicy(data, EdmInterfaceCode::DISABLED_HDC, result);
199 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
200 }
201
202 /**
203 * @tc.name: TestGetDisallowedPolicyNullptr
204 * @tc.desc: Test GetDisallowedPolicy func.
205 * @tc.type: FUNC
206 */
207 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedPolicyNullptr, TestSize.Level1)
208 {
209 Utils::SetEdmServiceDisable();
210 bool result = false;
211 int32_t ret = proxy_->GetDisallowedPolicy(nullptr, EdmInterfaceCode::DISABLED_HDC, result);
212 ASSERT_TRUE(ret == ERR_OK);
213 }
214
215 /**
216 * @tc.name: TestSetFingerprintAuthDisabledSuc
217 * @tc.desc: Test SetFingerprintAuthDisabled success func.
218 * @tc.type: FUNC
219 */
220 HWTEST_F(RestrictionsProxyTest, TestSetFingerprintAuthDisabledSuc, TestSize.Level1)
221 {
222 OHOS::AppExecFwk::ElementName admin;
223 admin.SetBundleName(ADMIN_PACKAGENAME);
224 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
225 .Times(1)
226 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
227 int32_t ret = proxy_->SetFingerprintAuthDisabled(admin, false);
228 ASSERT_TRUE(ret == ERR_OK);
229 }
230
231 /**
232 * @tc.name: TestSetFingerprintAuthDisabledFail
233 * @tc.desc: Test SetFingerprintAuthDisabled without enable edm service func.
234 * @tc.type: FUNC
235 */
236 HWTEST_F(RestrictionsProxyTest, TestSetFingerprintAuthDisabledFail, TestSize.Level1)
237 {
238 Utils::SetEdmServiceDisable();
239 OHOS::AppExecFwk::ElementName admin;
240 admin.SetBundleName(ADMIN_PACKAGENAME);
241 int32_t ret = proxy_->SetFingerprintAuthDisabled(admin, false);
242 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
243 }
244
245 /**
246 * @tc.name: TestIsFingerprintAuthDisabledSuc
247 * @tc.desc: Test IsFingerprintAuthDisabled func.
248 * @tc.type: FUNC
249 */
250 HWTEST_F(RestrictionsProxyTest, TestIsFingerprintAuthDisabledSuc, TestSize.Level1)
251 {
252 AppExecFwk::ElementName admin;
253 admin.SetBundleName(ADMIN_PACKAGENAME);
254 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
255 .Times(1)
256 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
257 bool result = false;
258 int32_t ret = proxy_->IsFingerprintAuthDisabled(&admin, result);
259 ASSERT_TRUE(ret == ERR_OK);
260 ASSERT_TRUE(result);
261 }
262
263 /**
264 * @tc.name: TestIsFingerprintAuthDisabledFail
265 * @tc.desc: Test IsFingerprintAuthDisabled func.
266 * @tc.type: FUNC
267 */
268 HWTEST_F(RestrictionsProxyTest, TestIsFingerprintAuthDisabledFail, TestSize.Level1)
269 {
270 Utils::SetEdmServiceDisable();
271 AppExecFwk::ElementName admin;
272 admin.SetBundleName(ADMIN_PACKAGENAME);
273 bool result = false;
274 int32_t ret = proxy_->IsFingerprintAuthDisabled(&admin, result);
275 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
276 }
277
278 /**
279 * @tc.name: TestIsFingerprintAuthDisabledNullptr
280 * @tc.desc: Test IsFingerprintAuthDisabled func.
281 * @tc.type: FUNC
282 */
283 HWTEST_F(RestrictionsProxyTest, TestIsFingerprintAuthDisabledNullptr, TestSize.Level1)
284 {
285 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
286 .Times(1)
287 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
288 bool result = false;
289 int32_t ret = proxy_->IsFingerprintAuthDisabled(nullptr, result);
290 ASSERT_TRUE(ret == ERR_OK);
291 ASSERT_TRUE(result);
292 }
293
294 /**
295 * @tc.name: TestSetFingerprintAuthDisallowedPolicyForAccountSuc
296 * @tc.desc: Test SetFingerprintAuthDisallowedPolicyForAccount success func.
297 * @tc.type: FUNC
298 */
299 HWTEST_F(RestrictionsProxyTest, TestSetFingerprintAuthDisallowedPolicyForAccountSuc, TestSize.Level1)
300 {
301 OHOS::AppExecFwk::ElementName admin;
302 admin.SetBundleName(ADMIN_PACKAGENAME);
303 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
304 .Times(1)
305 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
306 int32_t ret = proxy_->SetFingerprintAuthDisallowedPolicyForAccount(admin,
307 EdmInterfaceCode::FINGERPRINT_AUTH, false, WITHOUT_PERMISSION_TAG, 100);
308 ASSERT_TRUE(ret == ERR_OK);
309 }
310
311 /**
312 * @tc.name: TestSetFingerprintAuthDisallowedPolicyForAccountFail
313 * @tc.desc: Test SetFingerprintAuthDisallowedPolicyForAccount without enable edm service func.
314 * @tc.type: FUNC
315 */
316 HWTEST_F(RestrictionsProxyTest, TestSetFingerprintAuthDisallowedPolicyForAccountFail, TestSize.Level1)
317 {
318 Utils::SetEdmServiceDisable();
319 OHOS::AppExecFwk::ElementName admin;
320 admin.SetBundleName(ADMIN_PACKAGENAME);
321 int32_t ret = proxy_->SetFingerprintAuthDisallowedPolicyForAccount(admin,
322 EdmInterfaceCode::FINGERPRINT_AUTH, false, WITHOUT_PERMISSION_TAG, 100);
323 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
324 }
325
326 /**
327 * @tc.name: TestSetDisallowedPolicyForAccountSuc
328 * @tc.desc: Test SetDisallowedPolicyForAccount success func.
329 * @tc.type: FUNC
330 */
331 HWTEST_F(RestrictionsProxyTest, TestSetDisallowedPolicyForAccountSuc, TestSize.Level1)
332 {
333 OHOS::AppExecFwk::ElementName admin;
334 admin.SetBundleName(ADMIN_PACKAGENAME);
335 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
336 .Times(1)
337 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
338 int32_t ret = proxy_->SetDisallowedPolicyForAccount(admin,
339 EdmInterfaceCode::DISABLE_USER_MTP_CLIENT, false, WITHOUT_PERMISSION_TAG, 100);
340 ASSERT_TRUE(ret == ERR_OK);
341 }
342
343 /**
344 * @tc.name: TestSetDisallowedPolicyForAccountFail
345 * @tc.desc: Test SetDisallowedPolicyForAccount without enable edm service func.
346 * @tc.type: FUNC
347 */
348 HWTEST_F(RestrictionsProxyTest, TestSetDisallowedPolicyForAccountFail, TestSize.Level1)
349 {
350 Utils::SetEdmServiceDisable();
351 OHOS::AppExecFwk::ElementName admin;
352 admin.SetBundleName(ADMIN_PACKAGENAME);
353 int32_t ret = proxy_->SetDisallowedPolicyForAccount(admin,
354 EdmInterfaceCode::DISABLE_USER_MTP_CLIENT, false, WITHOUT_PERMISSION_TAG, 100);
355 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
356 }
357
358 /**
359 * @tc.name: TestGetFingerprintAuthDisallowedPolicyForAccountSuc
360 * @tc.desc: Test GetFingerprintAuthDisallowedPolicyForAccount func.
361 * @tc.type: FUNC
362 */
363 HWTEST_F(RestrictionsProxyTest, TestGetFingerprintAuthDisallowedPolicyForAccountSuc, TestSize.Level1)
364 {
365 AppExecFwk::ElementName admin;
366 admin.SetBundleName(ADMIN_PACKAGENAME);
367 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
368 .Times(1)
369 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
370 bool result = true;
371 int32_t ret = proxy_->GetFingerprintAuthDisallowedPolicyForAccount(&admin,
372 EdmInterfaceCode::FINGERPRINT_AUTH, result, WITHOUT_PERMISSION_TAG, 100);
373 ASSERT_TRUE(ret == ERR_OK);
374 ASSERT_TRUE(result);
375 }
376
377 /**
378 * @tc.name: TestGetFingerprintAuthDisallowedPolicyForAccountFail
379 * @tc.desc: Test GetFingerprintAuthDisallowedPolicyForAccount func.
380 * @tc.type: FUNC
381 */
382 HWTEST_F(RestrictionsProxyTest, TestGetFingerprintAuthDisallowedPolicyForAccountFail, TestSize.Level1)
383 {
384 Utils::SetEdmServiceDisable();
385 AppExecFwk::ElementName admin;
386 admin.SetBundleName(ADMIN_PACKAGENAME);
387 bool result = false;
388 int32_t ret = proxy_->GetFingerprintAuthDisallowedPolicyForAccount(&admin,
389 EdmInterfaceCode::FINGERPRINT_AUTH, result, WITHOUT_PERMISSION_TAG, 100);
390 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
391 }
392
393 /**
394 * @tc.name: TestGetDisallowedPolicyForAccountSuc
395 * @tc.desc: Test GetDisallowedPolicyForAccount func.
396 * @tc.type: FUNC
397 */
398 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedPolicyForAccountSuc, TestSize.Level1)
399 {
400 AppExecFwk::ElementName admin;
401 admin.SetBundleName(ADMIN_PACKAGENAME);
402 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
403 .Times(1)
404 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
405 bool result = true;
406 int32_t ret = proxy_->GetDisallowedPolicyForAccount(admin,
407 EdmInterfaceCode::DISABLE_USER_MTP_CLIENT, result, WITHOUT_PERMISSION_TAG, 100);
408 ASSERT_TRUE(ret == ERR_OK);
409 ASSERT_TRUE(result);
410 }
411
412 /**
413 * @tc.name: TestGetDisallowedPolicyForAccountFail
414 * @tc.desc: Test GetDisallowedPolicyForAccount func.
415 * @tc.type: FUNC
416 */
417 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedPolicyForAccountFail, TestSize.Level1)
418 {
419 Utils::SetEdmServiceDisable();
420 AppExecFwk::ElementName admin;
421 admin.SetBundleName(ADMIN_PACKAGENAME);
422 bool result = false;
423 int32_t ret = proxy_->GetDisallowedPolicyForAccount(admin,
424 EdmInterfaceCode::DISABLE_USER_MTP_CLIENT, result, WITHOUT_PERMISSION_TAG, 100);
425 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
426 }
427
428 /**
429 * @tc.name: TestAddDisallowedListForAccountSuc
430 * @tc.desc: Test AddDisallowedListForAccount success func.
431 * @tc.type: FUNC
432 */
433 HWTEST_F(RestrictionsProxyTest, TestAddDisallowedListForAccountSuc, TestSize.Level1)
434 {
435 OHOS::AppExecFwk::ElementName admin;
436 admin.SetBundleName(ADMIN_PACKAGENAME);
437 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
438 .Times(1)
439 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
440 std::vector<std::string> bundles;
441 bundles.emplace_back("aaaa");
442 bundles.emplace_back("bbbb");
443 int32_t ret = proxy_->AddOrRemoveDisallowedListForAccount(admin, FEATURE_SNAPSHOT_SKIP, bundles, 100, true);
444 ASSERT_TRUE(ret == ERR_OK);
445 }
446
447 /**
448 * @tc.name: TestRemoveDisallowedListForAccountSucc
449 * @tc.desc: Test RemoveDisallowedListForAccount success func.
450 * @tc.type: FUNC
451 */
452 HWTEST_F(RestrictionsProxyTest, TestRemoveDisallowedListForAccountSucc, TestSize.Level1)
453 {
454 OHOS::AppExecFwk::ElementName admin;
455 admin.SetBundleName(ADMIN_PACKAGENAME);
456 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
457 .Times(1)
458 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
459 std::vector<std::string> bundles;
460 bundles.emplace_back("aaaa");
461 bundles.emplace_back("bbbb");
462 int32_t ret = proxy_->AddOrRemoveDisallowedListForAccount(admin, FEATURE_SNAPSHOT_SKIP, bundles, 100, false);
463 ASSERT_TRUE(ret == ERR_OK);
464 }
465
466 /**
467 * @tc.name: TestAddDisallowedListForAccountFail
468 * @tc.desc: Test AddDisallowedListForAccount without enable edm service func.
469 * @tc.type: FUNC
470 */
471 HWTEST_F(RestrictionsProxyTest, TestAddDisallowedListForAccountFail, TestSize.Level1)
472 {
473 Utils::SetEdmServiceDisable();
474 OHOS::AppExecFwk::ElementName admin;
475 admin.SetBundleName(ADMIN_PACKAGENAME);
476 std::vector<std::string> bundles;
477 bundles.emplace_back("aaaa");
478 bundles.emplace_back("bbbb");
479 int32_t ret = proxy_->AddOrRemoveDisallowedListForAccount(admin, FEATURE_SNAPSHOT_SKIP, bundles, 100, true);
480 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
481 }
482
483 /**
484 * @tc.name: TestRemoveDisallowedListForAccountFail
485 * @tc.desc: Test RemoveDisallowedListForAccount without enable edm service func.
486 * @tc.type: FUNC
487 */
488 HWTEST_F(RestrictionsProxyTest, TestRemoveDisallowedListForAccountFail, TestSize.Level1)
489 {
490 Utils::SetEdmServiceDisable();
491 OHOS::AppExecFwk::ElementName admin;
492 admin.SetBundleName(ADMIN_PACKAGENAME);
493 std::vector<std::string> bundles;
494 bundles.emplace_back("aaaa");
495 bundles.emplace_back("bbbb");
496 int32_t ret = proxy_->AddOrRemoveDisallowedListForAccount(admin, FEATURE_SNAPSHOT_SKIP, bundles, 100, false);
497 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
498 }
499
500 /**
501 * @tc.name: TestGetDisallowedListForAccountSuc
502 * @tc.desc: Test GetDisallowedListForAccount func.
503 * @tc.type: FUNC
504 */
505 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedListForAccountSuc, TestSize.Level1)
506 {
507 AppExecFwk::ElementName admin;
508 admin.SetBundleName(ADMIN_PACKAGENAME);
509 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
510 .Times(1)
511 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeArrayStringSendRequestGetPolicy));
512 std::vector<std::string> bundles;
513 int32_t ret = proxy_->GetDisallowedListForAccount(admin, FEATURE_SNAPSHOT_SKIP, 100, bundles);
514 ASSERT_TRUE(ret == ERR_OK);
515 ASSERT_TRUE(bundles.size() == 1);
516 ASSERT_TRUE(bundles[0] == RETURN_STRING);
517 }
518
519 /**
520 * @tc.name: TestGetDisallowedListForAccountFail
521 * @tc.desc: Test GetDisallowedListForAccount func.
522 * @tc.type: FUNC
523 */
524 HWTEST_F(RestrictionsProxyTest, TestGetDisallowedListForAccountFail, TestSize.Level1)
525 {
526 Utils::SetEdmServiceDisable();
527 AppExecFwk::ElementName admin;
528 admin.SetBundleName(ADMIN_PACKAGENAME);
529 std::vector<std::string> bundles;
530 int32_t ret = proxy_->GetDisallowedListForAccount(admin, FEATURE_SNAPSHOT_SKIP, 100, bundles);
531 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
532 }
533
534 /**
535 * @tc.name: TestSetUserRestrictionSuc
536 * @tc.desc: Test SetUserRestriction success func.
537 * @tc.type: FUNC
538 */
539 HWTEST_F(RestrictionsProxyTest, TestSetUserRestrictionSuc, TestSize.Level1)
540 {
541 OHOS::AppExecFwk::ElementName admin;
542 admin.SetBundleName(ADMIN_PACKAGENAME);
543 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
544 .Times(1)
545 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
546 int32_t ret = proxy_->SetUserRestriction(admin, true, EdmInterfaceCode::DISALLOW_MODIFY_APN);
547 ASSERT_TRUE(ret == ERR_OK);
548 }
549
550 /**
551 * @tc.name: TestSetUserRestrictionSuc_01
552 * @tc.desc: Test SetUserRestriction success func.
553 * @tc.type: FUNC
554 */
555 HWTEST_F(RestrictionsProxyTest, TestSetUserRestrictionSuc_01, TestSize.Level1)
556 {
557 OHOS::AppExecFwk::ElementName admin;
558 admin.SetBundleName(ADMIN_PACKAGENAME);
559 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
560 .Times(1)
561 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeSendRequestSetPolicy));
562 int32_t ret = proxy_->SetUserRestriction(admin, false, EdmInterfaceCode::DISALLOW_MODIFY_APN);
563 ASSERT_TRUE(ret == ERR_OK);
564 }
565
566 /**
567 * @tc.name: TestSetUserRestrictionFail
568 * @tc.desc: Test SetUserRestriction without enable edm service func.
569 * @tc.type: FUNC
570 */
571 HWTEST_F(RestrictionsProxyTest, TestSetUserRestrictionFail, TestSize.Level1)
572 {
573 Utils::SetEdmServiceDisable();
574 OHOS::AppExecFwk::ElementName admin;
575 admin.SetBundleName(ADMIN_PACKAGENAME);
576 int32_t ret = proxy_->SetUserRestriction(admin, true, EdmInterfaceCode::DISALLOW_MODIFY_APN);
577 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
578 }
579
580 /**
581 * @tc.name: TestGetUserRestrictedSuc
582 * @tc.desc: Test GetUserRestricted success func.
583 * @tc.type: FUNC
584 */
585 HWTEST_F(RestrictionsProxyTest, TestGetUserRestrictedSuc, TestSize.Level1)
586 {
587 OHOS::AppExecFwk::ElementName admin;
588 admin.SetBundleName(ADMIN_PACKAGENAME);
589 bool restricted = false;
590 EXPECT_CALL(*object_, SendRequest(_, _, _, _))
591 .Times(1)
592 .WillOnce(Invoke(object_.GetRefPtr(), &EnterpriseDeviceMgrStubMock::InvokeBoolSendRequestGetPolicy));
593 int32_t ret = proxy_->GetUserRestricted(&admin, EdmInterfaceCode::DISALLOW_MODIFY_ETHERNET_IP, restricted);
594 ASSERT_TRUE(ret == ERR_OK);
595 }
596
597 /**
598 * @tc.name: TestGetUserRestrictedFail
599 * @tc.desc: Test GetUserRestricted without enable edm service func.
600 * @tc.type: FUNC
601 */
602 HWTEST_F(RestrictionsProxyTest, TestGetUserRestrictedFail, TestSize.Level1)
603 {
604 Utils::SetEdmServiceDisable();
605 OHOS::AppExecFwk::ElementName admin;
606 admin.SetBundleName(ADMIN_PACKAGENAME);
607 bool restricted = false;
608 int32_t ret = proxy_->GetUserRestricted(&admin, EdmInterfaceCode::DISALLOW_MODIFY_ETHERNET_IP, restricted);
609 ASSERT_TRUE(ret == EdmReturnErrCode::ADMIN_INACTIVE);
610 }
611 } // namespace TEST
612 } // namespace EDM
613 } // namespace OHOS
614