• 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 "user_idm_proxy_test.h"
17 
18 #include "iam_ptr.h"
19 #include "user_idm_proxy.h"
20 #include "mock_remote_object.h"
21 #include "mock_user_idm_service.h"
22 #include "mock_user_idm_client_callback.h"
23 #include "user_idm_callback_service.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 using namespace testing;
29 using namespace testing::ext;
30 
SetUpTestCase()31 void UserIdmProxyTest::SetUpTestCase()
32 {
33 }
34 
TearDownTestCase()35 void UserIdmProxyTest::TearDownTestCase()
36 {
37 }
38 
SetUp()39 void UserIdmProxyTest::SetUp()
40 {
41 }
42 
TearDown()43 void UserIdmProxyTest::TearDown()
44 {
45 }
46 
47 HWTEST_F(UserIdmProxyTest, UserIdmProxyOpenSession, TestSize.Level0)
48 {
49     static const int32_t testUserId = 200;
50     std::vector<uint8_t> testChallenge;
51 
52     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
53     EXPECT_NE(obj, nullptr);
54     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
55     EXPECT_NE(proxy, nullptr);
56     auto service = Common::MakeShared<MockUserIdmService>();
57     EXPECT_NE(service, nullptr);
58     EXPECT_CALL(*service, OpenSession(_, _))
59         .Times(Exactly(1))
__anon5f864a060102(int32_t userId, std::vector<uint8_t> &challenge) 60         .WillOnce([](int32_t userId, std::vector<uint8_t> &challenge) {
61             EXPECT_EQ(testUserId, userId);
62             return SUCCESS;
63         });
64     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
65     ON_CALL(*obj, SendRequest)
__anon5f864a060202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 66         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
67             service->OnRemoteRequest(code, data, reply, option);
68             return SUCCESS;
69         });
70     proxy->OpenSession(testUserId, testChallenge);
71 }
72 
73 HWTEST_F(UserIdmProxyTest, UserIdmProxyCloseSession, TestSize.Level0)
74 {
75     static const int32_t testUserId = 200;
76 
77     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
78     EXPECT_NE(obj, nullptr);
79     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
80     EXPECT_NE(proxy, nullptr);
81     auto service = Common::MakeShared<MockUserIdmService>();
82     EXPECT_NE(service, nullptr);
83     EXPECT_CALL(*service, CloseSession(_))
84         .Times(Exactly(1))
__anon5f864a060302(int32_t userId) 85         .WillOnce([](int32_t userId) {
86             EXPECT_EQ(testUserId, userId);
87             return SUCCESS;
88         });
89     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
90     ON_CALL(*obj, SendRequest)
__anon5f864a060402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 91         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
92             service->OnRemoteRequest(code, data, reply, option);
93             return SUCCESS;
94         });
95     proxy->CloseSession(testUserId);
96 }
97 
98 HWTEST_F(UserIdmProxyTest, UserIdmProxyGetCredentialInfo001, TestSize.Level0)
99 {
100     static const int32_t testUserId = 200;
101     static const AuthType testAuthType = PIN;
102 
103     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
104     EXPECT_NE(obj, nullptr);
105     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
106     EXPECT_NE(proxy, nullptr);
107     auto getCredInfoCallback = Common::MakeShared<MockGetCredentialInfoCallback>();
108     EXPECT_NE(getCredInfoCallback, nullptr);
109     sptr<IdmGetCredInfoCallbackInterface> testCallback(
110         new (std::nothrow) IdmGetCredInfoCallbackService(getCredInfoCallback));
111     auto service = Common::MakeShared<MockUserIdmService>();
112     EXPECT_NE(service, nullptr);
113     EXPECT_CALL(*service, GetCredentialInfo(_, _, _))
114         .Times(Exactly(1))
115         .WillOnce([&testCallback](int32_t userId, AuthType authType,
__anon5f864a060502(int32_t userId, AuthType authType, const sptr<IdmGetCredInfoCallbackInterface> &callback) 116             const sptr<IdmGetCredInfoCallbackInterface> &callback) {
117             EXPECT_EQ(testUserId, userId);
118             EXPECT_EQ(testAuthType, authType);
119             EXPECT_EQ(testCallback, callback);
120             return SUCCESS;
121         });
122     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
123     ON_CALL(*obj, SendRequest)
__anon5f864a060602(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 124         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
125             service->OnRemoteRequest(code, data, reply, option);
126             return SUCCESS;
127         });
128     EXPECT_EQ(proxy->GetCredentialInfo(testUserId, testAuthType, testCallback), SUCCESS);
129 }
130 
131 HWTEST_F(UserIdmProxyTest, UserIdmProxyGetCredentialInfo002, TestSize.Level0)
132 {
133     static const int32_t testUserId = 200;
134     static const AuthType testAuthType = PIN;
135 
136     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
137     EXPECT_NE(obj, nullptr);
138     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
139     EXPECT_NE(proxy, nullptr);
140     EXPECT_EQ(proxy->GetCredentialInfo(testUserId, testAuthType, nullptr), GENERAL_ERROR);
141 }
142 
143 HWTEST_F(UserIdmProxyTest, UserIdmProxyGetSecInfo001, TestSize.Level0)
144 {
145     static const int32_t testUserId = 200;
146 
147     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
148     EXPECT_NE(obj, nullptr);
149     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
150     EXPECT_NE(proxy, nullptr);
151     auto getSecInfoCallback = Common::MakeShared<MockGetSecUserInfoCallback>();
152     EXPECT_NE(getSecInfoCallback, nullptr);
153     sptr<IdmGetSecureUserInfoCallbackInterface> testCallback(
154         new (std::nothrow) IdmGetSecureUserInfoCallbackService(getSecInfoCallback));
155     auto service = Common::MakeShared<MockUserIdmService>();
156     EXPECT_NE(service, nullptr);
157     EXPECT_CALL(*service, GetSecInfo(_, _))
158         .Times(Exactly(1))
__anon5f864a060702(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) 159         .WillOnce([&testCallback](int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) {
160             EXPECT_EQ(testUserId, userId);
161             EXPECT_EQ(testCallback, callback);
162             return SUCCESS;
163         });
164     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
165     ON_CALL(*obj, SendRequest)
__anon5f864a060802(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 166         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
167             service->OnRemoteRequest(code, data, reply, option);
168             return SUCCESS;
169         });
170     EXPECT_EQ(proxy->GetSecInfo(testUserId, testCallback), SUCCESS);
171 }
172 
173 HWTEST_F(UserIdmProxyTest, UserIdmProxyGetSecInfo002, TestSize.Level0)
174 {
175     static const int32_t testUserId = 200;
176 
177     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
178     EXPECT_NE(obj, nullptr);
179     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
180     EXPECT_NE(proxy, nullptr);
181     EXPECT_EQ(proxy->GetSecInfo(testUserId, nullptr), GENERAL_ERROR);
182 }
183 
184 HWTEST_F(UserIdmProxyTest, UserIdmProxyAddCredential001, TestSize.Level0)
185 {
186     static const int32_t testUserId = 200;
187     UserIdmInterface::CredentialPara testCredPara = {};
188     testCredPara.authType = FACE;
189     testCredPara.pinType = PIN_SIX;
190     testCredPara.token = {1, 2, 3, 4};
191 
192     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
193     EXPECT_NE(obj, nullptr);
194     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
195     EXPECT_NE(proxy, nullptr);
196     auto idmCallback = Common::MakeShared<MockUserIdmClientCallback>();
197     EXPECT_NE(idmCallback, nullptr);
198     sptr<IdmCallbackInterface> testCallback(new (std::nothrow) IdmCallbackService(idmCallback));
199     auto service = Common::MakeShared<MockUserIdmService>();
200     EXPECT_NE(service, nullptr);
201     EXPECT_CALL(*service, AddCredential(_, _, _, _))
202         .Times(Exactly(1))
203         .WillOnce([&testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anon5f864a060902(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback, bool isUpdate) 204             const sptr<IdmCallbackInterface> &callback, bool isUpdate) {
205             EXPECT_EQ(userId, testUserId);
206             EXPECT_EQ(credPara.authType, testCredPara.authType);
207             EXPECT_EQ(credPara.pinType, testCredPara.pinType);
208             EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token));
209             return SUCCESS;
210         });
211     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
212     ON_CALL(*obj, SendRequest)
__anon5f864a060a02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 213         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
214             service->OnRemoteRequest(code, data, reply, option);
215             return SUCCESS;
216         });
217     proxy->AddCredential(testUserId, testCredPara, testCallback, false);
218 }
219 
220 HWTEST_F(UserIdmProxyTest, UserIdmProxyAddCredential002, TestSize.Level0)
221 {
222     static const int32_t testUserId = 200;
223     UserIdmInterface::CredentialPara testCredPara = {};
224     testCredPara.authType = FACE;
225     testCredPara.pinType = PIN_SIX;
226     testCredPara.token = {1, 2, 3, 4};
227 
228     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
229     EXPECT_NE(obj, nullptr);
230     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
231     EXPECT_NE(proxy, nullptr);
232     proxy->AddCredential(testUserId, testCredPara, nullptr, false);
233 }
234 
235 HWTEST_F(UserIdmProxyTest, UserIdmProxyUpdateCredential001, TestSize.Level0)
236 {
237     static const int32_t testUserId = 200;
238     UserIdmInterface::CredentialPara testCredPara = {};
239     testCredPara.authType = FACE;
240     testCredPara.pinType = PIN_SIX;
241     testCredPara.token = {1, 2, 3, 4};
242 
243     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
244     EXPECT_NE(obj, nullptr);
245     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
246     EXPECT_NE(proxy, nullptr);
247     auto idmCallback = Common::MakeShared<MockUserIdmClientCallback>();
248     EXPECT_NE(idmCallback, nullptr);
249     sptr<IdmCallbackInterface> testCallback(new (std::nothrow) IdmCallbackService(idmCallback));
250     auto service = Common::MakeShared<MockUserIdmService>();
251     EXPECT_NE(service, nullptr);
252     EXPECT_CALL(*service, UpdateCredential(_, _, _))
253         .Times(Exactly(1))
254         .WillOnce([&testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anon5f864a060b02(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback) 255             const sptr<IdmCallbackInterface> &callback) {
256             EXPECT_EQ(userId, testUserId);
257             EXPECT_EQ(credPara.authType, testCredPara.authType);
258             EXPECT_EQ(credPara.pinType, testCredPara.pinType);
259             EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token));
260             return SUCCESS;
261         });
262     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
263     ON_CALL(*obj, SendRequest)
__anon5f864a060c02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 264         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
265             service->OnRemoteRequest(code, data, reply, option);
266             return SUCCESS;
267         });
268     proxy->UpdateCredential(testUserId, testCredPara, testCallback);
269 }
270 
271 HWTEST_F(UserIdmProxyTest, UserIdmProxyUpdateCredential002, TestSize.Level0)
272 {
273     static const int32_t testUserId = 200;
274     UserIdmInterface::CredentialPara testCredPara = {};
275     testCredPara.authType = FACE;
276     testCredPara.pinType = PIN_SIX;
277     testCredPara.token = {1, 2, 3, 4};
278 
279     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
280     EXPECT_NE(obj, nullptr);
281     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
282     EXPECT_NE(proxy, nullptr);
283     proxy->UpdateCredential(testUserId, testCredPara, nullptr);
284 }
285 
286 HWTEST_F(UserIdmProxyTest, UserIdmProxyCancel, TestSize.Level0)
287 {
288     static const int32_t testUserId = 200;
289 
290     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
291     EXPECT_NE(obj, nullptr);
292     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
293     EXPECT_NE(proxy, nullptr);
294     auto service = Common::MakeShared<MockUserIdmService>();
295     EXPECT_NE(service, nullptr);
296     EXPECT_CALL(*service, Cancel(_))
297         .Times(Exactly(1))
__anon5f864a060d02(int32_t userId) 298         .WillOnce([](int32_t userId) {
299             EXPECT_EQ(testUserId, userId);
300             return SUCCESS;
301         });
302     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
303     ON_CALL(*obj, SendRequest)
__anon5f864a060e02(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 304         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
305             service->OnRemoteRequest(code, data, reply, option);
306             return SUCCESS;
307         });
308     proxy->Cancel(testUserId);
309 }
310 
311 HWTEST_F(UserIdmProxyTest, UserIdmProxyEnforceDelUser001, TestSize.Level0)
312 {
313     static const int32_t testUserId = 200;
314 
315     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
316     EXPECT_NE(obj, nullptr);
317     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
318     EXPECT_NE(proxy, nullptr);
319     auto idmCallback = Common::MakeShared<MockUserIdmClientCallback>();
320     EXPECT_NE(idmCallback, nullptr);
321     sptr<IdmCallbackInterface> testCallback(new (std::nothrow) IdmCallbackService(idmCallback));
322     auto service = Common::MakeShared<MockUserIdmService>();
323     EXPECT_NE(service, nullptr);
324     EXPECT_CALL(*service, EnforceDelUser(_, _))
325         .Times(Exactly(1))
__anon5f864a060f02(int32_t userId, const sptr<IdmCallbackInterface> &callback) 326         .WillOnce([&testCallback](int32_t userId, const sptr<IdmCallbackInterface> &callback) {
327             EXPECT_EQ(testUserId, userId);
328             EXPECT_EQ(testCallback, callback);
329             return SUCCESS;
330         });
331     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
332     ON_CALL(*obj, SendRequest)
__anon5f864a061002(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 333         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
334             service->OnRemoteRequest(code, data, reply, option);
335             return SUCCESS;
336         });
337     EXPECT_EQ(proxy->EnforceDelUser(testUserId, testCallback), SUCCESS);
338 }
339 
340 HWTEST_F(UserIdmProxyTest, UserIdmProxyEnforceDelUser002, TestSize.Level0)
341 {
342     static const int32_t testUserId = 200;
343 
344     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
345     EXPECT_NE(obj, nullptr);
346     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
347     EXPECT_NE(proxy, nullptr);
348     EXPECT_EQ(proxy->EnforceDelUser(testUserId, nullptr), GENERAL_ERROR);
349 }
350 
351 HWTEST_F(UserIdmProxyTest, UserIdmProxyDelUser001, TestSize.Level0)
352 {
353     static const int32_t testUserId = 200;
354     static const std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
355 
356     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
357     EXPECT_NE(obj, nullptr);
358     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
359     EXPECT_NE(proxy, nullptr);
360     auto idmCallback = Common::MakeShared<MockUserIdmClientCallback>();
361     EXPECT_NE(idmCallback, nullptr);
362     sptr<IdmCallbackInterface> testCallback(new (std::nothrow) IdmCallbackService(idmCallback));
363     auto service = Common::MakeShared<MockUserIdmService>();
364     EXPECT_NE(service, nullptr);
365     EXPECT_CALL(*service, DelUser(_, _, _))
366         .Times(Exactly(1))
367         .WillOnce([&testCallback](int32_t userId, const std::vector<uint8_t> authToken,
__anon5f864a061102(int32_t userId, const std::vector<uint8_t> authToken, const sptr<IdmCallbackInterface> &callback) 368             const sptr<IdmCallbackInterface> &callback) {
369             EXPECT_EQ(testUserId, userId);
370             EXPECT_THAT(testAuthToken, ElementsAre(1, 2, 3, 4));
371             EXPECT_EQ(testCallback, callback);
372             return SUCCESS;
373         });
374     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
375     ON_CALL(*obj, SendRequest)
__anon5f864a061202(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 376         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
377             service->OnRemoteRequest(code, data, reply, option);
378             return SUCCESS;
379         });
380     proxy->DelUser(testUserId, testAuthToken, testCallback);
381 }
382 
383 HWTEST_F(UserIdmProxyTest, UserIdmProxyDelUser002, TestSize.Level0)
384 {
385     static const int32_t testUserId = 200;
386     static const std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
387 
388     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
389     EXPECT_NE(obj, nullptr);
390     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
391     EXPECT_NE(proxy, nullptr);
392     proxy->DelUser(testUserId, testAuthToken, nullptr);
393 }
394 
395 HWTEST_F(UserIdmProxyTest, UserIdmProxyDelCredential001, TestSize.Level0)
396 {
397     static const int32_t testUserId = 200;
398     static const uint64_t testCredentialId = 300;
399     static const std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
400 
401     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
402     EXPECT_NE(obj, nullptr);
403     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
404     EXPECT_NE(proxy, nullptr);
405     auto idmCallback = Common::MakeShared<MockUserIdmClientCallback>();
406     EXPECT_NE(idmCallback, nullptr);
407     sptr<IdmCallbackInterface> testCallback(new (std::nothrow) IdmCallbackService(idmCallback));
408     auto service = Common::MakeShared<MockUserIdmService>();
409     EXPECT_NE(service, nullptr);
410     EXPECT_CALL(*service, DelCredential(_, _, _, _))
411         .Times(Exactly(1))
412         .WillOnce([&testCallback](int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken,
__anon5f864a061302(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) 413             const sptr<IdmCallbackInterface> &callback) {
414             EXPECT_EQ(testUserId, userId);
415             EXPECT_EQ(testCredentialId, credentialId);
416             EXPECT_THAT(testAuthToken, ElementsAre(1, 2, 3, 4));
417             EXPECT_EQ(testCallback, callback);
418             return SUCCESS;
419         });
420     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
421     ON_CALL(*obj, SendRequest)
__anon5f864a061402(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 422         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
423             service->OnRemoteRequest(code, data, reply, option);
424             return SUCCESS;
425         });
426     proxy->DelCredential(testUserId, testCredentialId, testAuthToken, testCallback);
427 }
428 
429 HWTEST_F(UserIdmProxyTest, UserIdmProxyDelCredential002, TestSize.Level0)
430 {
431     static const int32_t testUserId = 200;
432     static const uint64_t testCredentialId = 300;
433     static const std::vector<uint8_t> testAuthToken = {1, 2, 3, 4};
434 
435     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
436     EXPECT_NE(obj, nullptr);
437     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
438     EXPECT_NE(proxy, nullptr);
439     proxy->DelCredential(testUserId, testCredentialId, testAuthToken, nullptr);
440 }
441 
442 HWTEST_F(UserIdmProxyTest, UserIdmProxyClearRedundancyCredential001, TestSize.Level0)
443 {
444     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
445     EXPECT_NE(obj, nullptr);
446     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
447     EXPECT_NE(proxy, nullptr);
448     auto idmCallback = Common::MakeShared<MockUserIdmClientCallback>();
449     EXPECT_NE(idmCallback, nullptr);
450     sptr<IdmCallbackInterface> testCallback(new (std::nothrow) IdmCallbackService(idmCallback));
451     auto service = Common::MakeShared<MockUserIdmService>();
452     EXPECT_NE(service, nullptr);
453     EXPECT_CALL(*service, ClearRedundancyCredential(_))
454         .Times(Exactly(1))
__anon5f864a061502(const sptr<IdmCallbackInterface> &callback) 455         .WillOnce([&testCallback](const sptr<IdmCallbackInterface> &callback) {
456             return SUCCESS;
457         });
458     EXPECT_CALL(*obj, SendRequest(_, _, _, _)).Times(1);
459     ON_CALL(*obj, SendRequest)
__anon5f864a061602(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 460         .WillByDefault([&service](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
461             service->OnRemoteRequest(code, data, reply, option);
462             return SUCCESS;
463         });
464     proxy->ClearRedundancyCredential(testCallback);
465 }
466 
467 HWTEST_F(UserIdmProxyTest, UserIdmProxyClearRedundancyCredential002, TestSize.Level0)
468 {
469     sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
470     EXPECT_NE(obj, nullptr);
471     auto proxy = Common::MakeShared<UserIdmProxy>(obj);
472     EXPECT_NE(proxy, nullptr);
473     auto idmCallback = Common::MakeShared<MockUserIdmClientCallback>();
474     proxy->ClearRedundancyCredential(nullptr);
475 }
476 } // namespace UserAuth
477 } // namespace UserIam
478 } // namespace OHOS