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