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 options.parameters.SetParam(Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
177 ErrCode result = authenticateProxyPtr_->CreateAccountImplicitly(options, callback);
178 EXPECT_NE(result, ERR_OK);
179 }
180
181 /**
182 * @tc.name: AppAccountAuthenticateTest_Auth_0100
183 * @tc.desc: test authenticate proxy func Auth.
184 * @tc.type: FUNC
185 * @tc.require: issueI5RWXN
186 */
187 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_Auth_0100, TestSize.Level1)
188 {
189 ACCOUNT_LOGI("AppAccountAuthenticateTest_Auth_0100");
190
191 AAFwk::Want want;
192 want.SetParam(Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
193 sptr<IRemoteObject> callback = nullptr;
194 ErrCode result = authenticateProxyPtr_->Auth(STRING_NAME, STRING_AUTH_TYPE, want.GetParams(), callback);
195 EXPECT_NE(result, ERR_OK);
196 }
197
198 /**
199 * @tc.name: AppAccountAuthenticateTest_CreateAccountImplicitly_0200
200 * @tc.desc: test authenticate proxy func CreateAccountImplicitly.
201 * @tc.type: FUNC
202 * @tc.require: issueI5RWXN
203 */
204 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_CreateAccountImplicitly_0200, TestSize.Level1)
205 {
206 ACCOUNT_LOGI("AppAccountAuthenticateTest_CreateAccountImplicitly_0200");
207
208 CreateAccountImplicitlyOptions options;
209 options.parameters.SetParam(Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
210 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
211 sptr<IRemoteObject> callback = oauthCallbackPtr->AsObject();
212 EXPECT_NE(callback, nullptr);
213 ErrCode result = authenticateProxyPtr_->CreateAccountImplicitly(options, callback);
214 EXPECT_EQ(result, ERR_OK);
215 }
216
217 /**
218 * @tc.name: AppAccountAuthenticateTest_Auth_0200
219 * @tc.desc: test authenticate proxy func Auth.
220 * @tc.type: FUNC
221 * @tc.require: issueI5RWXN
222 */
223 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_Auth_0200, TestSize.Level1)
224 {
225 ACCOUNT_LOGI("AppAccountAuthenticateTest_Auth_0200");
226
227 AAFwk::Want want;
228 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
229 sptr<IRemoteObject> callback = oauthCallbackPtr->AsObject();
230 EXPECT_NE(callback, nullptr);
231 ErrCode result = authenticateProxyPtr_->Auth(STRING_NAME, STRING_AUTH_TYPE, want.GetParams(), callback);
232 EXPECT_EQ(result, ERR_OK);
233 }
234
235
236 /**
237 * @tc.name: AppAccountAuthenticateTest_AddAccountImplicitly_0100
238 * @tc.desc: test authenticate proxy func AddAccountImplicitly.
239 * @tc.type: FUNC
240 * @tc.require
241 */
242 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_AddAccountImplicitly_0100, TestSize.Level1)
243 {
244 ACCOUNT_LOGI("AppAccountAuthenticateTest_AddAccountImplicitly_0100");
245 AAFwk::Want want;
246 sptr<IRemoteObject> callback = nullptr;
247 ErrCode result =
248 authenticateProxyPtr_->AddAccountImplicitly(STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
249 EXPECT_NE(result, ERR_OK);
250
251 want.SetParam(Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
252 result =
253 authenticateProxyPtr_->AddAccountImplicitly(STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
254 EXPECT_NE(result, ERR_OK);
255
256 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
257 ASSERT_NE(oauthCallbackPtr, nullptr);
258 callback = oauthCallbackPtr->AsObject();
259 ASSERT_NE(callback, nullptr);
260 result =
261 authenticateProxyPtr_->AddAccountImplicitly(STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
262 EXPECT_EQ(result, ERR_OK);
263 }
264
265 /**
266 * @tc.name: AppAccountAuthenticateTest_Authenticate_0100
267 * @tc.desc: test authenticate proxy func Authenticate.
268 * @tc.type: FUNC
269 * @tc.require
270 */
271 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_Authenticate_0100, TestSize.Level1)
272 {
273 ACCOUNT_LOGI("AppAccountAuthenticateTest_Authenticate_0100");
274 AAFwk::Want want;
275 sptr<IRemoteObject> callback = nullptr;
276 ErrCode result = authenticateProxyPtr_->Authenticate(
277 STRING_NAME, STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
278 EXPECT_NE(result, ERR_OK);
279
280 want.SetParam(Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
281 result = authenticateProxyPtr_->Authenticate(
282 STRING_NAME, STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
283 EXPECT_NE(result, ERR_OK);
284
285 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
286 ASSERT_NE(oauthCallbackPtr, nullptr);
287 callback = oauthCallbackPtr->AsObject();
288 ASSERT_NE(callback, nullptr);
289 result = authenticateProxyPtr_->Authenticate(
290 STRING_NAME, STRING_AUTH_TYPE, CALLER_BUNDLE_NAME, want.GetParams(), callback);
291 EXPECT_EQ(result, ERR_OK);
292 }
293
294 /**
295 * @tc.name: AppAccountAuthenticateTest_VerifyCredential_0100
296 * @tc.desc: test authenticate proxy func VerifyCredential.
297 * @tc.type: FUNC
298 * @tc.require
299 */
300 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_VerifyCredential_0100, TestSize.Level1)
301 {
302 ACCOUNT_LOGI("AppAccountAuthenticateTest_VerifyCredential_0100");
303 VerifyCredentialOptions options;
304 sptr<IRemoteObject> callback = nullptr;
305 ErrCode result = authenticateProxyPtr_->VerifyCredential(STRING_NAME, options, callback);
306 EXPECT_NE(result, ERR_OK);
307
308 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
309 ASSERT_NE(oauthCallbackPtr, nullptr);
310 callback = oauthCallbackPtr->AsObject();
311 ASSERT_NE(callback, nullptr);
312 result = authenticateProxyPtr_->VerifyCredential(STRING_NAME, options, callback);
313 EXPECT_EQ(result, ERR_OK);
314 }
315
316 /**
317 * @tc.name: AppAccountAuthenticateTest_CheckAccountLabels_0100
318 * @tc.desc: test authenticate proxy func VerifyCredential.
319 * @tc.type: FUNC
320 * @tc.require
321 */
322 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_CheckAccountLabels_0100, TestSize.Level1)
323 {
324 ACCOUNT_LOGI("AppAccountAuthenticateTest_CheckAccountLabels_0100");
325 std::vector<std::string> labels;
326 sptr<IRemoteObject> callback = nullptr;
327 ErrCode result = authenticateProxyPtr_->CheckAccountLabels(STRING_NAME, labels, callback);
328 EXPECT_NE(result, ERR_OK);
329
330 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
331 ASSERT_NE(oauthCallbackPtr, nullptr);
332 callback = oauthCallbackPtr->AsObject();
333 ASSERT_NE(callback, nullptr);
334 result = authenticateProxyPtr_->CheckAccountLabels(STRING_NAME, labels, callback);
335 EXPECT_EQ(result, ERR_OK);
336 }
337
338 /**
339 * @tc.name: AppAccountAuthenticateTest_SetProperties_0100
340 * @tc.desc: test authenticate proxy func VerifyCredential.
341 * @tc.type: FUNC
342 * @tc.require
343 */
344 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_SetProperties_0100, TestSize.Level1)
345 {
346 ACCOUNT_LOGI("AppAccountAuthenticateTest_SetProperties_0100");
347 SetPropertiesOptions options;
348 sptr<IRemoteObject> callback = nullptr;
349 ErrCode result = authenticateProxyPtr_->SetProperties(options, callback);
350 EXPECT_NE(result, ERR_OK);
351
352 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
353 ASSERT_NE(oauthCallbackPtr, nullptr);
354 callback = oauthCallbackPtr->AsObject();
355 ASSERT_NE(callback, nullptr);
356 result = authenticateProxyPtr_->SetProperties(options, callback);
357 EXPECT_EQ(result, ERR_OK);
358 }
359
360 /**
361 * @tc.name: AppAccountAuthenticateTest_IsAccountRemovable_0100
362 * @tc.desc: test authenticate proxy func VerifyCredential.
363 * @tc.type: FUNC
364 * @tc.require
365 */
366 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticateTest_IsAccountRemovable_0100, TestSize.Level1)
367 {
368 ACCOUNT_LOGI("AppAccountAuthenticateTest_IsAccountRemovable_0100");
369 sptr<IRemoteObject> callback = nullptr;
370 ErrCode result = authenticateProxyPtr_->IsAccountRemovable(STRING_NAME, callback);
371 EXPECT_NE(result, ERR_OK);
372
373 sptr<IAppAccountAuthenticatorCallback> oauthCallbackPtr = new (std::nothrow) MockAuthenticatorCallback();
374 ASSERT_NE(oauthCallbackPtr, nullptr);
375 callback = oauthCallbackPtr->AsObject();
376 ASSERT_NE(callback, nullptr);
377 result = authenticateProxyPtr_->IsAccountRemovable(STRING_NAME, callback);
378 EXPECT_EQ(result, ERR_OK);
379 }
380
381 /**
382 * @tc.name: AppAccountAuthenticatorManagerTest_GetAuthenticatorInfo_0100
383 * @tc.desc: test GetAuthenticatorInfo with not init.
384 * @tc.type: FUNC
385 * @tc.require
386 */
387 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_GetAuthenticatorInfo_0100,
388 TestSize.Level1)
389 {
390 std::string owner = "owner";
391 int32_t userId = 1;
392 AuthenticatorInfo info;
393 ErrCode result = AppAccountAuthenticatorManager::GetAuthenticatorInfo(owner, userId, info);
394 ASSERT_NE(result, ERR_OK);
395 }
396
397 /**
398 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0100
399 * @tc.desc: test AppAccountAuthenticatorStub.
400 * @tc.type: FUNC
401 * @tc.require
402 */
403 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0100,
404 TestSize.Level1)
405 {
406 EXPECT_NE(mockServicePtr_, nullptr);
407 MessageParcel data;
408 MessageParcel reply;
409 MessageOption option;
410 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(-1, data, reply, option), ERR_ACCOUNT_COMMON_CHECK_DESCRIPTOR_ERROR);
411 }
412
413 /**
414 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0200
415 * @tc.desc: test AppAccountAuthenticatorStub.
416 * @tc.type: FUNC
417 * @tc.require
418 */
419 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0200,
420 TestSize.Level1)
421 {
422 EXPECT_NE(mockServicePtr_, nullptr);
423 MessageParcel data;
424 MessageParcel reply;
425 MessageOption option;
426 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
427 EXPECT_NE(mockServicePtr_->OnRemoteRequest(-1, data, reply, option), ERR_NONE);
428 }
429
430 /**
431 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0300
432 * @tc.desc: test AppAccountAuthenticatorStub.
433 * @tc.type: FUNC
434 * @tc.require
435 */
436 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0300,
437 TestSize.Level1)
438 {
439 EXPECT_NE(mockServicePtr_, nullptr);
440 MessageParcel data;
441 MessageParcel reply;
442 MessageOption option;
443 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
444 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(ADD_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
445 int result = 0;
446 reply.ReadInt32(result);
447 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
448 }
449
450 /**
451 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0400
452 * @tc.desc: test AppAccountAuthenticatorStub.
453 * @tc.type: FUNC
454 * @tc.require
455 */
456 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0400,
457 TestSize.Level1)
458 {
459 EXPECT_NE(mockServicePtr_, nullptr);
460 MessageParcel data;
461 MessageParcel reply;
462 MessageOption option;
463 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
464 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTHENTICATE, data, reply, option), ERR_NONE);
465 int result = 0;
466 reply.ReadInt32(result);
467 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
468 }
469
470 /**
471 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0500
472 * @tc.desc: test AppAccountAuthenticatorStub.
473 * @tc.type: FUNC
474 * @tc.require
475 */
476 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0500,
477 TestSize.Level1)
478 {
479 ASSERT_NE(mockServicePtr_, nullptr);
480 MessageParcel data;
481 MessageParcel reply;
482 MessageOption option;
483 int result = 0;
484 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
485 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(VERIFY_CREDENTIAL, data, reply, option), ERR_NONE);
486 reply.ReadInt32(result);
487 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
488 }
489
490 /**
491 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0600
492 * @tc.desc: test AppAccountAuthenticatorStub.
493 * @tc.type: FUNC
494 * @tc.require
495 */
496 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0600,
497 TestSize.Level1)
498 {
499 ASSERT_NE(mockServicePtr_, nullptr);
500 MessageParcel data;
501 MessageParcel reply;
502 MessageOption option;
503 int result = 0;
504 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
505 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CHECK_ACCOUNT_LABELS, data, reply, option), ERR_NONE);
506 reply.ReadInt32(result);
507 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
508 }
509
510 /**
511 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0700
512 * @tc.desc: test AppAccountAuthenticatorStub.
513 * @tc.type: FUNC
514 * @tc.require
515 */
516 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0700,
517 TestSize.Level1)
518 {
519 ASSERT_NE(mockServicePtr_, nullptr);
520 MessageParcel data;
521 MessageParcel reply;
522 MessageOption option;
523 int result = 0;
524 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
525 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(SET_PROPERTIES, data, reply, option),
526 ERR_NONE);
527 reply.ReadInt32(result);
528 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
529 }
530
531 /**
532 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0800
533 * @tc.desc: test AppAccountAuthenticatorStub.
534 * @tc.type: FUNC
535 * @tc.require
536 */
537 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0800,
538 TestSize.Level1)
539 {
540 ASSERT_NE(mockServicePtr_, nullptr);
541 MessageParcel data;
542 MessageParcel reply;
543 MessageOption option;
544 int result = 0;
545 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
546 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(IS_ACCOUNT_REMOVABLE, data, reply, option), ERR_NONE);
547 reply.ReadInt32(result);
548 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
549 }
550
551 /**
552 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0900
553 * @tc.desc: test AppAccountAuthenticatorStub.
554 * @tc.type: FUNC
555 * @tc.require
556 */
557 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0900,
558 TestSize.Level1)
559 {
560 ASSERT_NE(mockServicePtr_, nullptr);
561 MessageParcel data;
562 MessageParcel reply;
563 MessageOption option;
564 int result = 0;
565 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
566 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CREATE_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
567 reply.ReadInt32(result);
568 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
569 }
570
571 /**
572 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_100
573 * @tc.desc: test AppAccountAuthenticatorStub.
574 * @tc.type: FUNC
575 * @tc.require
576 */
577 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_100,
578 TestSize.Level1)
579 {
580 ASSERT_NE(mockServicePtr_, nullptr);
581 MessageParcel data;
582 MessageParcel reply;
583 MessageOption option;
584 int result = 0;
585 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
586 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTH, data, reply, option), ERR_NONE);
587 reply.ReadInt32(result);
588 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
589 }
590
591 /**
592 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0300
593 * @tc.desc: test AppAccountAuthenticatorStub.
594 * @tc.type: FUNC
595 * @tc.require
596 */
597 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1100,
598 TestSize.Level1)
599 {
600 EXPECT_NE(mockServicePtr_, nullptr);
601 MessageParcel data;
602 MessageParcel reply;
603 MessageOption option;
604 AAFwk::WantParams options;
605 std::string authType;
606 std::string callerBundleName;
607 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
608 EXPECT_EQ(data.WriteString(authType), true);
609 EXPECT_EQ(data.WriteString(callerBundleName), true);
610 EXPECT_EQ(data.WriteParcelable(&options), true);
611 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
612 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(ADD_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
613 int result = 0;
614 reply.ReadInt32(result);
615 EXPECT_EQ(result, ERR_OK);
616 }
617
618 /**
619 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0400
620 * @tc.desc: test AppAccountAuthenticatorStub.
621 * @tc.type: FUNC
622 * @tc.require
623 */
624 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1200,
625 TestSize.Level1)
626 {
627 EXPECT_NE(mockServicePtr_, nullptr);
628 MessageParcel data;
629 MessageParcel reply;
630 MessageOption option;
631 AAFwk::WantParams options;
632 std::string name;
633 std::string authType;
634 std::string callerBundleName;
635 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
636 EXPECT_EQ(data.WriteString(name), true);
637 EXPECT_EQ(data.WriteString(authType), true);
638 EXPECT_EQ(data.WriteString(callerBundleName), true);
639 EXPECT_EQ(data.WriteParcelable(&options), true);
640 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
641 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTHENTICATE, data, reply, option), ERR_NONE);
642 int result = 0;
643 reply.ReadInt32(result);
644 EXPECT_EQ(result, ERR_OK);
645 }
646
647 /**
648 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0500
649 * @tc.desc: test AppAccountAuthenticatorStub.
650 * @tc.type: FUNC
651 * @tc.require
652 */
653 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1300,
654 TestSize.Level1)
655 {
656 ASSERT_NE(mockServicePtr_, nullptr);
657 MessageParcel data;
658 MessageParcel reply;
659 MessageOption option;
660 int result = 0;
661 VerifyCredentialOptions options;
662 std::string name;
663 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
664 EXPECT_EQ(data.WriteString(name), true);
665 EXPECT_EQ(data.WriteParcelable(&options), true);
666 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
667 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(VERIFY_CREDENTIAL, data, reply, option), ERR_NONE);
668 reply.ReadInt32(result);
669 EXPECT_EQ(result, ERR_OK);
670 }
671
672 /**
673 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0600
674 * @tc.desc: test AppAccountAuthenticatorStub.
675 * @tc.type: FUNC
676 * @tc.require
677 */
678 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1400,
679 TestSize.Level1)
680 {
681 ASSERT_NE(mockServicePtr_, nullptr);
682 MessageParcel data;
683 MessageParcel reply;
684 MessageOption option;
685 std::vector<std::string> labels;
686 std::string name;
687 int result = 0;
688 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
689 EXPECT_EQ(data.WriteString(name), true);
690 EXPECT_EQ(data.WriteStringVector(labels), true);
691 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
692 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CHECK_ACCOUNT_LABELS, data, reply, option), ERR_NONE);
693 reply.ReadInt32(result);
694 EXPECT_EQ(result, ERR_OK);
695 }
696
697 /**
698 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0700
699 * @tc.desc: test AppAccountAuthenticatorStub.
700 * @tc.type: FUNC
701 * @tc.require
702 */
703 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1500,
704 TestSize.Level1)
705 {
706 ASSERT_NE(mockServicePtr_, nullptr);
707 MessageParcel data;
708 MessageParcel reply;
709 MessageOption option;
710 SetPropertiesOptions options;
711 int result = 0;
712 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
713 EXPECT_EQ(data.WriteParcelable(&options), true);
714 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
715 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(SET_PROPERTIES, data, reply, option),
716 ERR_NONE);
717 reply.ReadInt32(result);
718 EXPECT_EQ(result, ERR_OK);
719 }
720
721 /**
722 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0800
723 * @tc.desc: test AppAccountAuthenticatorStub.
724 * @tc.type: FUNC
725 * @tc.require
726 */
727 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1600,
728 TestSize.Level1)
729 {
730 ASSERT_NE(mockServicePtr_, nullptr);
731 MessageParcel data;
732 MessageParcel reply;
733 MessageOption option;
734 std::string name;
735 int result = 0;
736 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
737 EXPECT_EQ(data.WriteString(name), true);
738 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
739 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(IS_ACCOUNT_REMOVABLE, data, reply, option), ERR_NONE);
740 reply.ReadInt32(result);
741 EXPECT_EQ(result, ERR_OK);
742 }
743
744 /**
745 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_0900
746 * @tc.desc: test AppAccountAuthenticatorStub.
747 * @tc.type: FUNC
748 * @tc.require
749 */
750 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1700,
751 TestSize.Level1)
752 {
753 ASSERT_NE(mockServicePtr_, nullptr);
754 MessageParcel data;
755 MessageParcel reply;
756 MessageOption option;
757 CreateAccountImplicitlyOptions options;
758 int result = 0;
759 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
760 EXPECT_EQ(data.WriteParcelable(&options), true);
761 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
762 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(CREATE_ACCOUNT_IMPLICITLY, data, reply, option), ERR_NONE);
763 reply.ReadInt32(result);
764 EXPECT_EQ(result, ERR_OK);
765 }
766
767 /**
768 * @tc.name: AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_100
769 * @tc.desc: test AppAccountAuthenticatorStub.
770 * @tc.type: FUNC
771 * @tc.require
772 */
773 HWTEST_F(AppAccountAuthenticateModuleTest, AppAccountAuthenticatorManagerTest_AppAccountAuthenticatorStub_1800,
774 TestSize.Level1)
775 {
776 ASSERT_NE(mockServicePtr_, nullptr);
777 MessageParcel data;
778 MessageParcel reply;
779 MessageOption option;
780 std::string name;
781 std::string authType;
782 AAFwk::WantParams options;
783 int result = 0;
784 EXPECT_EQ(data.WriteInterfaceToken(GetDescriptor()), true);
785 EXPECT_EQ(data.WriteString(name), true);
786 EXPECT_EQ(data.WriteString(authType), true);
787 EXPECT_EQ(data.WriteParcelable(&options), true);
788 EXPECT_EQ(data.WriteRemoteObject(authenticorService_), true);
789 EXPECT_EQ(mockServicePtr_->OnRemoteRequest(AUTH, data, reply, option), ERR_NONE);
790 reply.ReadInt32(result);
791 EXPECT_EQ(result, ERR_OK);
792 }