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_stub_test.h"
17
18 #include "credential_info_interface.h"
19 #include "iam_common_defines.h"
20 #include "securec.h"
21 #include "user_idm_callback_proxy.h"
22 #include "user_idm_stub.h"
23
24 #include "mock_secure_user_info.h"
25 #include "mock_user_idm_callback.h"
26 #include "mock_user_idm_service.h"
27
28 namespace OHOS {
29 namespace UserIam {
30 namespace UserAuth {
31 using namespace testing;
32 using namespace testing::ext;
33
SetUpTestCase()34 void UserIdmStubTest::SetUpTestCase()
35 {
36 }
37
TearDownTestCase()38 void UserIdmStubTest::TearDownTestCase()
39 {
40 }
41
SetUp()42 void UserIdmStubTest::SetUp()
43 {
44 }
45
TearDown()46 void UserIdmStubTest::TearDown()
47 {
48 }
49
50 HWTEST_F(UserIdmStubTest, UserIdmStubOpenSessionStub001, TestSize.Level0)
51 {
52 MessageParcel data;
53 MessageParcel reply;
54 MessageOption option(MessageOption::TF_SYNC);
55 uint32_t code = UserIdmInterfaceCode::USER_IDM_OPEN_SESSION;
56
57 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
58
59 MockUserIdmService service;
60 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
61 }
62
63 HWTEST_F(UserIdmStubTest, UserIdmStubOpenSessionStub002, TestSize.Level0)
64 {
65 int32_t testUserId = 887436;
66 std::vector<uint8_t> testChallenge = {1, 2, 8, 4};
67
68 MockUserIdmService service;
69 EXPECT_CALL(service, OpenSession(_, _)).Times(1);
70 ON_CALL(service, OpenSession)
71 .WillByDefault(
__anonb36e4f710102(int32_t userId, std::vector<uint8_t> &challenge) 72 [&testUserId, &testChallenge](int32_t userId, std::vector<uint8_t> &challenge) {
73 EXPECT_EQ(userId, testUserId);
74 challenge = testChallenge;
75 return SUCCESS;
76 }
77 );
78
79 MessageParcel data;
80 MessageParcel reply;
81 MessageOption option(MessageOption::TF_SYNC);
82 uint32_t code = UserIdmInterfaceCode::USER_IDM_OPEN_SESSION;
83
84 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
85 EXPECT_TRUE(data.WriteInt32(testUserId));
86
87 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
88
89 std::vector<uint8_t> challenge;
90 EXPECT_TRUE(reply.ReadUInt8Vector(&challenge));
91 EXPECT_THAT(challenge, ElementsAreArray(testChallenge));
92 }
93
94 HWTEST_F(UserIdmStubTest, UserIdmStubCloseSessionStub001, TestSize.Level0)
95 {
96 MessageParcel data;
97 MessageParcel reply;
98 MessageOption option(MessageOption::TF_SYNC);
99 uint32_t code = UserIdmInterfaceCode::USER_IDM_CLOSE_SESSION;
100
101 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
102
103 MockUserIdmService service;
104 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
105 }
106
107 HWTEST_F(UserIdmStubTest, UserIdmStubCloseSessionStub002, TestSize.Level0)
108 {
109 int32_t testUserId = 887436;
110
111 MockUserIdmService service;
112 EXPECT_CALL(service, CloseSession(_)).Times(1);
113 ON_CALL(service, CloseSession)
114 .WillByDefault(
__anonb36e4f710202(int32_t userId) 115 [&testUserId](int32_t userId) {
116 EXPECT_EQ(userId, testUserId);
117 return;
118 }
119 );
120
121 MessageParcel data;
122 MessageParcel reply;
123 MessageOption option(MessageOption::TF_SYNC);
124 uint32_t code = UserIdmInterfaceCode::USER_IDM_CLOSE_SESSION;
125
126 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
127 EXPECT_TRUE(data.WriteInt32(testUserId));
128
129 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
130 }
131
132 HWTEST_F(UserIdmStubTest, UserIdmStubGetCredentialInfoStub001, TestSize.Level0)
133 {
134 MessageParcel data;
135 MessageParcel reply;
136 MessageOption option(MessageOption::TF_SYNC);
137 uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_CRED_INFO;
138
139 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
140
141 MockUserIdmService service;
142 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
143 }
144
145 HWTEST_F(UserIdmStubTest, UserIdmStubGetCredentialInfoStub002, TestSize.Level0)
146 {
147 int32_t testUserId = 76255;
148 AuthType testAuthType = FACE;
149
150 sptr<MockIdmGetCredentialInfoCallback> callback(new (std::nothrow) MockIdmGetCredentialInfoCallback());
151 EXPECT_NE(callback, nullptr);
152 MockUserIdmService service;
153 EXPECT_CALL(service, GetCredentialInfo(_, _, _)).Times(1);
154 ON_CALL(service, GetCredentialInfo)
155 .WillByDefault(
156 [&testUserId, &testAuthType](int32_t userId, AuthType authType,
__anonb36e4f710302(int32_t userId, AuthType authType, const sptr<IdmGetCredInfoCallbackInterface> &callback) 157 const sptr<IdmGetCredInfoCallbackInterface> &callback) {
158 EXPECT_EQ(userId, testUserId);
159 EXPECT_EQ(authType, testAuthType);
160 if (callback != nullptr) {
161 std::vector<CredentialInfo> credInfoList;
162 callback->OnCredentialInfos(SUCCESS, credInfoList);
163 }
164 return SUCCESS;
165 }
166 );
167 EXPECT_CALL(*callback, OnCredentialInfos(_, _)).Times(1);
168
169 MessageParcel data;
170 MessageParcel reply;
171 MessageOption option(MessageOption::TF_SYNC);
172 uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_CRED_INFO;
173
174 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
175 EXPECT_TRUE(data.WriteInt32(testUserId));
176 EXPECT_TRUE(data.WriteUint32(testAuthType));
177 EXPECT_NE(callback->AsObject(), nullptr);
178 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
179
180 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
181
182 int32_t result = FAIL;
183 EXPECT_TRUE(reply.ReadInt32(result));
184 EXPECT_EQ(result, SUCCESS);
185 }
186
187 HWTEST_F(UserIdmStubTest, UserIdmStubGetSecInfoStub001, TestSize.Level0)
188 {
189 MessageParcel data;
190 MessageParcel reply;
191 MessageOption option(MessageOption::TF_SYNC);
192 uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_SEC_INFO;
193
194 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
195
196 MockUserIdmService service;
197 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
198 }
199
200 HWTEST_F(UserIdmStubTest, UserIdmStubGetSecInfoStub002, TestSize.Level0)
201 {
202 int32_t testUserId = 87463;
203
204 sptr<MockIdmGetSecureUserInfoCallback> callback(new (std::nothrow) MockIdmGetSecureUserInfoCallback());
205 EXPECT_NE(callback, nullptr);
206 MockUserIdmService service;
207 EXPECT_CALL(service, GetSecInfo(_, _)).Times(1);
208 ON_CALL(service, GetSecInfo)
209 .WillByDefault(
__anonb36e4f710402(int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) 210 [&testUserId](int32_t userId, const sptr<IdmGetSecureUserInfoCallbackInterface> &callback) {
211 EXPECT_EQ(userId, testUserId);
212 if (callback != nullptr) {
213 SecUserInfo secUserInfo = {};
214 int32_t result = 0;
215 callback->OnSecureUserInfo(result, secUserInfo);
216 }
217 return SUCCESS;
218 }
219 );
220 EXPECT_CALL(*callback, OnSecureUserInfo(_, _)).Times(1);
221
222 MessageParcel data;
223 MessageParcel reply;
224 MessageOption option(MessageOption::TF_SYNC);
225 uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_SEC_INFO;
226
227 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
228 EXPECT_TRUE(data.WriteInt32(testUserId));
229 EXPECT_NE(callback->AsObject(), nullptr);
230 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
231
232 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
233
234 int32_t result = FAIL;
235 EXPECT_TRUE(reply.ReadInt32(result));
236 EXPECT_EQ(result, SUCCESS);
237 }
238
239 HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub001, TestSize.Level0)
240 {
241 MessageParcel data;
242 MessageParcel reply;
243 MessageOption option(MessageOption::TF_SYNC);
244 uint32_t code = UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL;
245
246 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
247
248 MockUserIdmService service;
249 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
250 }
251
252 HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub002, TestSize.Level0)
253 {
254 int32_t testUserId = 753662;
255 UserIdmInterface::CredentialPara testCredPara = {};
256 testCredPara.authType = FACE;
257 testCredPara.pinType = PIN_SIX;
258 testCredPara.token = {2, 4, 6, 8};
259
260 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
261 EXPECT_NE(callback, nullptr);
262 MockUserIdmService service;
263 EXPECT_CALL(service, AddCredential(_, _, _, _)).Times(1);
264 ON_CALL(service, AddCredential)
265 .WillByDefault(
266 [&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anonb36e4f710502(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback, bool isUpdate) 267 const sptr<IdmCallbackInterface> &callback, bool isUpdate) {
268 EXPECT_EQ(userId, testUserId);
269 EXPECT_EQ(credPara.authType, testCredPara.authType);
270 EXPECT_EQ(credPara.pinType, testCredPara.pinType);
271 EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token));
272 if (callback != nullptr) {
273 Attributes attr;
274 callback->OnResult(SUCCESS, attr);
275 }
276 }
277 );
278 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
279
280 MessageParcel data;
281 MessageParcel reply;
282 MessageOption option(MessageOption::TF_SYNC);
283 uint32_t code = UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL;
284
285 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
286 EXPECT_TRUE(data.WriteInt32(testUserId));
287 EXPECT_TRUE(data.WriteInt32(testCredPara.authType));
288 EXPECT_TRUE(data.WriteInt32(testCredPara.pinType));
289 EXPECT_TRUE(data.WriteUInt8Vector(testCredPara.token));
290 EXPECT_NE(callback->AsObject(), nullptr);
291 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
292
293 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
294 }
295
296 HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub001, TestSize.Level0)
297 {
298 MessageParcel data;
299 MessageParcel reply;
300 MessageOption option(MessageOption::TF_SYNC);
301 uint32_t code = UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL;
302
303 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
304
305 MockUserIdmService service;
306 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
307 }
308
309 HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub002, TestSize.Level0)
310 {
311 int32_t testUserId = 63526;
312 UserIdmInterface::CredentialPara testCredPara = {};
313 testCredPara.authType = PIN;
314 testCredPara.pinType = PIN_SIX;
315 testCredPara.token = {1, 2, 4, 6, 8};
316
317 const sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
318 EXPECT_NE(callback, nullptr);
319 MockUserIdmService service;
320 EXPECT_CALL(service, UpdateCredential(_, _, _)).Times(1);
321 ON_CALL(service, UpdateCredential)
322 .WillByDefault(
323 [&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anonb36e4f710602(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback) 324 const sptr<IdmCallbackInterface> &callback) {
325 EXPECT_EQ(userId, testUserId);
326 EXPECT_EQ(credPara.authType, testCredPara.authType);
327 EXPECT_EQ(credPara.pinType, testCredPara.pinType);
328 EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token));
329 if (callback != nullptr) {
330 Attributes attr;
331 callback->OnResult(SUCCESS, attr);
332 }
333 }
334 );
335 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
336
337 MessageParcel data;
338 MessageParcel reply;
339 MessageOption option(MessageOption::TF_SYNC);
340 uint32_t code = UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL;
341
342 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
343 EXPECT_TRUE(data.WriteInt32(testUserId));
344 EXPECT_TRUE(data.WriteInt32(testCredPara.authType));
345 EXPECT_TRUE(data.WriteInt32(testCredPara.pinType));
346 EXPECT_TRUE(data.WriteUInt8Vector(testCredPara.token));
347 EXPECT_NE(callback->AsObject(), nullptr);
348 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
349
350 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
351 }
352
353 HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub001, TestSize.Level0)
354 {
355 MessageParcel data;
356 MessageParcel reply;
357 MessageOption option(MessageOption::TF_SYNC);
358 uint32_t code = UserIdmInterfaceCode::USER_IDM_CANCEL;
359
360 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
361
362 MockUserIdmService service;
363 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
364 }
365
366 HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub002, TestSize.Level0)
367 {
368 int32_t testUserId = 725345;
369
370 MockUserIdmService service;
371 EXPECT_CALL(service, Cancel(_)).Times(1);
372 ON_CALL(service, Cancel)
373 .WillByDefault(
__anonb36e4f710702(int32_t userId) 374 [&testUserId](int32_t userId) {
375 EXPECT_EQ(userId, testUserId);
376 return SUCCESS;
377 }
378 );
379
380 MessageParcel data;
381 MessageParcel reply;
382 MessageOption option(MessageOption::TF_SYNC);
383 uint32_t code = UserIdmInterfaceCode::USER_IDM_CANCEL;
384
385 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
386 EXPECT_TRUE(data.WriteInt32(testUserId));
387
388 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
389
390 int32_t result = FAIL;
391 EXPECT_TRUE(reply.ReadInt32(result));
392 EXPECT_EQ(result, SUCCESS);
393 }
394
395 HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub001, TestSize.Level0)
396 {
397 MessageParcel data;
398 MessageParcel reply;
399 MessageOption option(MessageOption::TF_SYNC);
400 uint32_t code = UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER;
401
402 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
403
404 MockUserIdmService service;
405 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
406 }
407
408 HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub002, TestSize.Level0)
409 {
410 int32_t testUserId = 83462;
411
412 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
413 EXPECT_NE(callback, nullptr);
414 MockUserIdmService service;
415 EXPECT_CALL(service, EnforceDelUser(_, _)).Times(1);
416 ON_CALL(service, EnforceDelUser)
417 .WillByDefault(
__anonb36e4f710802(int32_t userId, const sptr<IdmCallbackInterface> &callback) 418 [&testUserId](int32_t userId, const sptr<IdmCallbackInterface> &callback) {
419 EXPECT_EQ(userId, testUserId);
420 if (callback != nullptr) {
421 Attributes attr;
422 callback->OnResult(SUCCESS, attr);
423 }
424 return SUCCESS;
425 }
426 );
427 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
428
429 MessageParcel data;
430 MessageParcel reply;
431 MessageOption option(MessageOption::TF_SYNC);
432 uint32_t code = UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER;
433
434 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
435 EXPECT_TRUE(data.WriteInt32(testUserId));
436 EXPECT_NE(callback->AsObject(), nullptr);
437 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
438
439 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
440
441 int32_t result = FAIL;
442 EXPECT_TRUE(reply.ReadInt32(result));
443 EXPECT_EQ(result, SUCCESS);
444 }
445
446 HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub001, TestSize.Level0)
447 {
448 MessageParcel data;
449 MessageParcel reply;
450 MessageOption option(MessageOption::TF_SYNC);
451 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_USER;
452
453 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
454
455 MockUserIdmService service;
456 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
457 }
458
459 HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub002, TestSize.Level0)
460 {
461 int32_t testUserId = 72342;
462 std::vector<uint8_t> testAuthToken = {1, 3, 5, 7};
463
464 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
465 EXPECT_NE(callback, nullptr);
466 MockUserIdmService service;
467 EXPECT_CALL(service, DelUser(_, _, _)).Times(1);
468 ON_CALL(service, DelUser)
469 .WillByDefault(
470 [&testUserId, &testAuthToken](int32_t userId, const std::vector<uint8_t> authToken,
__anonb36e4f710902(int32_t userId, const std::vector<uint8_t> authToken, const sptr<IdmCallbackInterface> &callback) 471 const sptr<IdmCallbackInterface> &callback) {
472 EXPECT_EQ(userId, testUserId);
473 EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
474 if (callback != nullptr) {
475 Attributes attr;
476 callback->OnResult(SUCCESS, attr);
477 }
478 }
479 );
480 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
481
482 MessageParcel data;
483 MessageParcel reply;
484 MessageOption option(MessageOption::TF_SYNC);
485 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_USER;
486
487 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
488 EXPECT_TRUE(data.WriteInt32(testUserId));
489 EXPECT_TRUE(data.WriteUInt8Vector(testAuthToken));
490 EXPECT_NE(callback->AsObject(), nullptr);
491 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
492
493 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
494 }
495
496 HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub001, TestSize.Level0)
497 {
498 MessageParcel data;
499 MessageParcel reply;
500 MessageOption option(MessageOption::TF_SYNC);
501 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_CRED;
502
503 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
504
505 MockUserIdmService service;
506 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
507 }
508
509 HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub002, TestSize.Level0)
510 {
511 int32_t testUserId = 93261;
512 uint64_t testCredentialId = 72632;
513 std::vector<uint8_t> testAuthToken = {3, 5, 7, 9};
514
515 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
516 EXPECT_NE(callback, nullptr);
517 MockUserIdmService service;
518 EXPECT_CALL(service, DelCredential(_, _, _, _)).Times(1);
519 ON_CALL(service, DelCredential)
520 .WillByDefault(
521 [&testUserId, &testCredentialId, &testAuthToken](int32_t userId, uint64_t credentialId,
__anonb36e4f710a02(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) 522 const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) {
523 EXPECT_EQ(userId, testUserId);
524 EXPECT_EQ(credentialId, testCredentialId);
525 EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
526 if (callback != nullptr) {
527 Attributes attr;
528 callback->OnResult(SUCCESS, attr);
529 }
530 }
531 );
532 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
533
534 MessageParcel data;
535 MessageParcel reply;
536 MessageOption option(MessageOption::TF_SYNC);
537 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_CRED;
538
539 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
540 EXPECT_TRUE(data.WriteInt32(testUserId));
541 EXPECT_TRUE(data.WriteUint64(testCredentialId));
542 EXPECT_TRUE(data.WriteUInt8Vector(testAuthToken));
543 EXPECT_NE(callback->AsObject(), nullptr);
544 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
545
546 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
547 }
548 } // namespace UserAuth
549 } // namespace UserIam
550 } // namespace OHOS