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(
__anon847c91690102(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(
__anon847c91690202(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,
__anon847c91690302(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(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(
__anon847c91690402(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 callback->OnSecureUserInfo(secUserInfo);
215 }
216 return SUCCESS;
217 }
218 );
219 EXPECT_CALL(*callback, OnSecureUserInfo(_)).Times(1);
220
221 MessageParcel data;
222 MessageParcel reply;
223 MessageOption option(MessageOption::TF_SYNC);
224 uint32_t code = UserIdmInterfaceCode::USER_IDM_GET_SEC_INFO;
225
226 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
227 EXPECT_TRUE(data.WriteInt32(testUserId));
228 EXPECT_NE(callback->AsObject(), nullptr);
229 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
230
231 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
232
233 int32_t result = FAIL;
234 EXPECT_TRUE(reply.ReadInt32(result));
235 EXPECT_EQ(result, SUCCESS);
236 }
237
238 HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub001, TestSize.Level0)
239 {
240 MessageParcel data;
241 MessageParcel reply;
242 MessageOption option(MessageOption::TF_SYNC);
243 uint32_t code = UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL;
244
245 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
246
247 MockUserIdmService service;
248 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
249 }
250
251 HWTEST_F(UserIdmStubTest, UserIdmStubAddCredentialStub002, TestSize.Level0)
252 {
253 int32_t testUserId = 753662;
254 UserIdmInterface::CredentialPara testCredPara = {};
255 testCredPara.authType = FACE;
256 testCredPara.pinType = PIN_SIX;
257 testCredPara.token = {2, 4, 6, 8};
258
259 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
260 EXPECT_NE(callback, nullptr);
261 MockUserIdmService service;
262 EXPECT_CALL(service, AddCredential(_, _, _, _)).Times(1);
263 ON_CALL(service, AddCredential)
264 .WillByDefault(
265 [&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anon847c91690502(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback, bool isUpdate) 266 const sptr<IdmCallbackInterface> &callback, bool isUpdate) {
267 EXPECT_EQ(userId, testUserId);
268 EXPECT_EQ(credPara.authType, testCredPara.authType);
269 EXPECT_EQ(credPara.pinType, testCredPara.pinType);
270 EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token));
271 if (callback != nullptr) {
272 Attributes attr;
273 callback->OnResult(SUCCESS, attr);
274 }
275 }
276 );
277 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
278
279 MessageParcel data;
280 MessageParcel reply;
281 MessageOption option(MessageOption::TF_SYNC);
282 uint32_t code = UserIdmInterfaceCode::USER_IDM_ADD_CREDENTIAL;
283
284 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
285 EXPECT_TRUE(data.WriteInt32(testUserId));
286 EXPECT_TRUE(data.WriteInt32(testCredPara.authType));
287 EXPECT_TRUE(data.WriteInt32(testCredPara.pinType));
288 EXPECT_TRUE(data.WriteUInt8Vector(testCredPara.token));
289 EXPECT_NE(callback->AsObject(), nullptr);
290 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
291
292 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
293 }
294
295 HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub001, TestSize.Level0)
296 {
297 MessageParcel data;
298 MessageParcel reply;
299 MessageOption option(MessageOption::TF_SYNC);
300 uint32_t code = UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL;
301
302 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
303
304 MockUserIdmService service;
305 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
306 }
307
308 HWTEST_F(UserIdmStubTest, UserIdmStubUpdateCredentialStub002, TestSize.Level0)
309 {
310 int32_t testUserId = 63526;
311 UserIdmInterface::CredentialPara testCredPara = {};
312 testCredPara.authType = PIN;
313 testCredPara.pinType = PIN_SIX;
314 testCredPara.token = {1, 2, 4, 6, 8};
315
316 const sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
317 EXPECT_NE(callback, nullptr);
318 MockUserIdmService service;
319 EXPECT_CALL(service, UpdateCredential(_, _, _)).Times(1);
320 ON_CALL(service, UpdateCredential)
321 .WillByDefault(
322 [&testUserId, &testCredPara](int32_t userId, const UserIdmInterface::CredentialPara &credPara,
__anon847c91690602(int32_t userId, const UserIdmInterface::CredentialPara &credPara, const sptr<IdmCallbackInterface> &callback) 323 const sptr<IdmCallbackInterface> &callback) {
324 EXPECT_EQ(userId, testUserId);
325 EXPECT_EQ(credPara.authType, testCredPara.authType);
326 EXPECT_EQ(credPara.pinType, testCredPara.pinType);
327 EXPECT_THAT(credPara.token, ElementsAreArray(testCredPara.token));
328 if (callback != nullptr) {
329 Attributes attr;
330 callback->OnResult(SUCCESS, attr);
331 }
332 }
333 );
334 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
335
336 MessageParcel data;
337 MessageParcel reply;
338 MessageOption option(MessageOption::TF_SYNC);
339 uint32_t code = UserIdmInterfaceCode::USER_IDM_UPDATE_CREDENTIAL;
340
341 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
342 EXPECT_TRUE(data.WriteInt32(testUserId));
343 EXPECT_TRUE(data.WriteInt32(testCredPara.authType));
344 EXPECT_TRUE(data.WriteInt32(testCredPara.pinType));
345 EXPECT_TRUE(data.WriteUInt8Vector(testCredPara.token));
346 EXPECT_NE(callback->AsObject(), nullptr);
347 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
348
349 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
350 }
351
352 HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub001, TestSize.Level0)
353 {
354 MessageParcel data;
355 MessageParcel reply;
356 MessageOption option(MessageOption::TF_SYNC);
357 uint32_t code = UserIdmInterfaceCode::USER_IDM_CANCEL;
358
359 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
360
361 MockUserIdmService service;
362 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
363 }
364
365 HWTEST_F(UserIdmStubTest, UserIdmStubCancelStub002, TestSize.Level0)
366 {
367 int32_t testUserId = 725345;
368
369 MockUserIdmService service;
370 EXPECT_CALL(service, Cancel(_)).Times(1);
371 ON_CALL(service, Cancel)
372 .WillByDefault(
__anon847c91690702(int32_t userId) 373 [&testUserId](int32_t userId) {
374 EXPECT_EQ(userId, testUserId);
375 return SUCCESS;
376 }
377 );
378
379 MessageParcel data;
380 MessageParcel reply;
381 MessageOption option(MessageOption::TF_SYNC);
382 uint32_t code = UserIdmInterfaceCode::USER_IDM_CANCEL;
383
384 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
385 EXPECT_TRUE(data.WriteInt32(testUserId));
386
387 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
388
389 int32_t result = FAIL;
390 EXPECT_TRUE(reply.ReadInt32(result));
391 EXPECT_EQ(result, SUCCESS);
392 }
393
394 HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub001, TestSize.Level0)
395 {
396 MessageParcel data;
397 MessageParcel reply;
398 MessageOption option(MessageOption::TF_SYNC);
399 uint32_t code = UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER;
400
401 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
402
403 MockUserIdmService service;
404 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
405 }
406
407 HWTEST_F(UserIdmStubTest, UserIdmStubEnforceDelUserStub002, TestSize.Level0)
408 {
409 int32_t testUserId = 83462;
410
411 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
412 EXPECT_NE(callback, nullptr);
413 MockUserIdmService service;
414 EXPECT_CALL(service, EnforceDelUser(_, _)).Times(1);
415 ON_CALL(service, EnforceDelUser)
416 .WillByDefault(
__anon847c91690802(int32_t userId, const sptr<IdmCallbackInterface> &callback) 417 [&testUserId](int32_t userId, const sptr<IdmCallbackInterface> &callback) {
418 EXPECT_EQ(userId, testUserId);
419 if (callback != nullptr) {
420 Attributes attr;
421 callback->OnResult(SUCCESS, attr);
422 }
423 return SUCCESS;
424 }
425 );
426 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
427
428 MessageParcel data;
429 MessageParcel reply;
430 MessageOption option(MessageOption::TF_SYNC);
431 uint32_t code = UserIdmInterfaceCode::USER_IDM_ENFORCE_DEL_USER;
432
433 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
434 EXPECT_TRUE(data.WriteInt32(testUserId));
435 EXPECT_NE(callback->AsObject(), nullptr);
436 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
437
438 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
439
440 int32_t result = FAIL;
441 EXPECT_TRUE(reply.ReadInt32(result));
442 EXPECT_EQ(result, SUCCESS);
443 }
444
445 HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub001, TestSize.Level0)
446 {
447 MessageParcel data;
448 MessageParcel reply;
449 MessageOption option(MessageOption::TF_SYNC);
450 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_USER;
451
452 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
453
454 MockUserIdmService service;
455 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
456 }
457
458 HWTEST_F(UserIdmStubTest, UserIdmStubDelUserStub002, TestSize.Level0)
459 {
460 int32_t testUserId = 72342;
461 std::vector<uint8_t> testAuthToken = {1, 3, 5, 7};
462
463 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
464 EXPECT_NE(callback, nullptr);
465 MockUserIdmService service;
466 EXPECT_CALL(service, DelUser(_, _, _)).Times(1);
467 ON_CALL(service, DelUser)
468 .WillByDefault(
469 [&testUserId, &testAuthToken](int32_t userId, const std::vector<uint8_t> authToken,
__anon847c91690902(int32_t userId, const std::vector<uint8_t> authToken, const sptr<IdmCallbackInterface> &callback) 470 const sptr<IdmCallbackInterface> &callback) {
471 EXPECT_EQ(userId, testUserId);
472 EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
473 if (callback != nullptr) {
474 Attributes attr;
475 callback->OnResult(SUCCESS, attr);
476 }
477 }
478 );
479 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
480
481 MessageParcel data;
482 MessageParcel reply;
483 MessageOption option(MessageOption::TF_SYNC);
484 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_USER;
485
486 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
487 EXPECT_TRUE(data.WriteInt32(testUserId));
488 EXPECT_TRUE(data.WriteUInt8Vector(testAuthToken));
489 EXPECT_NE(callback->AsObject(), nullptr);
490 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
491
492 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
493 }
494
495 HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub001, TestSize.Level0)
496 {
497 MessageParcel data;
498 MessageParcel reply;
499 MessageOption option(MessageOption::TF_SYNC);
500 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_CRED;
501
502 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
503
504 MockUserIdmService service;
505 EXPECT_EQ(READ_PARCEL_ERROR, service.OnRemoteRequest(code, data, reply, option));
506 }
507
508 HWTEST_F(UserIdmStubTest, UserIdmStubDelCredentialStub002, TestSize.Level0)
509 {
510 int32_t testUserId = 93261;
511 uint64_t testCredentialId = 72632;
512 std::vector<uint8_t> testAuthToken = {3, 5, 7, 9};
513
514 sptr<MockIdmCallback> callback(new (std::nothrow) MockIdmCallback());
515 EXPECT_NE(callback, nullptr);
516 MockUserIdmService service;
517 EXPECT_CALL(service, DelCredential(_, _, _, _)).Times(1);
518 ON_CALL(service, DelCredential)
519 .WillByDefault(
520 [&testUserId, &testCredentialId, &testAuthToken](int32_t userId, uint64_t credentialId,
__anon847c91690a02(int32_t userId, uint64_t credentialId, const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) 521 const std::vector<uint8_t> &authToken, const sptr<IdmCallbackInterface> &callback) {
522 EXPECT_EQ(userId, testUserId);
523 EXPECT_EQ(credentialId, testCredentialId);
524 EXPECT_THAT(authToken, ElementsAreArray(testAuthToken));
525 if (callback != nullptr) {
526 Attributes attr;
527 callback->OnResult(SUCCESS, attr);
528 }
529 }
530 );
531 EXPECT_CALL(*callback, OnResult(_, _)).Times(1);
532
533 MessageParcel data;
534 MessageParcel reply;
535 MessageOption option(MessageOption::TF_SYNC);
536 uint32_t code = UserIdmInterfaceCode::USER_IDM_DEL_CRED;
537
538 EXPECT_TRUE(data.WriteInterfaceToken(UserIdmInterface::GetDescriptor()));
539 EXPECT_TRUE(data.WriteInt32(testUserId));
540 EXPECT_TRUE(data.WriteUint64(testCredentialId));
541 EXPECT_TRUE(data.WriteUInt8Vector(testAuthToken));
542 EXPECT_NE(callback->AsObject(), nullptr);
543 EXPECT_TRUE(data.WriteRemoteObject(callback->AsObject()));
544
545 EXPECT_EQ(SUCCESS, service.OnRemoteRequest(code, data, reply, option));
546 }
547 } // namespace UserAuth
548 } // namespace UserIam
549 } // namespace OHOS