• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022-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 "user_idm_client_test.h"
17 
18 #include "iam_ptr.h"
19 #include "user_idm_client.h"
20 #include "user_idm_client_impl.h"
21 
22 namespace OHOS {
23 namespace UserIam {
24 namespace UserAuth {
25 using namespace testing;
26 using namespace testing::ext;
27 
SetUpTestCase()28 void UserIdmClientTest::SetUpTestCase()
29 {
30 }
31 
TearDownTestCase()32 void UserIdmClientTest::TearDownTestCase()
33 {
34 }
35 
SetUp()36 void UserIdmClientTest::SetUp()
37 {
38 }
39 
TearDown()40 void UserIdmClientTest::TearDown()
41 {
42 }
43 
44 HWTEST_F(UserIdmClientTest, UserIdmClientOpenSession001, TestSize.Level0)
45 {
46     int32_t testUserId = 21200;
47 
48     IpcClientUtils::ResetObj();
49     std::vector<uint8_t> challenge = UserIdmClient::GetInstance().OpenSession(testUserId);
50     EXPECT_TRUE(challenge.empty());
51 }
52 
53 HWTEST_F(UserIdmClientTest, UserIdmClientOpenSession002, TestSize.Level0)
54 {
55     int32_t testUserId = 21200;
56     std::vector<uint8_t> testChallenge = {1, 3, 4, 7};
57 
58     auto service = Common::MakeShared<MockUserIdmService>();
59     EXPECT_NE(service, nullptr);
60     EXPECT_CALL(*service, OpenSession(_, _)).Times(1);
61     ON_CALL(*service, OpenSession)
62         .WillByDefault(
__anond43cba230102(int32_t userId, std::vector<uint8_t> &challenge) 63             [&testUserId, &testChallenge](int32_t userId, std::vector<uint8_t> &challenge) {
64                 EXPECT_EQ(userId, testUserId);
65                 challenge = testChallenge;
66                 return SUCCESS;
67             }
68         );
69     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
70     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
71     CallRemoteObject(service, obj, dr);
72 
73     std::vector<uint8_t> challenge = UserIdmClient::GetInstance().OpenSession(testUserId);
74     EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
75     EXPECT_NE(dr, nullptr);
76     dr->OnRemoteDied(obj);
77     IpcClientUtils::ResetObj();
78 }
79 
80 HWTEST_F(UserIdmClientTest, UserIdmClientCloseSession001, TestSize.Level0)
81 {
82     int32_t testUserId = 200;
83 
84     IpcClientUtils::ResetObj();
85     EXPECT_NO_THROW(UserIdmClient::GetInstance().CloseSession(testUserId));
86 }
87 
88 HWTEST_F(UserIdmClientTest, UserIdmClientCloseSession002, TestSize.Level0)
89 {
90     int32_t testUserId = 200;
91 
92     auto service = Common::MakeShared<MockUserIdmService>();
93     EXPECT_NE(service, nullptr);
94     EXPECT_CALL(*service, CloseSession(_)).Times(1);
95     ON_CALL(*service, CloseSession)
96         .WillByDefault(
__anond43cba230202(int32_t userId) 97             [&testUserId](int32_t userId) {
98                 EXPECT_EQ(userId, testUserId);
99                 return;
100             }
101         );
102     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
103     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
104     CallRemoteObject(service, obj, dr);
105 
106     UserIdmClient::GetInstance().CloseSession(testUserId);
107     EXPECT_NE(dr, nullptr);
108     dr->OnRemoteDied(obj);
109     IpcClientUtils::ResetObj();
110 }
111 
112 HWTEST_F(UserIdmClientTest, UserIdmClientCloseSession003, TestSize.Level0)
113 {
114     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
115     EXPECT_NE(obj, nullptr);
116     EXPECT_CALL(*obj, IsProxyObject()).WillRepeatedly(Return(true));
117 
118     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
119     EXPECT_CALL(*obj, RemoveDeathRecipient(_)).WillRepeatedly(Return(true));
120     EXPECT_CALL(*obj, AddDeathRecipient(_))
121         .WillOnce(Return(false))
__anond43cba230302(const sptr<IRemoteObject::DeathRecipient> &recipient) 122         .WillRepeatedly([&dr](const sptr<IRemoteObject::DeathRecipient> &recipient) {
123             dr = recipient;
124             return true;
125         });
126 
127     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).WillRepeatedly(Return(OHOS::NO_ERROR));
128 
129     IpcClientUtils::SetObj(obj);
130 
131     int32_t testUserId = 1326;
132     UserIdmClient::GetInstance().CloseSession(testUserId);
133     UserIdmClient::GetInstance().CloseSession(testUserId);
134     UserIdmClient::GetInstance().CloseSession(testUserId);
135 
136     EXPECT_NE(dr, nullptr);
137     sptr<IRemoteObject> remote(nullptr);
138     dr->OnRemoteDied(remote);
139     dr->OnRemoteDied(obj);
140     IpcClientUtils::ResetObj();
141 }
142 
143 HWTEST_F(UserIdmClientTest, UserIdmClientAddCredential001, TestSize.Level0)
144 {
145     int32_t testUserId = 200;
146     CredentialParameters testPara = {};
147     std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
148     UserIdmClient::GetInstance().AddCredential(testUserId, testPara, testCallback);
149 
150     testCallback = Common::MakeShared<MockUserIdmClientCallback>();
151     EXPECT_NE(testCallback, nullptr);
152     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
153     IpcClientUtils::ResetObj();
154     UserIdmClient::GetInstance().AddCredential(testUserId, testPara, testCallback);
155 }
156 
157 HWTEST_F(UserIdmClientTest, UserIdmClientAddCredential002, TestSize.Level0)
158 {
159     int32_t testUserId = 200;
160     CredentialParameters testPara = {};
161     testPara.authType = FACE;
162     testPara.pinType = std::nullopt;
163     testPara.token = {1, 4, 7, 0};
164     auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
165     EXPECT_NE(testCallback, nullptr);
166     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
167 
168     auto service = Common::MakeShared<MockUserIdmService>();
169     EXPECT_NE(service, nullptr);
170     EXPECT_CALL(*service, AddCredential(_, _, _, _)).Times(1);
171     ON_CALL(*service, AddCredential)
172         .WillByDefault(
173             [&testUserId, &testPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anond43cba230402(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback, bool isUpdate) 174                 const sptr<IdmCallbackInterface> &callback, bool isUpdate) {
175                 EXPECT_EQ(userId, testUserId);
176                 EXPECT_EQ(credPara.authType, testPara.authType);
177                 EXPECT_THAT(credPara.token, ElementsAreArray(testPara.token));
178                 EXPECT_EQ(isUpdate, false);
179                 if (callback != nullptr) {
180                     Attributes extraInfo;
181                     callback->OnResult(SUCCESS, extraInfo);
182                 }
183             }
184         );
185     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
186     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
187     CallRemoteObject(service, obj, dr);
188 
189     UserIdmClient::GetInstance().AddCredential(testUserId, testPara, testCallback);
190     EXPECT_NE(dr, nullptr);
191     dr->OnRemoteDied(obj);
192     IpcClientUtils::ResetObj();
193 }
194 
195 HWTEST_F(UserIdmClientTest, UserIdmClientUpdateCredential001, TestSize.Level0)
196 {
197     int32_t testUserId = 200;
198     CredentialParameters testPara = {};
199     std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
200     UserIdmClient::GetInstance().UpdateCredential(testUserId, testPara, testCallback);
201 
202     testCallback = Common::MakeShared<MockUserIdmClientCallback>();
203     EXPECT_NE(testCallback, nullptr);
204     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
205     IpcClientUtils::ResetObj();
206     UserIdmClient::GetInstance().UpdateCredential(testUserId, testPara, testCallback);
207 }
208 
209 HWTEST_F(UserIdmClientTest, UserIdmClientUpdateCredential002, TestSize.Level0)
210 {
211     int32_t testUserId = 200;
212     CredentialParameters testPara = {};
213     testPara.authType = PIN;
214     testPara.pinType = PIN_SIX;
215     testPara.token = {1, 4, 7, 0};
216     auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
217     EXPECT_NE(testCallback, nullptr);
218     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
219 
220     auto service = Common::MakeShared<MockUserIdmService>();
221     EXPECT_NE(service, nullptr);
222     EXPECT_CALL(*service, UpdateCredential(_, _, _)).Times(1);
223     ON_CALL(*service, UpdateCredential)
224         .WillByDefault(
225             [&testUserId, &testPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anond43cba230502(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback) 226                 const sptr<IdmCallbackInterface> &callback) {
227                 EXPECT_EQ(userId, testUserId);
228                 EXPECT_EQ(credPara.authType, testPara.authType);
229                 EXPECT_TRUE(testPara.pinType.has_value());
230                 EXPECT_EQ(credPara.pinType, testPara.pinType.value());
231                 EXPECT_THAT(credPara.token, ElementsAreArray(testPara.token));
232                 if (callback != nullptr) {
233                     Attributes extraInfo;
234                     callback->OnResult(SUCCESS, extraInfo);
235                 }
236             }
237         );
238     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
239     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
240     CallRemoteObject(service, obj, dr);
241 
242     UserIdmClient::GetInstance().UpdateCredential(testUserId, testPara, testCallback);
243     EXPECT_NE(dr, nullptr);
244     dr->OnRemoteDied(obj);
245     IpcClientUtils::ResetObj();
246 }
247 
248 HWTEST_F(UserIdmClientTest, UserIdmClientCancel001, TestSize.Level0)
249 {
250     int32_t testUserId = 200;
251 
252     IpcClientUtils::ResetObj();
253     int32_t ret = UserIdmClient::GetInstance().Cancel(testUserId);
254     EXPECT_EQ(ret, GENERAL_ERROR);
255 }
256 
257 HWTEST_F(UserIdmClientTest, UserIdmClientCancel002, TestSize.Level0)
258 {
259     int32_t testUserId = 200;
260 
261     auto service = Common::MakeShared<MockUserIdmService>();
262     EXPECT_NE(service, nullptr);
263     EXPECT_CALL(*service, Cancel(_)).Times(1);
264     ON_CALL(*service, Cancel)
265         .WillByDefault(
__anond43cba230602(int32_t userId) 266             [&testUserId](int32_t userId) {
267                 EXPECT_EQ(userId, testUserId);
268                 return SUCCESS;
269             }
270         );
271     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
272     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
273     CallRemoteObject(service, obj, dr);
274 
275     int32_t ret = UserIdmClient::GetInstance().Cancel(testUserId);
276     EXPECT_EQ(ret, SUCCESS);
277     EXPECT_NE(dr, nullptr);
278     dr->OnRemoteDied(obj);
279     IpcClientUtils::ResetObj();
280 }
281 
282 HWTEST_F(UserIdmClientTest, UserIdmClientDeleteCredential001, TestSize.Level0)
283 {
284     int32_t testUserId = 200;
285     uint64_t testCredentialId = 111;
286     std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
287     std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
288     UserIdmClient::GetInstance().DeleteCredential(testUserId, testCredentialId, testAuthToken, testCallback);
289 
290     IpcClientUtils::ResetObj();
291     testCallback = Common::MakeShared<MockUserIdmClientCallback>();
292     EXPECT_NE(testCallback, nullptr);
293     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
294     UserIdmClient::GetInstance().DeleteCredential(testUserId, testCredentialId, testAuthToken, testCallback);
295 }
296 
297 HWTEST_F(UserIdmClientTest, UserIdmClientDeleteCredential002, TestSize.Level0)
298 {
299     int32_t testUserId = 200;
300     uint64_t testCredentialId = 111;
301     std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
302     auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
303     EXPECT_NE(testCallback, nullptr);
304     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
305 
306     auto service = Common::MakeShared<MockUserIdmService>();
307     EXPECT_NE(service, nullptr);
308     EXPECT_CALL(*service, DelCredential(_, _, _, _)).Times(1);
309     ON_CALL(*service, DelCredential)
310         .WillByDefault(
311             [&testUserId, &testCredentialId, &testAuthToken](int32_t userId, uint64_t credentialId,
__anond43cba230702(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) 312                 const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) {
313                 EXPECT_EQ(userId, testUserId);
314                 EXPECT_EQ(credentialId, testCredentialId);
315                 EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
316                 if (callback != nullptr) {
317                     Attributes extraInfo;
318                     callback->OnResult(SUCCESS, extraInfo);
319                 }
320             }
321         );
322     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
323     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
324     CallRemoteObject(service, obj, dr);
325 
326     UserIdmClient::GetInstance().DeleteCredential(testUserId, testCredentialId, testAuthToken, testCallback);
327     EXPECT_NE(dr, nullptr);
328     dr->OnRemoteDied(obj);
329     IpcClientUtils::ResetObj();
330 }
331 
332 HWTEST_F(UserIdmClientTest, UserIdmClientDeleteUser001, TestSize.Level0)
333 {
334     int32_t testUserId = 200;
335     std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
336     std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
337     UserIdmClient::GetInstance().DeleteUser(testUserId, testAuthToken, testCallback);
338 
339     IpcClientUtils::ResetObj();
340     testCallback = Common::MakeShared<MockUserIdmClientCallback>();
341     EXPECT_NE(testCallback, nullptr);
342     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
343     UserIdmClient::GetInstance().DeleteUser(testUserId, testAuthToken, testCallback);
344 }
345 
346 HWTEST_F(UserIdmClientTest, UserIdmClientDeleteUser002, TestSize.Level0)
347 {
348     int32_t testUserId = 200;
349     std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
350     auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
351     EXPECT_NE(testCallback, nullptr);
352     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
353 
354     auto service = Common::MakeShared<MockUserIdmService>();
355     EXPECT_NE(service, nullptr);
356     EXPECT_CALL(*service, DelUser(_, _, _)).Times(1);
357     ON_CALL(*service, DelUser)
358         .WillByDefault(
359             [&testUserId, &testAuthToken](int32_t userId, const std::vector<uint8_t> authToken,
__anond43cba230802(int32_t userId, const std::vector<uint8_t> authToken, const sptr<IdmCallbackInterface> &callback) 360                 const sptr<IdmCallbackInterface> &callback) {
361                 EXPECT_EQ(userId, testUserId);
362                 EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
363                 if (callback != nullptr) {
364                     Attributes extraInfo;
365                     callback->OnResult(SUCCESS, extraInfo);
366                 }
367             }
368         );
369     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
370     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
371     CallRemoteObject(service, obj, dr);
372 
373     UserIdmClient::GetInstance().DeleteUser(testUserId, testAuthToken, testCallback);
374     EXPECT_NE(dr, nullptr);
375     dr->OnRemoteDied(obj);
376     IpcClientUtils::ResetObj();
377 }
378 
379 HWTEST_F(UserIdmClientTest, UserIdmClientEraseUser001, TestSize.Level0)
380 {
381     int32_t testUserId = 200;
382     std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
383     int32_t ret = UserIdmClient::GetInstance().EraseUser(testUserId, testCallback);
384     EXPECT_EQ(ret, GENERAL_ERROR);
385 
386     IpcClientUtils::ResetObj();
387     testCallback = Common::MakeShared<MockUserIdmClientCallback>();
388     EXPECT_NE(testCallback, nullptr);
389     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
390     ret = UserIdmClient::GetInstance().EraseUser(testUserId, testCallback);
391     EXPECT_EQ(ret, GENERAL_ERROR);
392 }
393 
394 HWTEST_F(UserIdmClientTest, UserIdmClientEraseUser002, TestSize.Level0)
395 {
396     int32_t testUserId = 200;
397     auto testCallback = Common::MakeShared<MockUserIdmClientCallback>();
398     EXPECT_NE(testCallback, nullptr);
399     EXPECT_CALL(*testCallback, OnResult(_, _)).Times(1);
400 
401     auto service = Common::MakeShared<MockUserIdmService>();
402     EXPECT_NE(service, nullptr);
403     EXPECT_CALL(*service, EnforceDelUser(_, _)).Times(1);
404     ON_CALL(*service, EnforceDelUser)
405         .WillByDefault(
__anond43cba230902(int32_t userId, const sptr<IdmCallbackInterface> &callback) 406             [&testUserId](int32_t userId, const sptr<IdmCallbackInterface> &callback) {
407                 EXPECT_EQ(userId, testUserId);
408                 if (callback != nullptr) {
409                     Attributes extraInfo;
410                     callback->OnResult(SUCCESS, extraInfo);
411                 }
412                 return SUCCESS;
413             }
414         );
415     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
416     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
417     CallRemoteObject(service, obj, dr);
418 
419     int32_t ret = UserIdmClient::GetInstance().EraseUser(testUserId, testCallback);
420     EXPECT_EQ(ret, SUCCESS);
421     EXPECT_NE(dr, nullptr);
422     dr->OnRemoteDied(obj);
423     IpcClientUtils::ResetObj();
424 }
425 
426 HWTEST_F(UserIdmClientTest, UserIdmClientGetCredentialInfo001, TestSize.Level0)
427 {
428     int32_t testUserId = 200;
429     AuthType testAuthType = PIN;
430     std::shared_ptr<MockGetCredentialInfoCallback> testCallback = nullptr;
431     int32_t ret = UserIdmClient::GetInstance().GetCredentialInfo(testUserId, testAuthType, testCallback);
432     EXPECT_EQ(ret, GENERAL_ERROR);
433 
434     IpcClientUtils::ResetObj();
435     testCallback = Common::MakeShared<MockGetCredentialInfoCallback>();
436     EXPECT_NE(testCallback, nullptr);
437     EXPECT_CALL(*testCallback, OnCredentialInfo(_, _)).Times(1);
438     ret = UserIdmClient::GetInstance().GetCredentialInfo(testUserId, testAuthType, testCallback);
439     EXPECT_EQ(ret, GENERAL_ERROR);
440 }
441 
442 HWTEST_F(UserIdmClientTest, UserIdmClientGetCredentialInfo002, TestSize.Level0)
443 {
444     int32_t testUserId = 200;
445     AuthType testAuthType = PIN;
446     auto testCallback = Common::MakeShared<MockGetCredentialInfoCallback>();
447     EXPECT_NE(testCallback, nullptr);
448     EXPECT_CALL(*testCallback, OnCredentialInfo(_, _)).Times(1);
449 
450     auto service = Common::MakeShared<MockUserIdmService>();
451     EXPECT_NE(service, nullptr);
452     EXPECT_CALL(*service, GetCredentialInfo(_, _, _)).Times(1);
453     ON_CALL(*service, GetCredentialInfo)
454         .WillByDefault(
455             [&testUserId, &testAuthType](int32_t userId, AuthType authType,
__anond43cba230a02(int32_t userId, AuthType authType, const sptr<IdmGetCredInfoCallbackInterface> &callback) 456                 const sptr<IdmGetCredInfoCallbackInterface> &callback) {
457                 EXPECT_EQ(userId, testUserId);
458                 EXPECT_EQ(authType, testAuthType);
459                 if (callback != nullptr) {
460                     std::vector<CredentialInfo> credInfoList;
461                     callback->OnCredentialInfos(SUCCESS, credInfoList);
462                 }
463                 return SUCCESS;
464             }
465         );
466     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
467     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
468     CallRemoteObject(service, obj, dr);
469 
470     int32_t ret = UserIdmClient::GetInstance().GetCredentialInfo(testUserId, testAuthType, testCallback);
471     EXPECT_EQ(ret, SUCCESS);
472     EXPECT_NE(dr, nullptr);
473     dr->OnRemoteDied(obj);
474     IpcClientUtils::ResetObj();
475 }
476 
477 HWTEST_F(UserIdmClientTest, UserIdmClientGetSecUserInfo001, TestSize.Level0)
478 {
479     int32_t testUserId = 200;
480     std::shared_ptr<MockGetSecUserInfoCallback> testCallback = nullptr;
481     int32_t ret = UserIdmClient::GetInstance().GetSecUserInfo(testUserId, testCallback);
482     EXPECT_EQ(ret, GENERAL_ERROR);
483 
484     IpcClientUtils::ResetObj();
485     testCallback = Common::MakeShared<MockGetSecUserInfoCallback>();
486     EXPECT_NE(testCallback, nullptr);
487     EXPECT_CALL(*testCallback, OnSecUserInfo(_, _)).Times(1);
488     ret = UserIdmClient::GetInstance().GetSecUserInfo(testUserId, testCallback);
489     EXPECT_EQ(ret, GENERAL_ERROR);
490 }
491 
492 HWTEST_F(UserIdmClientTest, UserIdmClientGetSecUserInfo002, TestSize.Level0)
493 {
494     int32_t testUserId = 200;
495     auto testCallback = Common::MakeShared<MockGetSecUserInfoCallback>();
496     EXPECT_NE(testCallback, nullptr);
497 
498     auto service = Common::MakeShared<MockUserIdmService>();
499     EXPECT_NE(service, nullptr);
500     EXPECT_CALL(*service, GetSecInfo(_, _)).Times(1);
501     ON_CALL(*service, GetSecInfo)
502         .WillByDefault(
__anond43cba230b02(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) 503             [&testUserId](int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) {
504                 EXPECT_EQ(userId, testUserId);
505                 EXPECT_NE(callback, nullptr);
506                 return SUCCESS;
507             }
508         );
509     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
510     sptr<IRemoteObject::DeathRecipient> dr(nullptr);
511     CallRemoteObject(service, obj, dr);
512 
513     int32_t ret = UserIdmClient::GetInstance().GetSecUserInfo(testUserId, testCallback);
514     EXPECT_EQ(ret, SUCCESS);
515     EXPECT_NE(dr, nullptr);
516     dr->OnRemoteDied(obj);
517     IpcClientUtils::ResetObj();
518 }
519 
520 HWTEST_F(UserIdmClientTest, UserIdmClientImplClearRedundancyCredential, TestSize.Level0)
521 {
522     std::shared_ptr<MockUserIdmClientCallback> testCallback = nullptr;
523     testCallback = Common::MakeShared<MockUserIdmClientCallback>();
524     EXPECT_NE(testCallback, nullptr);
525     EXPECT_NO_THROW(UserIdmClient::GetInstance().ClearRedundancyCredential(testCallback));
526 }
527 
CallRemoteObject(const std::shared_ptr<MockUserIdmService> service,const sptr<MockRemoteObject> & obj,sptr<IRemoteObject::DeathRecipient> & dr)528 void UserIdmClientTest::CallRemoteObject(const std::shared_ptr<MockUserIdmService> service,
529     const sptr<MockRemoteObject> &obj, sptr<IRemoteObject::DeathRecipient> &dr)
530 {
531     EXPECT_NE(obj, nullptr);
532     EXPECT_CALL(*obj, IsProxyObject()).WillRepeatedly(Return(true));
533     EXPECT_CALL(*obj, RemoveDeathRecipient(_)).WillRepeatedly(Return(true));
534     EXPECT_CALL(*obj, AddDeathRecipient(_))
535         .WillRepeatedly([&dr](const sptr<IRemoteObject::DeathRecipient> &recipient) {
536             dr = recipient;
537             return true;
538         });
539 
540     IpcClientUtils::SetObj(obj);
541     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
542     ON_CALL(*obj, SendRequest)
543         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
544             service->OnRemoteRequest(code, data, reply, option);
545             return OHOS::NO_ERROR;
546         });
547 }
548 } // namespace UserAuth
549 } // namespace UserIam
550 } // namespace OHOS