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 <gtest/gtest.h>
17 #include <gmock/gmock.h>
18
19 #include <thread>
20
21 #include "account_log_wrapper.h"
22 #include "app_account_common.h"
23 #define private public
24 #include "app_account_authenticator_callback.h"
25 #include "app_account_authenticator_manager.h"
26 #include "app_account_authenticator_proxy.h"
27 #include "app_account_authenticator_stub.h"
28 #include "app_account_constants.h"
29 #undef private
30
31 using namespace testing::ext;
32 using namespace OHOS;
33 using namespace OHOS::AccountSA;
34 DECLARE_INTERFACE_DESCRIPTOR(u"ohos.accountfwk.IAppAccountAuthenticator");
35 namespace {
36 const std::string STRING_NAME = "name";
37 const std::string STRING_AUTH_TYPE = "test.authType";
38 const std::string STRING_ABILITY_NAME = "test.mainAbility";
39 const std::string CALLER_BUNDLE_NAME = "test.callerbundlename";
40 const uint32_t SET_PROPERTIES = 4;
41 } // namespace
42
43 class MockAuthenticatorCallback final : public AppAccountAuthenticatorCallbackStub {
44 public:
45 MOCK_METHOD2(OnResult, void(int32_t resultCode, const AAFwk::Want &result));
46 MOCK_METHOD1(OnRequestRedirected, void(AAFwk::Want &request));
47 MOCK_METHOD0(OnRequestContinued, void());
48 };
49
50 class MockAppAccountAuthenticator : public AppAccountAuthenticatorStub {
51 public:
52 ErrCode AddAccountImplicitly(const std::string &authType, const std::string &callerBundleName,
53 const AAFwk::WantParams &options, const sptr<IRemoteObject> &callback);
54 ErrCode Authenticate(
55 const std::string &name, const std::string &authType, const std::string &callerBundleName,
56 const AAFwk::WantParams &options, const sptr<IRemoteObject> &callback);
57 ErrCode VerifyCredential(
58 const std::string &name, const VerifyCredentialOptions &options, const sptr<IRemoteObject> &callback);
59 ErrCode CheckAccountLabels(
60 const std::string &name, const std::vector<std::string> &labels, const sptr<IRemoteObject> &callback);
61 ErrCode SetProperties(const SetPropertiesOptions &options, const sptr<IRemoteObject> &callback);
62 ErrCode IsAccountRemovable(const std::string &name, const sptr<IRemoteObject> &callback);
63 ErrCode CreateAccountImplicitly(
64 const CreateAccountImplicitlyOptions &options, const sptr<IRemoteObject> &callback);
65 ErrCode Auth(const std::string &name, const std::string &authType,
66 const AAFwk::WantParams &options, const sptr<IRemoteObject> &callback);
67 };
68
AddAccountImplicitly(const std::string & authType,const std::string & callerBundleName,const AAFwk::WantParams & options,const sptr<IRemoteObject> & callback)69 ErrCode MockAppAccountAuthenticator::AddAccountImplicitly(
70 const std::string &authType, const std::string &callerBundleName,
71 const AAFwk::WantParams &options, const sptr<IRemoteObject> &callback)
72 {
73 ACCOUNT_LOGI("mock enter");
74 return ERR_OK;
75 }
76
Authenticate(const std::string & name,const std::string & authType,const std::string & callerBundleName,const AAFwk::WantParams & options,const sptr<IRemoteObject> & callback)77 ErrCode MockAppAccountAuthenticator::Authenticate(
78 const std::string &name, const std::string &authType, const std::string &callerBundleName,
79 const AAFwk::WantParams &options, const sptr<IRemoteObject> &callback)
80 {
81 ACCOUNT_LOGI("mock enter");
82 return ERR_OK;
83 }
84
VerifyCredential(const std::string & name,const VerifyCredentialOptions & options,const sptr<IRemoteObject> & callback)85 ErrCode MockAppAccountAuthenticator::VerifyCredential(
86 const std::string &name, const VerifyCredentialOptions &options, const sptr<IRemoteObject> &callback)
87 {
88 ACCOUNT_LOGI("mock enter");
89 return ERR_OK;
90 }
91
CheckAccountLabels(const std::string & name,const std::vector<std::string> & labels,const sptr<IRemoteObject> & callback)92 ErrCode MockAppAccountAuthenticator::CheckAccountLabels(
93 const std::string &name, const std::vector<std::string> &labels, const sptr<IRemoteObject> &callback)
94 {
95 ACCOUNT_LOGI("mock enter");
96 return ERR_OK;
97 }
98
SetProperties(const SetPropertiesOptions & options,const sptr<IRemoteObject> & callback)99 ErrCode MockAppAccountAuthenticator::SetProperties(
100 const SetPropertiesOptions &options, const sptr<IRemoteObject> &callback)
101 {
102 ACCOUNT_LOGI("mock enter");
103 return ERR_OK;
104 }
105
IsAccountRemovable(const std::string & name,const sptr<IRemoteObject> & callback)106 ErrCode MockAppAccountAuthenticator::IsAccountRemovable(const std::string &name, const sptr<IRemoteObject> &callback)
107 {
108 ACCOUNT_LOGI("mock enter");
109 return ERR_OK;
110 }
111
CreateAccountImplicitly(const CreateAccountImplicitlyOptions & options,const sptr<IRemoteObject> & callback)112 ErrCode MockAppAccountAuthenticator::CreateAccountImplicitly(
113 const CreateAccountImplicitlyOptions &options, const sptr<IRemoteObject> &callback)
114 {
115 ACCOUNT_LOGI("mock enter");
116 return ERR_OK;
117 }
118
Auth(const std::string & name,const std::string & authType,const AAFwk::WantParams & options,const sptr<IRemoteObject> & callback)119 ErrCode MockAppAccountAuthenticator::Auth(const std::string &name, const std::string &authType,
120 const AAFwk::WantParams &options, const sptr<IRemoteObject> &callback)
121 {
122 ACCOUNT_LOGI("mock enter");
123 return ERR_OK;
124 }
125
126 class AppAccountAuthenticateModuleTest : public testing::Test {
127 public:
128 static void SetUpTestCase(void);
129 static void TearDownTestCase(void);
130 void SetUp(void) override;
131 void TearDown(void) override;
132 sptr<AppAccountAuthenticatorProxy> authenticateProxyPtr_ = nullptr;
133 sptr<MockAppAccountAuthenticator> mockServicePtr_ = nullptr;
134 sptr<IRemoteObject> authenticorService_ = nullptr;
135 };
136
SetUpTestCase(void)137 void AppAccountAuthenticateModuleTest::SetUpTestCase(void)
138 {}
139
TearDownTestCase(void)140 void AppAccountAuthenticateModuleTest::TearDownTestCase(void)
141 {
142 GTEST_LOG_(INFO) << "TearDownTestCase enter";
143 }
144
SetUp(void)145 void AppAccountAuthenticateModuleTest::SetUp(void) __attribute__((no_sanitize("cfi")))
146 {
147 testing::UnitTest *test = testing::UnitTest::GetInstance();
148 ASSERT_NE(test, nullptr);
149 const testing::TestInfo *testinfo = test->current_test_info();
150 ASSERT_NE(testinfo, nullptr);
151 string testCaseName = string(testinfo->name());
152 ACCOUNT_LOGI("[SetUp] %{public}s start", testCaseName.c_str());
153
154 mockServicePtr_ = new (std::nothrow) MockAppAccountAuthenticator();
155 ASSERT_NE(mockServicePtr_, nullptr);
156
157 authenticorService_ = mockServicePtr_->AsObject();
158 authenticateProxyPtr_ = new (std::nothrow) AppAccountAuthenticatorProxy(authenticorService_);
159 }
160
TearDown(void)161 void AppAccountAuthenticateModuleTest::TearDown(void)
162 {}
163
164 /**
165 * @tc.name: AppAccountAuthenticateTest_CreateAccountImplicitly_0100
166 * @tc.desc: test authenticate proxy func CreateAccountImplicitly.
167 * @tc.type: FUNC
168 * @tc.require: issueI5RWXN
169 */
170 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_CreateAccountImplicitly_0100, TestSize.Level1)
171 {
172 ACCOUNT_LOGI("AppAccountAuthenticateTest_CreateAccountImplicitly_0100");
173
174 CreateAccountImplicitlyOptions options;
175 sptr<IRemoteObject> callback = nullptr;
176 ErrCode result = authenticateProxyPtr_->CreateAccountImplicitly(options, callback);
177 EXPECT_NE(result, ERR_OK);
178 }
179
180 /**
181 * @tc.name: AppAccountAuthenticateTest_Auth_0100
182 * @tc.desc: test authenticate proxy func Auth.
183 * @tc.type: FUNC
184 * @tc.require: issueI5RWXN
185 */
186 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_Auth_0100, TestSize.Level1)
187 {
188 ACCOUNT_LOGI("AppAccountAuthenticateTest_Auth_0100");
189
190 AAFwk::Want want;
191 sptr<IRemoteObject> callback = nullptr;
192 ErrCode result = authenticateProxyPtr_->Auth(STRING_NAME, STRING_AUTH_TYPE, want.GetParams(), callback);
193 EXPECT_NE(result, ERR_OK);
194 }
195
196 /**
197 * @tc.name: AppAccountAuthenticateTest_CreateAccountImplicitly_0200
198 * @tc.desc: test authenticate proxy func CreateAccountImplicitly.
199 * @tc.type: FUNC
200 * @tc.require: issueI5RWXN
201 */
202 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_CreateAccountImplicitly_0200, TestSize.Level1)
203 {
204 ACCOUNT_LOGI("AppAccountAuthenticateTest_CreateAccountImplicitly_0200");
205
206 CreateAccountImplicitlyOptions options;
207 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
208 sptr<IRemoteObject> callback = oauthCallbackPtr->AsObject();
209 EXPECT_NE(callback, nullptr);
210 ErrCode result = authenticateProxyPtr_->CreateAccountImplicitly(options, callback);
211 EXPECT_EQ(result, ERR_OK);
212 }
213
214 /**
215 * @tc.name: AppAccountAuthenticateTest_Auth_0200
216 * @tc.desc: test authenticate proxy func Auth.
217 * @tc.type: FUNC
218 * @tc.require: issueI5RWXN
219 */
220 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_Auth_0200, TestSize.Level1)
221 {
222 ACCOUNT_LOGI("AppAccountAuthenticateTest_Auth_0200");
223
224 AAFwk::Want want;
225 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
226 sptr<IRemoteObject> callback = oauthCallbackPtr->AsObject();
227 EXPECT_NE(callback, nullptr);
228 ErrCode result = authenticateProxyPtr_->Auth(STRING_NAME, STRING_AUTH_TYPE, want.GetParams(), callback);
229 EXPECT_EQ(result, ERR_OK);
230 }
231
232
233 /**
234 * @tc.name: AppAccountAuthenticateTest_AddAccountImplicitly_0100
235 * @tc.desc: test authenticate proxy func AddAccountImplicitly.
236 * @tc.type: FUNC
237 * @tc.require
238 */
239 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_AddAccountImplicitly_0100, TestSize.Level1)
240 {
241 ACCOUNT_LOGI("AppAccountAuthenticateTest_AddAccountImplicitly_0100");
242 AAFwk::Want want;
243 sptr<IRemoteObject> callback = nullptr;
244 ErrCode result =
245 authenticateProxyPtr_->AddAccountImplicitly(STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
246 EXPECT_NE(result, ERR_OK);
247
248 result =
249 authenticateProxyPtr_->AddAccountImplicitly(STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
250 EXPECT_NE(result, ERR_OK);
251
252 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
253 ASSERT_NE(oauthCallbackPtr, nullptr);
254 callback = oauthCallbackPtr->AsObject();
255 ASSERT_NE(callback, nullptr);
256 result =
257 authenticateProxyPtr_->AddAccountImplicitly(STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
258 EXPECT_EQ(result, ERR_OK);
259 }
260
261 /**
262 * @tc.name: AppAccountAuthenticateTest_Authenticate_0100
263 * @tc.desc: test authenticate proxy func Authenticate.
264 * @tc.type: FUNC
265 * @tc.require
266 */
267 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_Authenticate_0100, TestSize.Level1)
268 {
269 ACCOUNT_LOGI("AppAccountAuthenticateTest_Authenticate_0100");
270 AAFwk::Want want;
271 sptr<IRemoteObject> callback = nullptr;
272 ErrCode result = authenticateProxyPtr_->Authenticate(
273 STRING_NAME, STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
274 EXPECT_NE(result, ERR_OK);
275
276 result = authenticateProxyPtr_->Authenticate(
277 STRING_NAME, STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
278 EXPECT_NE(result, ERR_OK);
279
280 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
281 ASSERT_NE(oauthCallbackPtr, nullptr);
282 callback = oauthCallbackPtr->AsObject();
283 ASSERT_NE(callback, nullptr);
284 result = authenticateProxyPtr_->Authenticate(
285 STRING_NAME, STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
286 EXPECT_EQ(result, ERR_OK);
287 }
288
289 /**
290 * @tc.name: AppAccountAuthenticateTest_VerifyCredential_0100
291 * @tc.desc: test authenticate proxy func VerifyCredential.
292 * @tc.type: FUNC
293 * @tc.require
294 */
295 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_VerifyCredential_0100, TestSize.Level1)
296 {
297 ACCOUNT_LOGI("AppAccountAuthenticateTest_VerifyCredential_0100");
298 VerifyCredentialOptions options;
299 sptr<IRemoteObject> callback = nullptr;
300 ErrCode result = authenticateProxyPtr_->VerifyCredential(STRING_NAME, options, callback);
301 EXPECT_NE(result, ERR_OK);
302
303 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
304 ASSERT_NE(oauthCallbackPtr, nullptr);
305 callback = oauthCallbackPtr->AsObject();
306 ASSERT_NE(callback, nullptr);
307 result = authenticateProxyPtr_->VerifyCredential(STRING_NAME, options, callback);
308 EXPECT_EQ(result, ERR_OK);
309 }
310
311 /**
312 * @tc.name: AppAccountAuthenticateTest_CheckAccountLabels_0100
313 * @tc.desc: test authenticate proxy func VerifyCredential.
314 * @tc.type: FUNC
315 * @tc.require
316 */
317 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_CheckAccountLabels_0100, TestSize.Level1)
318 {
319 ACCOUNT_LOGI("AppAccountAuthenticateTest_CheckAccountLabels_0100");
320 std::vector<std::string> labels;
321 sptr<IRemoteObject> callback = nullptr;
322 ErrCode result = authenticateProxyPtr_->CheckAccountLabels(STRING_NAME, labels, callback);
323 EXPECT_NE(result, ERR_OK);
324
325 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
326 ASSERT_NE(oauthCallbackPtr, nullptr);
327 callback = oauthCallbackPtr->AsObject();
328 ASSERT_NE(callback, nullptr);
329 result = authenticateProxyPtr_->CheckAccountLabels(STRING_NAME, labels, callback);
330 EXPECT_EQ(result, ERR_OK);
331 }
332
333 /**
334 * @tc.name: AppAccountAuthenticateTest_SetProperties_0100
335 * @tc.desc: test authenticate proxy func VerifyCredential.
336 * @tc.type: FUNC
337 * @tc.require
338 */
339 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_SetProperties_0100, TestSize.Level1)
340 {
341 ACCOUNT_LOGI("AppAccountAuthenticateTest_SetProperties_0100");
342 SetPropertiesOptions options;
343 sptr<IRemoteObject> callback = nullptr;
344 ErrCode result = authenticateProxyPtr_->SetProperties(options, callback);
345 EXPECT_NE(result, ERR_OK);
346
347 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
348 ASSERT_NE(oauthCallbackPtr, nullptr);
349 callback = oauthCallbackPtr->AsObject();
350 ASSERT_NE(callback, nullptr);
351 result = authenticateProxyPtr_->SetProperties(options, callback);
352 EXPECT_EQ(result, ERR_OK);
353 }
354
355 /**
356 * @tc.name: AppAccountAuthenticateTest_IsAccountRemovable_0100
357 * @tc.desc: test authenticate proxy func VerifyCredential.
358 * @tc.type: FUNC
359 * @tc.require
360 */
361 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_IsAccountRemovable_0100, TestSize.Level1)
362 {
363 ACCOUNT_LOGI("AppAccountAuthenticateTest_IsAccountRemovable_0100");
364 sptr<IRemoteObject> callback = nullptr;
365 ErrCode result = authenticateProxyPtr_->IsAccountRemovable(STRING_NAME, callback);
366 EXPECT_NE(result, ERR_OK);
367
368 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
369 ASSERT_NE(oauthCallbackPtr, nullptr);
370 callback = oauthCallbackPtr->AsObject();
371 ASSERT_NE(callback, nullptr);
372 result = authenticateProxyPtr_->IsAccountRemovable(STRING_NAME, callback);
373 EXPECT_EQ(result, ERR_OK);
374 }
375
376 /**
377 * @tc.name: AppAccountAuthenticatorManagerTest_GetAuthenticatorInfo_0100
378 * @tc.desc: test GetAuthenticatorInfo with not init.
379 * @tc.type: FUNC
380 * @tc.require
381 */
382 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_GetAuthenticatorInfo_0100,
383 TestSize.Level1)
384 {
385 std::string owner = "owner";
386 int32_t userId = 1;
387 AuthenticatorInfo info;
388 ErrCode result = AppAccountAuthenticatorManager::GetAuthenticatorInfo(owner, userId, info);
389 ASSERT_NE(result, ERR_OK);
390 }
391
392 /**
393 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0100
394 * @tc.desc: test AppAccountAuthenticatorStub.
395 * @tc.type: FUNC
396 * @tc.require
397 */
398 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0100,
399 TestSize.Level1)
400 {
401 EXPECT_NE(mockServicePtr_, nullptr);
402 MessageParcel data;
403 MessageParcel reply;
404 MessageOption option;
405 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(-1, data, reply, option), ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR);
406 }
407
408 /**
409 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0200
410 * @tc.desc: test AppAccountAuthenticatorStub.
411 * @tc.type: FUNC
412 * @tc.require
413 */
414 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0200,
415 TestSize.Level1)
416 {
417 EXPECT_NE(mockServicePtr_, nullptr);
418 MessageParcel data;
419 MessageParcel reply;
420 MessageOption option;
421 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
422 EXPECT_NE(mockServicePtr_->OnRemoteRequest(-1, data, reply, option), ERR_NONE);
423 }
424
425 /**
426 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0300
427 * @tc.desc: test AppAccountAuthenticatorStub.
428 * @tc.type: FUNC
429 * @tc.require
430 */
431 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0300,
432 TestSize.Level1)
433 {
434 EXPECT_NE(mockServicePtr_, nullptr);
435 MessageParcel data;
436 MessageParcel reply;
437 MessageOption option;
438 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
439 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(ADD_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
440 int result = 0;
441 reply.ReadInt32(result);
442 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
443 }
444
445 /**
446 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0400
447 * @tc.desc: test AppAccountAuthenticatorStub.
448 * @tc.type: FUNC
449 * @tc.require
450 */
451 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0400,
452 TestSize.Level1)
453 {
454 EXPECT_NE(mockServicePtr_, nullptr);
455 MessageParcel data;
456 MessageParcel reply;
457 MessageOption option;
458 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
459 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTHENTICATE, data, reply, option), ERR_NONE);
460 int result = 0;
461 reply.ReadInt32(result);
462 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
463 }
464
465 /**
466 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0500
467 * @tc.desc: test AppAccountAuthenticatorStub.
468 * @tc.type: FUNC
469 * @tc.require
470 */
471 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0500,
472 TestSize.Level1)
473 {
474 ASSERT_NE(mockServicePtr_, nullptr);
475 MessageParcel data;
476 MessageParcel reply;
477 MessageOption option;
478 int result = 0;
479 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
480 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(VERIFY_CREDENTIAL, data, reply, option), ERR_NONE);
481 reply.ReadInt32(result);
482 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
483 }
484
485 /**
486 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0600
487 * @tc.desc: test AppAccountAuthenticatorStub.
488 * @tc.type: FUNC
489 * @tc.require
490 */
491 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0600,
492 TestSize.Level1)
493 {
494 ASSERT_NE(mockServicePtr_, nullptr);
495 MessageParcel data;
496 MessageParcel reply;
497 MessageOption option;
498 int result = 0;
499 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
500 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CHECK_ACCOUNT_LABELS, data, reply, option), ERR_NONE);
501 reply.ReadInt32(result);
502 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
503 }
504
505 /**
506 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0700
507 * @tc.desc: test AppAccountAuthenticatorStub.
508 * @tc.type: FUNC
509 * @tc.require
510 */
511 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0700,
512 TestSize.Level1)
513 {
514 ASSERT_NE(mockServicePtr_, nullptr);
515 MessageParcel data;
516 MessageParcel reply;
517 MessageOption option;
518 int result = 0;
519 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
520 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(SET_PROPERTIES, data, reply, option),
521 ERR_NONE);
522 reply.ReadInt32(result);
523 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
524 }
525
526 /**
527 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0800
528 * @tc.desc: test AppAccountAuthenticatorStub.
529 * @tc.type: FUNC
530 * @tc.require
531 */
532 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0800,
533 TestSize.Level1)
534 {
535 ASSERT_NE(mockServicePtr_, nullptr);
536 MessageParcel data;
537 MessageParcel reply;
538 MessageOption option;
539 int result = 0;
540 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
541 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(IS_ACCOUNT_REMOVABLE, data, reply, option), ERR_NONE);
542 reply.ReadInt32(result);
543 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
544 }
545
546 /**
547 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0900
548 * @tc.desc: test AppAccountAuthenticatorStub.
549 * @tc.type: FUNC
550 * @tc.require
551 */
552 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0900,
553 TestSize.Level1)
554 {
555 ASSERT_NE(mockServicePtr_, nullptr);
556 MessageParcel data;
557 MessageParcel reply;
558 MessageOption option;
559 int result = 0;
560 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
561 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CREATE_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
562 reply.ReadInt32(result);
563 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
564 }
565
566 /**
567 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_100
568 * @tc.desc: test AppAccountAuthenticatorStub.
569 * @tc.type: FUNC
570 * @tc.require
571 */
572 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_100,
573 TestSize.Level1)
574 {
575 ASSERT_NE(mockServicePtr_, nullptr);
576 MessageParcel data;
577 MessageParcel reply;
578 MessageOption option;
579 int result = 0;
580 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
581 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTH, data, reply, option), ERR_NONE);
582 reply.ReadInt32(result);
583 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
584 }
585
586 /**
587 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0300
588 * @tc.desc: test AppAccountAuthenticatorStub.
589 * @tc.type: FUNC
590 * @tc.require
591 */
592 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1100,
593 TestSize.Level1)
594 {
595 EXPECT_NE(mockServicePtr_, nullptr);
596 MessageParcel data;
597 MessageParcel reply;
598 MessageOption option;
599 AAFwk::WantParams options;
600 std::string authType;
601 std::string callerBundleName;
602 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
603 EXPECT_EQ(data.WriteString(authType), true);
604 EXPECT_EQ(data.WriteString(callerBundleName), true);
605 EXPECT_EQ(data.WriteParcelable(&options), true);
606 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
607 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(ADD_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
608 int result = 0;
609 reply.ReadInt32(result);
610 EXPECT_EQ(result, ERR_OK);
611 }
612
613 /**
614 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0400
615 * @tc.desc: test AppAccountAuthenticatorStub.
616 * @tc.type: FUNC
617 * @tc.require
618 */
619 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1200,
620 TestSize.Level1)
621 {
622 EXPECT_NE(mockServicePtr_, nullptr);
623 MessageParcel data;
624 MessageParcel reply;
625 MessageOption option;
626 AAFwk::WantParams options;
627 std::string name;
628 std::string authType;
629 std::string callerBundleName;
630 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
631 EXPECT_EQ(data.WriteString(name), true);
632 EXPECT_EQ(data.WriteString(authType), true);
633 EXPECT_EQ(data.WriteString(callerBundleName), true);
634 EXPECT_EQ(data.WriteParcelable(&options), true);
635 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
636 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTHENTICATE, data, reply, option), ERR_NONE);
637 int result = 0;
638 reply.ReadInt32(result);
639 EXPECT_EQ(result, ERR_OK);
640 }
641
642 /**
643 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0500
644 * @tc.desc: test AppAccountAuthenticatorStub.
645 * @tc.type: FUNC
646 * @tc.require
647 */
648 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1300,
649 TestSize.Level1)
650 {
651 ASSERT_NE(mockServicePtr_, nullptr);
652 MessageParcel data;
653 MessageParcel reply;
654 MessageOption option;
655 int result = 0;
656 VerifyCredentialOptions options;
657 std::string name;
658 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
659 EXPECT_EQ(data.WriteString(name), true);
660 EXPECT_EQ(data.WriteParcelable(&options), true);
661 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
662 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(VERIFY_CREDENTIAL, data, reply, option), ERR_NONE);
663 reply.ReadInt32(result);
664 EXPECT_EQ(result, ERR_OK);
665 }
666
667 /**
668 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0600
669 * @tc.desc: test AppAccountAuthenticatorStub.
670 * @tc.type: FUNC
671 * @tc.require
672 */
673 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1400,
674 TestSize.Level1)
675 {
676 ASSERT_NE(mockServicePtr_, nullptr);
677 MessageParcel data;
678 MessageParcel reply;
679 MessageOption option;
680 std::vector<std::string> labels;
681 std::string name;
682 int result = 0;
683 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
684 EXPECT_EQ(data.WriteString(name), true);
685 EXPECT_EQ(data.WriteStringVector(labels), true);
686 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
687 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CHECK_ACCOUNT_LABELS, data, reply, option), ERR_NONE);
688 reply.ReadInt32(result);
689 EXPECT_EQ(result, ERR_OK);
690 }
691
692 /**
693 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0700
694 * @tc.desc: test AppAccountAuthenticatorStub.
695 * @tc.type: FUNC
696 * @tc.require
697 */
698 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1500,
699 TestSize.Level1)
700 {
701 ASSERT_NE(mockServicePtr_, nullptr);
702 MessageParcel data;
703 MessageParcel reply;
704 MessageOption option;
705 SetPropertiesOptions options;
706 int result = 0;
707 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
708 EXPECT_EQ(data.WriteParcelable(&options), true);
709 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
710 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(SET_PROPERTIES, data, reply, option),
711 ERR_NONE);
712 reply.ReadInt32(result);
713 EXPECT_EQ(result, ERR_OK);
714 }
715
716 /**
717 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0800
718 * @tc.desc: test AppAccountAuthenticatorStub.
719 * @tc.type: FUNC
720 * @tc.require
721 */
722 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1600,
723 TestSize.Level1)
724 {
725 ASSERT_NE(mockServicePtr_, nullptr);
726 MessageParcel data;
727 MessageParcel reply;
728 MessageOption option;
729 std::string name;
730 int result = 0;
731 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
732 EXPECT_EQ(data.WriteString(name), true);
733 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
734 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(IS_ACCOUNT_REMOVABLE, data, reply, option), ERR_NONE);
735 reply.ReadInt32(result);
736 EXPECT_EQ(result, ERR_OK);
737 }
738
739 /**
740 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0900
741 * @tc.desc: test AppAccountAuthenticatorStub.
742 * @tc.type: FUNC
743 * @tc.require
744 */
745 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1700,
746 TestSize.Level1)
747 {
748 ASSERT_NE(mockServicePtr_, nullptr);
749 MessageParcel data;
750 MessageParcel reply;
751 MessageOption option;
752 CreateAccountImplicitlyOptions options;
753 int result = 0;
754 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
755 EXPECT_EQ(data.WriteParcelable(&options), true);
756 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
757 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CREATE_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
758 reply.ReadInt32(result);
759 EXPECT_EQ(result, ERR_OK);
760 }
761
762 /**
763 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_100
764 * @tc.desc: test AppAccountAuthenticatorStub.
765 * @tc.type: FUNC
766 * @tc.require
767 */
768 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1800,
769 TestSize.Level1)
770 {
771 ASSERT_NE(mockServicePtr_, nullptr);
772 MessageParcel data;
773 MessageParcel reply;
774 MessageOption option;
775 std::string name;
776 std::string authType;
777 AAFwk::WantParams options;
778 int result = 0;
779 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
780 EXPECT_EQ(data.WriteString(name), true);
781 EXPECT_EQ(data.WriteString(authType), true);
782 EXPECT_EQ(data.WriteParcelable(&options), true);
783 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
784 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTH, data, reply, option), ERR_NONE);
785 reply.ReadInt32(result);
786 EXPECT_EQ(result, ERR_OK);
787 }