1 /*
2 * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <gtest/gtest.h>
17
18 #include <thread>
19 #include <gmock/gmock.h>
20 #include "account_log_wrapper.h"
21 #include "datetime_ex.h"
22 #define private public
23 #include "app_account_authenticator_callback_stub.h"
24 #include "app_account_common.h"
25 #include "app_account_common_event_observer.h"
26 #include "app_account_constants.h"
27 #include "app_account_control_manager.h"
28 #include "app_account_manager_service.h"
29 #undef private
30 #include "bundle_constants.h"
31 #ifdef HAS_CES_PART
32 #include "common_event_manager.h"
33 #include "common_event_support.h"
34 #endif // HAS_CES_PART
35 #include "iremote_object.h"
36 #include "app_account_manager_service.h"
37
38 using namespace testing;
39 using namespace testing::ext;
40 using namespace OHOS;
41 using namespace OHOS::AccountSA;
42 using namespace OHOS::AppExecFwk;
43 #ifdef HAS_CES_PART
44 using namespace OHOS::EventFwk;
45 #endif // HAS_CES_PART
46 namespace {
47 const std::string STRING_NAME = "name";
48 const std::string STRING_NAME_TWO = "name_two";
49 const std::string STRING_NAME_THREE = "name_three";
50 const std::string STRING_NAME_MAX_SIZE(512, '1'); // length 512
51 const std::string STRING_NAME_NOT_EXISTED = "name_not_existed";
52 const std::string STRING_EXTRA_INFO = "extra_info";
53 const std::string STRING_BUNDLE_NAME = "com.example.third_party";
54 const std::string STRING_BUNDLE_NAME_NOT_INSTALLED = "com.example.not_installed";
55 const std::string STRING_EMPTY = "";
56 const std::string STRING_KEY = "key";
57 const std::string STRING_KEY_TWO = "key_two";
58 const std::string STRING_VALUE = "value";
59 const std::string STRING_VALUE_TWO = "value_two";
60 const std::string STRING_CREDENTIAL_TYPE = "password";
61 const std::string STRING_CREDENTIAL = "1024";
62 const std::string STRING_CREDENTIAL_TYPE_TWO = "token";
63 const std::string STRING_CREDENTIAL_TWO = "2048";
64 const std::string STRING_TOKEN = "1024";
65 const std::string STRING_TOKEN_TWO = "2048";
66 const std::string STRING_OWNER = "com.example.owner";
67 const std::string INVALID_STRING_OWNER = "owner_not_exist";
68 const std::string STRING_AUTH_TYPE = "read";
69 const std::string STRING_AUTH_TYPE_TWO = "write";
70 const std::string STRING_SESSION_ID = "100";
71 const std::string STRING_ABILITY_NAME = "com.example.owner.MainAbility";
72 const std::vector<std::string> TEST_LABELS = {
73 "test_label1",
74 "test_label2",
75 };
76
77 const bool SYNC_ENABLE_TRUE = true;
78 const bool SYNC_ENABLE_FALSE = false;
79
80 constexpr std::int32_t UID = 10000;
81 constexpr std::int32_t TEST_USER_ID = 101;
82 constexpr std::size_t SIZE_ZERO = 0;
83 constexpr std::size_t SIZE_ONE = 1;
84 constexpr std::size_t SIZE_TWO = 2;
85 std::shared_ptr<AppAccountManagerService> g_accountManagerService =
86 std::make_shared<AppAccountManagerService>();
87 } // namespace
88
89 class MockAuthenticatorCallback final : public AppAccountAuthenticatorCallbackStub {
90 public:
91 MOCK_METHOD2(OnResult, void(int32_t resultCode, const AAFwk::Want &result));
92 MOCK_METHOD1(OnRequestRedirected, void(AAFwk::Want &request));
93 MOCK_METHOD0(OnRequestContinued, void());
94 };
95
96 class AppAccountManagerServiceModuleTest : public testing::Test {
97 public:
98 static void SetUpTestCase(void);
99 static void TearDownTestCase(void);
100 void SetUp(void) override;
101 void TearDown(void) override;
102 void ClearDataStorage();
103 };
104
ClearDataStorage()105 void AppAccountManagerServiceModuleTest::ClearDataStorage()
106 {
107 auto dataStoragePtr = AppAccountControlManager::GetInstance().GetDataStorage(UID);
108 std::map<std::string, std::shared_ptr<IAccountInfo>> accounts;
109 dataStoragePtr->LoadAllData(accounts);
110 if (!accounts.empty()) {
111 for (auto accountPtr : accounts) {
112 dataStoragePtr->RemoveValueFromKvStore(accountPtr.first);
113 }
114 }
115 dataStoragePtr->LoadAllData(accounts);
116 ASSERT_EQ(accounts.size(), 0);
117 }
118
SetUpTestCase(void)119 void AppAccountManagerServiceModuleTest::SetUpTestCase(void)
120 {
121 GTEST_LOG_(INFO) << "SetUpTestCase";
122 }
123
TearDownTestCase(void)124 void AppAccountManagerServiceModuleTest::TearDownTestCase(void)
125 {
126 GTEST_LOG_(INFO) << "TearDownTestCase enter";
127 auto dataStoragePtr = AppAccountControlManager::GetInstance().GetDataStorage(UID);
128 ASSERT_NE(dataStoragePtr, nullptr);
129
130 ErrCode result = dataStoragePtr->DeleteKvStore();
131 ASSERT_EQ(result, ERR_OK);
132
133 #ifdef DISTRIBUTED_FEATURE_ENABLED
134 dataStoragePtr = AppAccountControlManager::GetInstance().GetDataStorage(UID, true);
135 ASSERT_NE(dataStoragePtr, nullptr);
136
137 result = dataStoragePtr->DeleteKvStore();
138 ASSERT_EQ(result, ERR_OK);
139 #endif // DISTRIBUTED_FEATURE_ENABLED
140 GTEST_LOG_(INFO) << "TearDownTestCase exit";
141 }
142
SetUp(void)143 void AppAccountManagerServiceModuleTest::SetUp(void) __attribute__((no_sanitize("cfi")))
144 {
145 testing::UnitTest *test = testing::UnitTest::GetInstance();
146 ASSERT_NE(test, nullptr);
147 const testing::TestInfo *testinfo = test->current_test_info();
148 ASSERT_NE(testinfo, nullptr);
149 string testCaseName = string(testinfo->name());
150 ACCOUNT_LOGI("[SetUp] %{public}s start", testCaseName.c_str());
151
152 ClearDataStorage();
153 }
154
TearDown(void)155 void AppAccountManagerServiceModuleTest::TearDown(void)
156 {}
157
158 /**
159 * @tc.name: AppAccountManagerService_AddAccount_0100
160 * @tc.desc: Add an app account with valid data.
161 * @tc.type: FUNC
162 * @tc.require: issueI5N90B
163 */
164 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_AddAccount_0100, TestSize.Level0)
165 {
166 ACCOUNT_LOGI("AppAccountManagerService_AddAccount_0100");
167
168 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
169 EXPECT_EQ(result, ERR_OK);
170
171 result = g_accountManagerService->DeleteAccount(STRING_NAME);
172 EXPECT_EQ(result, ERR_OK);
173 }
174
175 /**
176 * @tc.name: AppAccountManagerService_AddAccount_0200
177 * @tc.desc: Add an app account with valid data.
178 * @tc.type: FUNC
179 * @tc.require: issueI5N90B
180 */
181 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_AddAccount_0200, TestSize.Level1)
182 {
183 ACCOUNT_LOGI("AppAccountManagerService_AddAccount_0200");
184
185 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EMPTY);
186 EXPECT_EQ(result, ERR_OK);
187
188 result = g_accountManagerService->DeleteAccount(STRING_NAME);
189 EXPECT_EQ(result, ERR_OK);
190 }
191
192 /**
193 * @tc.name: AppAccountManagerService_AddAccount_0300
194 * @tc.desc: Add an app account with valid data.
195 * @tc.type: FUNC
196 * @tc.require: issueI5N90B
197 */
198 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_AddAccount_0300, TestSize.Level1)
199 {
200 ACCOUNT_LOGI("AppAccountManagerService_AddAccount_0300");
201
202 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
203 EXPECT_EQ(result, ERR_OK);
204
205 result = g_accountManagerService->DeleteAccount(STRING_NAME);
206 EXPECT_EQ(result, ERR_OK);
207 }
208
209 /**
210 * @tc.name: AppAccountManagerService_AddAccount_0400
211 * @tc.desc: Add an app account with valid data.
212 * @tc.type: FUNC
213 * @tc.require: issueI5N90B
214 */
215 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_AddAccount_0400, TestSize.Level1)
216 {
217 ACCOUNT_LOGI("AppAccountManagerService_AddAccount_0400");
218
219 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME_MAX_SIZE, STRING_EXTRA_INFO);
220 EXPECT_EQ(result, ERR_OK);
221
222 result = g_accountManagerService->DeleteAccount(STRING_NAME_MAX_SIZE);
223 EXPECT_EQ(result, ERR_OK);
224 }
225
226 /**
227 * @tc.name: AppAccountManagerService_AddAccount_0500
228 * @tc.desc: Add an app account with invalid data.
229 * @tc.type: FUNC
230 * @tc.require: issueI5N90B
231 */
232 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_AddAccount_0500, TestSize.Level1)
233 {
234 ACCOUNT_LOGI("AppAccountManagerService_AddAccount_0500");
235
236 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
237 EXPECT_EQ(result, ERR_OK);
238
239 result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
240 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ADD_EXISTING_ACCOUNT);
241
242 result = g_accountManagerService->DeleteAccount(STRING_NAME);
243 EXPECT_EQ(result, ERR_OK);
244 }
245
246 /**
247 * @tc.name: AppAccountManagerService_CreateAccount_0100
248 * @tc.desc: test create app account exception case.
249 * @tc.type: FUNC
250 * @tc.require: issueI5RWXN
251 */
252 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CreateAccount_0100, TestSize.Level1)
253 {
254 ACCOUNT_LOGI("AppAccountManagerService_CreateAccount_0100");
255
256 CreateAccountOptions option;
257 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
258 EXPECT_EQ(result, ERR_OK);
259 result = g_accountManagerService->CreateAccount(STRING_NAME, option);
260 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ADD_EXISTING_ACCOUNT);
261 result = g_accountManagerService->DeleteAccount(STRING_NAME);
262 EXPECT_EQ(result, ERR_OK);
263 }
264
265 /**
266 * @tc.name: AppAccountManagerService_DeleteAccount_0100
267 * @tc.desc: Delete an app account with valid data.
268 * @tc.type: FUNC
269 * @tc.require: issueI5N90B
270 */
271 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAccount_0100, TestSize.Level0)
272 {
273 ACCOUNT_LOGI("AppAccountManagerService_DeleteAccount_0100");
274
275 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
276 EXPECT_EQ(result, ERR_OK);
277
278 result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
279 EXPECT_EQ(result, ERR_OK);
280
281 result = g_accountManagerService->DeleteAccount(STRING_NAME);
282 EXPECT_EQ(result, ERR_OK);
283
284 auto dataStoragePtr = AppAccountControlManager::GetInstance().GetDataStorage(UID);
285 ASSERT_NE(dataStoragePtr, nullptr);
286
287 std::vector<std::string> accessibleAccounts;
288 result = dataStoragePtr->GetAccessibleAccountsFromDataStorage(STRING_BUNDLE_NAME, accessibleAccounts);
289 EXPECT_EQ(result, ERR_OK);
290 EXPECT_EQ(accessibleAccounts.size(), SIZE_ZERO);
291 }
292
293 /**
294 * @tc.name: AppAccountManagerService_DeleteAccount_0200
295 * @tc.desc: Delete an app account with invalid data.
296 * @tc.type: FUNC
297 * @tc.require: issueI5N90B
298 */
299 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAccount_0200, TestSize.Level1)
300 {
301 ACCOUNT_LOGI("AppAccountManagerService_DeleteAccount_0200");
302
303 ErrCode result = g_accountManagerService->DeleteAccount(STRING_NAME_NOT_EXISTED);
304 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
305 }
306
307 /**
308 * @tc.name: AppAccountManagerService_GetAccountExtraInfo_0100
309 * @tc.desc: Get extra info of an app account with valid data.
310 * @tc.type: FUNC
311 * @tc.require: issueI5N90B
312 */
313 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAccountExtraInfo_0100, TestSize.Level1)
314 {
315 ACCOUNT_LOGI("AppAccountManagerService_GetAccountExtraInfo_0100");
316
317 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
318 EXPECT_EQ(result, ERR_OK);
319
320 std::string extraInfo;
321 result = g_accountManagerService->GetAccountExtraInfo(STRING_NAME, extraInfo);
322 EXPECT_EQ(result, ERR_OK);
323 EXPECT_EQ(extraInfo, STRING_EXTRA_INFO);
324
325 result = g_accountManagerService->DeleteAccount(STRING_NAME);
326 EXPECT_EQ(result, ERR_OK);
327 }
328
329 /**
330 * @tc.name: AppAccountManagerService_GetAccountExtraInfo_0200
331 * @tc.desc: Get extra info of an app account with invalid data.
332 * @tc.type: FUNC
333 * @tc.require: issueI5N90B
334 */
335 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAccountExtraInfo_0200, TestSize.Level1)
336 {
337 ACCOUNT_LOGI("AppAccountManagerService_GetAccountExtraInfo_0200");
338
339 std::string extraInfo;
340 ErrCode result = g_accountManagerService->GetAccountExtraInfo(STRING_NAME, extraInfo);
341 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
342 EXPECT_EQ(extraInfo, STRING_EMPTY);
343 }
344
345 /**
346 * @tc.name: AppAccountManagerService_SetAccountExtraInfo_0100
347 * @tc.desc: Set extra info of an app account with valid data.
348 * @tc.type: FUNC
349 * @tc.require: issueI5N90B
350 */
351 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAccountExtraInfo_0100, TestSize.Level1)
352 {
353 ACCOUNT_LOGI("AppAccountManagerService_SetAccountExtraInfo_0100");
354
355 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
356 EXPECT_EQ(result, ERR_OK);
357
358 result = g_accountManagerService->SetAccountExtraInfo(STRING_NAME, STRING_EXTRA_INFO);
359 EXPECT_EQ(result, ERR_OK);
360
361 std::string extraInfo;
362 result = g_accountManagerService->GetAccountExtraInfo(STRING_NAME, extraInfo);
363 EXPECT_EQ(result, ERR_OK);
364 EXPECT_EQ(extraInfo, STRING_EXTRA_INFO);
365
366 result = g_accountManagerService->DeleteAccount(STRING_NAME);
367 EXPECT_EQ(result, ERR_OK);
368 }
369
370 /**
371 * @tc.name: AppAccountManagerService_SetAccountExtraInfo_0200
372 * @tc.desc: Set extra info of an app account with valid data.
373 * @tc.type: FUNC
374 * @tc.require: issueI5N90B
375 */
376 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAccountExtraInfo_0200, TestSize.Level1)
377 {
378 ACCOUNT_LOGI("AppAccountManagerService_SetAccountExtraInfo_0200");
379
380 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
381 EXPECT_EQ(result, ERR_OK);
382
383 result = g_accountManagerService->SetAccountExtraInfo(STRING_NAME, STRING_EMPTY);
384 EXPECT_EQ(result, ERR_OK);
385
386 std::string extraInfo;
387 result = g_accountManagerService->GetAccountExtraInfo(STRING_NAME, extraInfo);
388 EXPECT_EQ(result, ERR_OK);
389 EXPECT_EQ(extraInfo, STRING_EMPTY);
390
391 result = g_accountManagerService->DeleteAccount(STRING_NAME);
392 EXPECT_EQ(result, ERR_OK);
393 }
394
395 /**
396 * @tc.name: AppAccountManagerService_SetAccountExtraInfo_0300
397 * @tc.desc: Set extra info of an app account with invalid data.
398 * @tc.type: FUNC
399 * @tc.require: issueI5N90B
400 */
401 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAccountExtraInfo_0300, TestSize.Level1)
402 {
403 ACCOUNT_LOGI("AppAccountManagerService_SetAccountExtraInfo_0300");
404
405 ErrCode result = g_accountManagerService->SetAccountExtraInfo(STRING_NAME, STRING_EXTRA_INFO);
406 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
407 }
408
409 /**
410 * @tc.name: seAppAccountManagerService_EnableAppAccess_0100
411 * @tc.desc: Enable app access with valid data.
412 * @tc.type: FUNC
413 * @tc.require: issueI5N90B
414 */
415 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_EnableAppAccess_0100, TestSize.Level1)
416 {
417 ACCOUNT_LOGI("seAppAccountManagerService_EnableAppAccess_0100");
418
419 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
420 EXPECT_EQ(result, ERR_OK);
421
422 result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
423 EXPECT_EQ(result, ERR_OK);
424
425 result = g_accountManagerService->DisableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
426 EXPECT_EQ(result, ERR_OK);
427
428 result = g_accountManagerService->DeleteAccount(STRING_NAME);
429 EXPECT_EQ(result, ERR_OK);
430 }
431
432 /**
433 * @tc.name: AppAccountManagerService_SetAppAccess_0100
434 * @tc.desc: Enable app access with valid data.
435 * @tc.type: FUNC
436 * @tc.require:
437 */
438 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAppAccess_0100, TestSize.Level1)
439 {
440 ACCOUNT_LOGI("AppAccountManagerService_SetAppAccess_0100");
441
442 CreateAccountOptions option;
443 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
444 EXPECT_EQ(result, ERR_OK);
445
446 result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_BUNDLE_NAME, true);
447 EXPECT_EQ(result, ERR_OK);
448
449 result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_BUNDLE_NAME, false);
450 EXPECT_EQ(result, ERR_OK);
451
452 result = g_accountManagerService->DeleteAccount(STRING_NAME);
453 EXPECT_EQ(result, ERR_OK);
454 }
455
456 /**
457 * @tc.name: seAppAccountManagerService_EnableAppAccess_0200
458 * @tc.desc: Enable app access with invalid data.
459 * @tc.type: FUNC
460 * @tc.require: issueI5N90B
461 */
462 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_EnableAppAccess_0200, TestSize.Level1)
463 {
464 ACCOUNT_LOGI("seAppAccountManagerService_EnableAppAccess_0200");
465
466 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
467 EXPECT_EQ(result, ERR_OK);
468
469 result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_OWNER);
470 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
471
472 result = g_accountManagerService->DeleteAccount(STRING_NAME);
473 EXPECT_EQ(result, ERR_OK);
474 }
475
476 /**
477 * @tc.name: seAppAccountManagerService_SetAppAccess_0200
478 * @tc.desc: Enable app access with invalid data.
479 * @tc.type: FUNC
480 * @tc.require:
481 */
482 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_SetAppAccess_0200, TestSize.Level1)
483 {
484 ACCOUNT_LOGI("seAppAccountManagerService_SetAppAccess_0200");
485
486 CreateAccountOptions option;
487 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
488 EXPECT_EQ(result, ERR_OK);
489
490 result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_OWNER, true);
491 EXPECT_EQ(result, ERR_OK);
492
493 result = g_accountManagerService->DeleteAccount(STRING_NAME);
494 EXPECT_EQ(result, ERR_OK);
495 }
496
497 /**
498 * @tc.name: seAppAccountManagerService_EnableAppAccess_0300
499 * @tc.desc: Enable app access with valid data.
500 * @tc.type: FUNC
501 * @tc.require: issueI5N90B
502 */
503 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_EnableAppAccess_0300, TestSize.Level1)
504 {
505 ACCOUNT_LOGI("seAppAccountManagerService_EnableAppAccess_0300");
506
507 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
508 EXPECT_EQ(result, ERR_OK);
509
510 result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
511 EXPECT_EQ(result, ERR_OK);
512
513 result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
514 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ENABLE_APP_ACCESS_ALREADY_EXISTS);
515
516 result = g_accountManagerService->DeleteAccount(STRING_NAME);
517 EXPECT_EQ(result, ERR_OK);
518 }
519
520 /**
521 * @tc.name: AppAccountManagerService_SetAppAccess_0300
522 * @tc.desc: Enable app access with valid data.
523 * @tc.type: FUNC
524 * @tc.require:
525 */
526 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAppAccess_0300, TestSize.Level1)
527 {
528 ACCOUNT_LOGI("AppAccountManagerService_SetAppAccess_0300");
529
530 CreateAccountOptions option;
531 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
532 EXPECT_EQ(result, ERR_OK);
533
534 result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_BUNDLE_NAME, true);
535 EXPECT_EQ(result, ERR_OK);
536
537 result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_BUNDLE_NAME, true);
538 EXPECT_EQ(result, ERR_OK);
539
540 result = g_accountManagerService->DeleteAccount(STRING_NAME);
541 EXPECT_EQ(result, ERR_OK);
542 }
543
544 /**
545 * @tc.name: seAppAccountManagerService_EnableAppAccess_0400
546 * @tc.desc: Enable app access with invalid data.
547 * @tc.type: FUNC
548 * @tc.require: issueI5N90B
549 */
550 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_EnableAppAccess_0400, TestSize.Level1)
551 {
552 ACCOUNT_LOGI("seAppAccountManagerService_EnableAppAccess_0400");
553
554 ErrCode result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
555 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
556 }
557
558 /**
559 * @tc.name: AppAccountManagerService_SetAppAccess_0400
560 * @tc.desc: Enable app access with invalid data.
561 * @tc.type: FUNC
562 * @tc.require:
563 */
564 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAppAccess_0400, TestSize.Level1)
565 {
566 ACCOUNT_LOGI("AppAccountManagerService_SetAppAccess_0400");
567
568 ErrCode result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_BUNDLE_NAME, true);
569 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
570 }
571
572 /**
573 * @tc.name: seAppAccountManagerService_DisableAppAccess_0100
574 * @tc.desc: Disable app access with invalid data.
575 * @tc.type: FUNC
576 * @tc.require: issueI5N90B
577 */
578 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_DisableAppAccess_0100, TestSize.Level1)
579 {
580 ACCOUNT_LOGI("seAppAccountManagerService_DisableAppAccess_0100");
581
582 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
583 EXPECT_EQ(result, ERR_OK);
584
585 result = g_accountManagerService->DisableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
586 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_DISABLE_APP_ACCESS_NOT_EXISTED);
587
588 result = g_accountManagerService->DeleteAccount(STRING_NAME);
589 EXPECT_EQ(result, ERR_OK);
590 }
591
592 /**
593 * @tc.name: AppAccountManagerService_SetAppAccess_0500
594 * @tc.desc: Disable app access with invalid data.
595 * @tc.type: FUNC
596 * @tc.require:
597 */
598 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAppAccess_0500, TestSize.Level1)
599 {
600 ACCOUNT_LOGI("AppAccountManagerService_SetAppAccess_0500");
601
602 CreateAccountOptions option;
603 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
604 EXPECT_EQ(result, ERR_OK);
605
606 result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_BUNDLE_NAME, false);
607 EXPECT_EQ(result, ERR_OK);
608
609 result = g_accountManagerService->DeleteAccount(STRING_NAME);
610 EXPECT_EQ(result, ERR_OK);
611 }
612
613 /**
614 * @tc.name: seAppAccountManagerService_DisableAppAccess_0200
615 * @tc.desc: Disable app access with invalid data.
616 * @tc.type: FUNC
617 * @tc.require: issueI5N90B
618 */
619 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_DisableAppAccess_0200, TestSize.Level1)
620 {
621 ACCOUNT_LOGI("seAppAccountManagerService_DisableAppAccess_0200");
622
623 ErrCode result = g_accountManagerService->DisableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
624 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
625 }
626
627 /**
628 * @tc.name: AppAccountManagerService_SetAppAccess_0600
629 * @tc.desc: Disable app access with invalid data.
630 * @tc.type: FUNC
631 * @tc.require: issueI5N90B
632 */
633 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAppAccess_0600, TestSize.Level1)
634 {
635 ACCOUNT_LOGI("AppAccountManagerService_SetAppAccess_0600");
636
637 ErrCode result = g_accountManagerService->SetAppAccess(STRING_NAME, STRING_BUNDLE_NAME, false);
638 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
639 }
640
641 /**
642 * @tc.name: seAppAccountManagerService_CheckAppAccountSyncEnable_0100
643 * @tc.desc: Check account sync enable with valid data.
644 * @tc.type: FUNC
645 * @tc.require: issueI5N90B
646 */
647 HWTEST_F(
648 AppAccountManagerServiceModuleTest, seAppAccountManagerService_CheckAppAccountSyncEnable_0100, TestSize.Level1)
649 {
650 ACCOUNT_LOGI("seAppAccountManagerService_CheckAppAccountSyncEnable_0100");
651
652 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
653 EXPECT_EQ(result, ERR_OK);
654
655 bool syncEnable = SYNC_ENABLE_FALSE;
656 result = g_accountManagerService->CheckAppAccountSyncEnable(STRING_NAME, syncEnable);
657 EXPECT_EQ(result, ERR_OK);
658 EXPECT_EQ(syncEnable, SYNC_ENABLE_FALSE);
659
660 result = g_accountManagerService->DeleteAccount(STRING_NAME);
661 EXPECT_EQ(result, ERR_OK);
662 }
663
664 /**
665 * @tc.name: seAppAccountManagerService_CheckAppAccountSyncEnable_0200
666 * @tc.desc: Check account sync enable with invalid data.
667 * @tc.type: FUNC
668 * @tc.require: issueI5N90B
669 */
670 HWTEST_F(
671 AppAccountManagerServiceModuleTest, seAppAccountManagerService_CheckAppAccountSyncEnable_0200, TestSize.Level1)
672 {
673 ACCOUNT_LOGI("seAppAccountManagerService_CheckAppAccountSyncEnable_0200");
674
675 bool syncEnable = SYNC_ENABLE_FALSE;
676 ErrCode result = g_accountManagerService->CheckAppAccountSyncEnable(STRING_NAME, syncEnable);
677 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
678 EXPECT_EQ(syncEnable, SYNC_ENABLE_FALSE);
679 }
680
681 /**
682 * @tc.name: seAppAccountManagerService_SetAppAccountSyncEnable_0100
683 * @tc.desc: Set account sync enable with valid data.
684 * @tc.type: FUNC
685 * @tc.require: issueI5N90B
686 */
687 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_SetAppAccountSyncEnable_0100, TestSize.Level1)
688 {
689 ACCOUNT_LOGI("seAppAccountManagerService_SetAppAccountSyncEnable_0100");
690
691 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
692 EXPECT_EQ(result, ERR_OK);
693
694 result = g_accountManagerService->SetAppAccountSyncEnable(STRING_NAME, SYNC_ENABLE_TRUE);
695 EXPECT_EQ(result, ERR_OK);
696
697 bool syncEnable = SYNC_ENABLE_FALSE;
698 result = g_accountManagerService->CheckAppAccountSyncEnable(STRING_NAME, syncEnable);
699 EXPECT_EQ(result, ERR_OK);
700 EXPECT_EQ(syncEnable, SYNC_ENABLE_TRUE);
701
702 result = g_accountManagerService->DeleteAccount(STRING_NAME);
703 EXPECT_EQ(result, ERR_OK);
704 }
705
706 /**
707 * @tc.name: seAppAccountManagerService_SetAppAccountSyncEnable_0200
708 * @tc.desc: Set account sync enable with valid data.
709 * @tc.type: FUNC
710 * @tc.require: issueI5N90B
711 */
712 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_SetAppAccountSyncEnable_0200, TestSize.Level1)
713 {
714 ACCOUNT_LOGI("seAppAccountManagerService_SetAppAccountSyncEnable_0200");
715
716 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
717 EXPECT_EQ(result, ERR_OK);
718
719 result = g_accountManagerService->SetAppAccountSyncEnable(STRING_NAME, SYNC_ENABLE_FALSE);
720 EXPECT_EQ(result, ERR_OK);
721
722 bool syncEnable = SYNC_ENABLE_FALSE;
723 result = g_accountManagerService->CheckAppAccountSyncEnable(STRING_NAME, syncEnable);
724 EXPECT_EQ(result, ERR_OK);
725 EXPECT_EQ(syncEnable, SYNC_ENABLE_FALSE);
726
727 result = g_accountManagerService->DeleteAccount(STRING_NAME);
728 EXPECT_EQ(result, ERR_OK);
729 }
730
731 /**
732 * @tc.name: seAppAccountManagerService_SetAppAccountSyncEnable_0300
733 * @tc.desc: Set account sync enable with invalid data.
734 * @tc.type: FUNC
735 * @tc.require: issueI5N90B
736 */
737 HWTEST_F(AppAccountManagerServiceModuleTest, seAppAccountManagerService_SetAppAccountSyncEnable_0300, TestSize.Level1)
738 {
739 ACCOUNT_LOGI("seAppAccountManagerService_SetAppAccountSyncEnable_0300");
740
741 ErrCode result = g_accountManagerService->SetAppAccountSyncEnable(STRING_NAME, SYNC_ENABLE_TRUE);
742 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
743 }
744
745 /**
746 * @tc.name: AppAccountManagerService_GetAccountCredential_0100
747 * @tc.desc: Get account credential with valid data.
748 * @tc.type: FUNC
749 * @tc.require: issueI5N90B
750 */
751 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAccountCredential_0100, TestSize.Level1)
752 {
753 ACCOUNT_LOGI("AppAccountManagerService_GetAccountCredential_0100");
754
755 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
756 EXPECT_EQ(result, ERR_OK);
757
758 result = g_accountManagerService->SetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL);
759 EXPECT_EQ(result, ERR_OK);
760
761 std::string credential;
762 result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, credential);
763 EXPECT_EQ(result, ERR_OK);
764 EXPECT_EQ(credential, STRING_CREDENTIAL);
765
766 result = g_accountManagerService->DeleteAccount(STRING_NAME);
767 EXPECT_EQ(result, ERR_OK);
768 }
769
770 /**
771 * @tc.name: AppAccountManagerService_GetAccountCredential_0200
772 * @tc.desc: Get account credential with valid data.
773 * @tc.type: FUNC
774 * @tc.require: issueI5N90B
775 */
776 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAccountCredential_0200, TestSize.Level1)
777 {
778 ACCOUNT_LOGI("AppAccountManagerService_GetAccountCredential_0200");
779
780 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
781 EXPECT_EQ(result, ERR_OK);
782
783 std::string credential;
784 result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, credential);
785 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_CREDENTIAL_NOT_EXIST);
786 EXPECT_EQ(credential, STRING_EMPTY);
787
788 result = g_accountManagerService->DeleteAccount(STRING_NAME);
789 EXPECT_EQ(result, ERR_OK);
790 }
791
792 /**
793 * @tc.name: AppAccountManagerService_GetAccountCredential_0300
794 * @tc.desc: Get account credential with invalid data.
795 * @tc.type: FUNC
796 * @tc.require: issueI5N90B
797 */
798 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAccountCredential_0300, TestSize.Level1)
799 {
800 ACCOUNT_LOGI("AppAccountManagerService_GetAccountCredential_0300");
801
802 std::string credential;
803 ErrCode result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, credential);
804 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_ACCOUNT_INFO_BY_ID);
805 EXPECT_EQ(credential, STRING_EMPTY);
806 }
807
808 /**
809 * @tc.name: AppAccountManagerService_GetAccountCredential_0400
810 * @tc.desc: Get account credential with valid data.
811 * @tc.type: FUNC
812 * @tc.require: issueI5N90B
813 */
814 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAccountCredential_0400, TestSize.Level1)
815 {
816 ACCOUNT_LOGI("AppAccountManagerService_GetAccountCredential_0400");
817
818 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
819 EXPECT_EQ(result, ERR_OK);
820
821 result = g_accountManagerService->SetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL);
822 EXPECT_EQ(result, ERR_OK);
823
824 result = g_accountManagerService->SetAccountCredential(STRING_NAME,
825 STRING_CREDENTIAL_TYPE_TWO, STRING_CREDENTIAL_TWO);
826 EXPECT_EQ(result, ERR_OK);
827
828 std::string credential;
829 result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, credential);
830 EXPECT_EQ(result, ERR_OK);
831 EXPECT_EQ(credential, STRING_CREDENTIAL);
832
833 result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE_TWO, credential);
834 EXPECT_EQ(result, ERR_OK);
835 EXPECT_EQ(credential, STRING_CREDENTIAL_TWO);
836
837 result = g_accountManagerService->DeleteAccount(STRING_NAME);
838 EXPECT_EQ(result, ERR_OK);
839 }
840
841 /**
842 * @tc.name: AppAccountManagerService_SetAccountCredential_0100
843 * @tc.desc: Set account credential with valid data.
844 * @tc.type: FUNC
845 * @tc.require: issueI5N90B
846 */
847 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAccountCredential_0100, TestSize.Level1)
848 {
849 ACCOUNT_LOGI("AppAccountManagerService_SetAccountCredential_0100");
850
851 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
852 EXPECT_EQ(result, ERR_OK);
853
854 result = g_accountManagerService->SetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL);
855 EXPECT_EQ(result, ERR_OK);
856
857 result = g_accountManagerService->DeleteAccount(STRING_NAME);
858 EXPECT_EQ(result, ERR_OK);
859 }
860
861 /**
862 * @tc.name: AppAccountManagerService_SetAccountCredential_0200
863 * @tc.desc: Set account credential with valid data.
864 * @tc.type: FUNC
865 * @tc.require: issueI5N90B
866 */
867 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAccountCredential_0200, TestSize.Level1)
868 {
869 ACCOUNT_LOGI("AppAccountManagerService_SetAccountCredential_0200");
870
871 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
872 EXPECT_EQ(result, ERR_OK);
873
874 result = g_accountManagerService->SetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL);
875 EXPECT_EQ(result, ERR_OK);
876
877 result = g_accountManagerService->SetAccountCredential(STRING_NAME,
878 STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL_TWO);
879 EXPECT_EQ(result, ERR_OK);
880
881 std::string credential;
882 result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, credential);
883 EXPECT_EQ(result, ERR_OK);
884 EXPECT_EQ(credential, STRING_CREDENTIAL_TWO);
885
886 result = g_accountManagerService->DeleteAccount(STRING_NAME);
887 EXPECT_EQ(result, ERR_OK);
888 }
889
890 /**
891 * @tc.name: AppAccountManagerService_SetAccountCredential_0300
892 * @tc.desc: Set account credential with invalid data.
893 * @tc.type: FUNC
894 * @tc.require: issueI5N90B
895 */
896 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAccountCredential_0300, TestSize.Level1)
897 {
898 ACCOUNT_LOGI("AppAccountManagerService_SetAccountCredential_0300");
899
900 ErrCode result = g_accountManagerService->SetAccountCredential(STRING_NAME,
901 STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL);
902 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
903 }
904
905 /**
906 * @tc.name: AppAccountManagerService_GetOAuthToken_0100
907 * @tc.desc: Get oauth token failed with non-existent account.
908 * @tc.type: FUNC
909 * @tc.require: issueI5N90B
910 */
911 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetOAuthToken_0100, TestSize.Level0)
912 {
913 ACCOUNT_LOGI("AppAccountManagerService_GetOAuthToken_0100");
914
915 std::string token;
916 ErrCode result = g_accountManagerService->GetOAuthToken(STRING_NAME, STRING_OWNER, STRING_AUTH_TYPE, token);
917 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
918 EXPECT_EQ(token, STRING_EMPTY);
919 }
920
921 /**
922 * @tc.name: AppAccountManagerService_GetAuthToken_0100
923 * @tc.desc: Get oauth token failed with non-existent account.
924 * @tc.type: FUNC
925 * @tc.require:
926 */
927 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthToken_0100, TestSize.Level0)
928 {
929 ACCOUNT_LOGI("AppAccountManagerService_GetAuthToken_0100");
930
931 std::string token;
932 ErrCode result = g_accountManagerService->GetAuthToken(STRING_NAME, STRING_OWNER, STRING_AUTH_TYPE, token);
933 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
934 EXPECT_EQ(token, STRING_EMPTY);
935 }
936
937 /**
938 * @tc.name: AppAccountManagerService_GetOAuthToken_0200
939 * @tc.desc: Get oauth token failed for non-existent oauth token.
940 * @tc.type: FUNC
941 * @tc.require: issueI5N90B
942 */
943 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetOAuthToken_0200, TestSize.Level0)
944 {
945 ACCOUNT_LOGI("AppAccountManagerService_GetOAuthToken_0200");
946
947 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
948 EXPECT_EQ(result, ERR_OK);
949
950 std::vector<AppAccountInfo> appAccounts;
951 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
952 EXPECT_EQ(result, ERR_OK);
953 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
954 std::string owner;
955 appAccounts[0].GetOwner(owner);
956
957 std::string token;
958 result = g_accountManagerService->GetOAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
959 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST);
960 EXPECT_EQ(token, STRING_EMPTY);
961
962 result = g_accountManagerService->DeleteAccount(STRING_NAME);
963 EXPECT_EQ(result, ERR_OK);
964 }
965
966 /**
967 * @tc.name: AppAccountManagerService_GetAuthToken_0200
968 * @tc.desc: Get oauth token failed for non-existent oauth token.
969 * @tc.type: FUNC
970 * @tc.require:
971 */
972 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthToken_0200, TestSize.Level0)
973 {
974 ACCOUNT_LOGI("AppAccountManagerService_GetAuthToken_0200");
975
976 CreateAccountOptions option;
977 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
978 EXPECT_EQ(result, ERR_OK);
979
980 std::vector<AppAccountInfo> appAccounts;
981 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
982 EXPECT_EQ(result, ERR_OK);
983 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
984 std::string owner;
985 appAccounts[0].GetOwner(owner);
986
987 std::string token;
988 result = g_accountManagerService->GetAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
989 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST);
990 EXPECT_EQ(token, STRING_EMPTY);
991
992 result = g_accountManagerService->DeleteAccount(STRING_NAME);
993 EXPECT_EQ(result, ERR_OK);
994 }
995
996 /**
997 * @tc.name: AppAccountManagerService_GetOAuthToken_0300
998 * @tc.desc: Get oauth token successfully.
999 * @tc.type: FUNC
1000 * @tc.require: issueI5N90B
1001 */
1002 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetOAuthToken_0300, TestSize.Level1)
1003 {
1004 ACCOUNT_LOGI("AppAccountManagerService_GetOAuthToken_0300");
1005
1006 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1007 EXPECT_EQ(result, ERR_OK);
1008
1009 std::vector<AppAccountInfo> appAccounts;
1010 g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1011 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1012 std::string owner;
1013 appAccounts[0].GetOwner(owner);
1014
1015 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1016 EXPECT_EQ(result, ERR_OK);
1017
1018 std::string token;
1019 result = g_accountManagerService->GetOAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
1020 EXPECT_EQ(result, ERR_OK);
1021 EXPECT_EQ(token, STRING_TOKEN);
1022
1023 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1024 EXPECT_EQ(result, ERR_OK);
1025 }
1026
1027 /**
1028 * @tc.name: AppAccountManagerService_GetAuthToken_0300
1029 * @tc.desc: Get oauth token successfully.
1030 * @tc.type: FUNC
1031 * @tc.require:
1032 */
1033 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthToken_0300, TestSize.Level1)
1034 {
1035 ACCOUNT_LOGI("AppAccountManagerService_GetAuthToken_0300");
1036
1037 CreateAccountOptions option;
1038 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1039 EXPECT_EQ(result, ERR_OK);
1040
1041 std::vector<AppAccountInfo> appAccounts;
1042 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1043 EXPECT_EQ(result, ERR_OK);
1044 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1045 std::string owner;
1046 appAccounts[0].GetOwner(owner);
1047
1048 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1049 EXPECT_EQ(result, ERR_OK);
1050
1051 std::string token;
1052 result = g_accountManagerService->GetAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
1053 EXPECT_EQ(result, ERR_OK);
1054 EXPECT_EQ(token, STRING_TOKEN);
1055
1056 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1057 EXPECT_EQ(result, ERR_OK);
1058 }
1059
1060 /**
1061 * @tc.name: AppAccountManagerService_SetOAuthToken_0100
1062 * @tc.desc: Set oauth token failed with non-exist account.
1063 * @tc.type: FUNC
1064 * @tc.require: issueI5N90B
1065 */
1066 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetOAuthToken_0100, TestSize.Level1)
1067 {
1068 ACCOUNT_LOGI("AppAccountManagerService_SetOAuthToken_0100");
1069
1070 ErrCode result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1071 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1072 }
1073
1074 /**
1075 * @tc.name: AppAccountManagerService_SetOAuthToken_0200
1076 * @tc.desc: Set oauth token successfully.
1077 * @tc.type: FUNC
1078 * @tc.require: issueI5N90B
1079 */
1080 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetOAuthToken_0200, TestSize.Level1)
1081 {
1082 ACCOUNT_LOGI("AppAccountManagerService_SetOAuthToken_0200");
1083
1084 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1085 EXPECT_EQ(result, ERR_OK);
1086
1087 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1088 EXPECT_EQ(result, ERR_OK);
1089
1090 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE_TWO, STRING_TOKEN_TWO);
1091 EXPECT_EQ(result, ERR_OK);
1092
1093 std::vector<AppAccountInfo> appAccounts;
1094 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1095 EXPECT_EQ(result, ERR_OK);
1096 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1097 std::string owner;
1098 appAccounts[0].GetOwner(owner);
1099
1100 std::string token;
1101 result = g_accountManagerService->GetOAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE_TWO, token);
1102 EXPECT_EQ(result, ERR_OK);
1103 EXPECT_EQ(token, STRING_TOKEN_TWO);
1104
1105 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1106 EXPECT_EQ(result, ERR_OK);
1107 }
1108
1109 /**
1110 * @tc.name: AppAccountManagerService_DeleteOAuthToken_0100
1111 * @tc.desc: Delete oauth token failed with non-exist account.
1112 * @tc.type: FUNC
1113 * @tc.require: issueI5N90B
1114 */
1115 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteOAuthToken_0100, TestSize.Level1)
1116 {
1117 ACCOUNT_LOGI("AppAccountManagerService_DeleteOAuthToken_0100");
1118
1119 ErrCode result = g_accountManagerService->DeleteOAuthToken(STRING_NAME,
1120 STRING_OWNER, STRING_AUTH_TYPE, STRING_TOKEN);
1121 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1122 }
1123
1124 /**
1125 * @tc.name: AppAccountManagerService_DeleteAuthToken_0100
1126 * @tc.desc: Delete oauth token failed with non-exist account.
1127 * @tc.type: FUNC
1128 * @tc.require:
1129 */
1130 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAuthToken_0100, TestSize.Level1)
1131 {
1132 ACCOUNT_LOGI("AppAccountManagerService_DeleteAuthToken_0100");
1133
1134 ErrCode result = g_accountManagerService->DeleteAuthToken(STRING_NAME,
1135 STRING_OWNER, STRING_AUTH_TYPE, STRING_TOKEN);
1136 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1137 }
1138
1139 /**
1140 * @tc.name: AppAccountManagerService_DeleteOAuthToken_0200
1141 * @tc.desc: Delete oauth token successfully with non-existent token.
1142 * @tc.type: FUNC
1143 * @tc.require: issueI5N90B
1144 */
1145 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteOAuthToken_0200, TestSize.Level1)
1146 {
1147 ACCOUNT_LOGI("AppAccountManagerService_DeleteOAuthToken_0200");
1148
1149 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1150 EXPECT_EQ(result, ERR_OK);
1151
1152 std::vector<AppAccountInfo> appAccounts;
1153 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1154 EXPECT_EQ(result, ERR_OK);
1155 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1156 std::string owner;
1157 appAccounts[0].GetOwner(owner);
1158
1159 result = g_accountManagerService->DeleteOAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, STRING_TOKEN);
1160 EXPECT_EQ(result, ERR_OK);
1161
1162 std::string token;
1163 result = g_accountManagerService->GetOAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
1164 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST);
1165 EXPECT_EQ(token, STRING_EMPTY);
1166
1167 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1168 EXPECT_EQ(result, ERR_OK);
1169 }
1170
1171 /**
1172 * @tc.name: AppAccountManagerService_DeleteAuthToken_0200
1173 * @tc.desc: Delete oauth token successfully with non-existent token.
1174 * @tc.type: FUNC
1175 * @tc.require: issueI5N90B
1176 */
1177 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAuthToken_0200, TestSize.Level1)
1178 {
1179 ACCOUNT_LOGI("AppAccountManagerService_DeleteAuthToken_0200");
1180
1181 CreateAccountOptions option;
1182 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1183 EXPECT_EQ(result, ERR_OK);
1184
1185 std::vector<AppAccountInfo> appAccounts;
1186 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1187 EXPECT_EQ(result, ERR_OK);
1188 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1189 std::string owner;
1190 appAccounts[0].GetOwner(owner);
1191
1192 result = g_accountManagerService->DeleteAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, STRING_TOKEN);
1193 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST);
1194
1195 std::string token;
1196 result = g_accountManagerService->GetAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
1197 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST);
1198 EXPECT_EQ(token, STRING_EMPTY);
1199
1200 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1201 EXPECT_EQ(result, ERR_OK);
1202 }
1203
1204 /**
1205 * @tc.name: AppAccountManagerService_DeleteOAuthToken_0300
1206 * @tc.desc: Delete oauth token successfully with existent token.
1207 * @tc.type: FUNC
1208 * @tc.require: issueI5N90B
1209 */
1210 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteOAuthToken_0300, TestSize.Level1)
1211 {
1212 ACCOUNT_LOGI("AppAccountManagerService_DeleteOAuthToken_0300");
1213
1214 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1215 EXPECT_EQ(result, ERR_OK);
1216
1217 std::vector<AppAccountInfo> appAccounts;
1218 g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1219 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1220 std::string owner;
1221 appAccounts[0].GetOwner(owner);
1222
1223 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1224 EXPECT_EQ(result, ERR_OK);
1225
1226 result = g_accountManagerService->DeleteOAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, STRING_TOKEN);
1227 EXPECT_EQ(result, ERR_OK);
1228
1229 std::string token;
1230 result = g_accountManagerService->GetOAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
1231 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST);
1232 EXPECT_EQ(token, STRING_EMPTY);
1233
1234 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1235 EXPECT_EQ(result, ERR_OK);
1236 }
1237
1238 /**
1239 * @tc.name: AppAccountManagerService_DeleteAuthToken_0300
1240 * @tc.desc: Delete oauth token successfully with non-existent token.
1241 * @tc.type: FUNC
1242 * @tc.require:
1243 */
1244 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAuthToken_0300, TestSize.Level1)
1245 {
1246 ACCOUNT_LOGI("AppAccountManagerService_DeleteAuthToken_0300");
1247
1248 CreateAccountOptions option;
1249 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1250 EXPECT_EQ(result, ERR_OK);
1251
1252 std::vector<AppAccountInfo> appAccounts;
1253 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1254 EXPECT_EQ(result, ERR_OK);
1255 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1256 std::string owner;
1257 appAccounts[0].GetOwner(owner);
1258
1259 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1260 EXPECT_EQ(result, ERR_OK);
1261
1262 std::string token;
1263 result = g_accountManagerService->GetAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
1264 EXPECT_EQ(result, ERR_OK);
1265 EXPECT_EQ(token, STRING_TOKEN);
1266
1267 result = g_accountManagerService->DeleteAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, STRING_TOKEN);
1268 EXPECT_EQ(result, ERR_OK);
1269
1270 token = "";
1271 result = g_accountManagerService->GetAuthToken(STRING_NAME, owner, STRING_AUTH_TYPE, token);
1272 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TOKEN_NOT_EXIST);
1273 EXPECT_EQ(token, STRING_EMPTY);
1274
1275 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1276 EXPECT_EQ(result, ERR_OK);
1277 }
1278
1279 /**
1280 * @tc.name: AppAccountManagerService_GetAllOAuthTokens_0100
1281 * @tc.desc: Get all oauth token failed for non-existent account.
1282 * @tc.type: FUNC
1283 * @tc.require: issueI5N90B
1284 */
1285 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllOAuthTokens_0100, TestSize.Level1)
1286 {
1287 ACCOUNT_LOGI("AppAccountManagerService_GetAllOAuthTokens_0100");
1288
1289 std::vector<OAuthTokenInfo> tokenInfos;
1290 ErrCode result = g_accountManagerService->GetAllOAuthTokens(STRING_NAME, STRING_OWNER, tokenInfos);
1291 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1292 }
1293
1294 /**
1295 * @tc.name: AppAccountManagerService_GetAllOAuthTokens_0200
1296 * @tc.desc: Get all oauth token successfully.
1297 * @tc.type: FUNC
1298 * @tc.require: issueI5N90B
1299 */
1300 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllOAuthTokens_0200, TestSize.Level1)
1301 {
1302 ACCOUNT_LOGI("AppAccountManagerService_GetAllOAuthTokens_0200");
1303
1304 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1305 EXPECT_EQ(result, ERR_OK);
1306
1307 std::vector<AppAccountInfo> appAccounts;
1308 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1309 EXPECT_EQ(result, ERR_OK);
1310 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1311 std::string owner;
1312 appAccounts[0].GetOwner(owner);
1313
1314 std::vector<OAuthTokenInfo> tokenInfos;
1315 result = g_accountManagerService->GetAllOAuthTokens(STRING_NAME, owner, tokenInfos);
1316 EXPECT_EQ(result, ERR_OK);
1317 ASSERT_EQ(tokenInfos.size(), static_cast<size_t>(0));
1318
1319 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1320 EXPECT_EQ(result, ERR_OK);
1321
1322 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE_TWO, STRING_TOKEN_TWO);
1323 EXPECT_EQ(result, ERR_OK);
1324
1325 tokenInfos.clear();
1326 result = g_accountManagerService->GetAllOAuthTokens(STRING_NAME, owner, tokenInfos);
1327 EXPECT_EQ(result, ERR_OK);
1328 ASSERT_EQ(tokenInfos.size(), SIZE_TWO);
1329 EXPECT_EQ(tokenInfos[0].token, STRING_TOKEN);
1330 EXPECT_EQ(tokenInfos[1].token, STRING_TOKEN_TWO);
1331
1332 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1333 EXPECT_EQ(result, ERR_OK);
1334 }
1335
1336 /**
1337 * @tc.name: AppAccountManagerService_SetOAuthTokenVisibility_0100
1338 * @tc.desc: Set oauth token failed with non-existent account.
1339 * @tc.type: FUNC
1340 * @tc.require: issueI5N90B
1341 */
1342 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetOAuthTokenVisibility_0100, TestSize.Level1)
1343 {
1344 ACCOUNT_LOGI("AppAccountManagerService_SetOAuthTokenVisibility_0100");
1345
1346 ErrCode result = g_accountManagerService->SetOAuthTokenVisibility(STRING_NAME,
1347 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1348 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1349 }
1350
1351 /**
1352 * @tc.name: AppAccountManagerService_SetAuthTokenVisibility_0100
1353 * @tc.desc: Set oauth token failed with non-existent account.
1354 * @tc.type: FUNC
1355 * @tc.require: issueI5N90B
1356 */
1357 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAuthTokenVisibility_0100, TestSize.Level1)
1358 {
1359 ACCOUNT_LOGI("AppAccountManagerService_SetAuthTokenVisibility_0100");
1360
1361 ErrCode result = g_accountManagerService->SetAuthTokenVisibility(STRING_NAME,
1362 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1363 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1364 }
1365
1366 /**
1367 * @tc.name: AppAccountManagerService_SetAuthTokenVisibility_0100
1368 * @tc.desc: Set oauth token failed with non-existent owner.
1369 * @tc.type: FUNC
1370 * @tc.require: issueI5N90B
1371 */
1372 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAuthTokenVisibility_01001, TestSize.Level1)
1373 {
1374 ACCOUNT_LOGI("AppAccountManagerService_SetAuthTokenVisibility_01001");
1375
1376 CreateAccountOptions option;
1377 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1378 EXPECT_EQ(result, ERR_OK);
1379
1380 result = g_accountManagerService->SetAuthTokenVisibility(STRING_NAME,
1381 STRING_AUTH_TYPE, STRING_BUNDLE_NAME_NOT_INSTALLED, true);
1382 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TYPE_NOT_EXIST);
1383
1384 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1385 EXPECT_EQ(result, ERR_OK);
1386 }
1387
1388 /**
1389 * @tc.name: AppAccountManagerService_SetOAuthTokenVisibility_0200
1390 * @tc.desc: Set oauth token visibility with non-existent authType successfully.
1391 * @tc.type: FUNC
1392 * @tc.require: issueI5N90B
1393 */
1394 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetOAuthTokenVisibility_0200, TestSize.Level1)
1395 {
1396 ACCOUNT_LOGI("AppAccountManagerService_SetOAuthTokenVisibility_0200");
1397
1398 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1399 EXPECT_EQ(result, ERR_OK);
1400
1401 bool isVisible = true;
1402 result = g_accountManagerService->CheckOAuthTokenVisibility(STRING_NAME,
1403 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1404 EXPECT_EQ(result, ERR_OK);
1405 EXPECT_EQ(isVisible, false);
1406
1407 result = g_accountManagerService->SetOAuthTokenVisibility(STRING_NAME,
1408 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1409 EXPECT_EQ(result, ERR_OK);
1410
1411 isVisible = false;
1412 result = g_accountManagerService->CheckOAuthTokenVisibility(STRING_NAME,
1413 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1414 EXPECT_EQ(result, ERR_OK);
1415 EXPECT_EQ(isVisible, true);
1416
1417 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1418 EXPECT_EQ(result, ERR_OK);
1419 }
1420
1421 /**
1422 * @tc.name: AppAccountManagerService_SetAuthTokenVisibility_0200
1423 * @tc.desc: Set oauth token visibility with non-existent authType.
1424 * @tc.type: FUNC
1425 * @tc.require: issueI5N90B
1426 */
1427 // STRING_OWNER valid owner
1428 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAuthTokenVisibility_0200, TestSize.Level1)
1429 {
1430 ACCOUNT_LOGI("AppAccountManagerService_SetAuthTokenVisibility_0200");
1431
1432 CreateAccountOptions option;
1433 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1434 EXPECT_EQ(result, ERR_OK);
1435
1436 bool isVisible = false;
1437 result = g_accountManagerService->CheckAuthTokenVisibility(STRING_NAME,
1438 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1439 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TYPE_NOT_EXIST);
1440
1441 result = g_accountManagerService->SetAuthTokenVisibility(STRING_NAME,
1442 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1443 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TYPE_NOT_EXIST);
1444
1445 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1446 EXPECT_EQ(result, ERR_OK);
1447 }
1448
1449 /**
1450 * @tc.name: AppAccountManagerService_SetOAuthTokenVisibility_0300
1451 * @tc.desc: Set oauth token visibility with existent authType successfully.
1452 * @tc.type: FUNC
1453 * @tc.require: issueI5N90B
1454 */
1455 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetOAuthTokenVisibility_0300, TestSize.Level1)
1456 {
1457 ACCOUNT_LOGI("AppAccountManagerService_SetOAuthTokenVisibility_0300");
1458
1459 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1460 EXPECT_EQ(result, ERR_OK);
1461
1462 std::vector<AppAccountInfo> appAccounts;
1463 g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1464 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1465 std::string owner;
1466 appAccounts[0].GetOwner(owner);
1467
1468 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1469 EXPECT_EQ(result, ERR_OK);
1470
1471 result = g_accountManagerService->SetOAuthTokenVisibility(STRING_NAME,
1472 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1473 EXPECT_EQ(result, ERR_OK);
1474
1475 bool isVisible = false;
1476 result = g_accountManagerService->CheckOAuthTokenVisibility(STRING_NAME,
1477 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1478 EXPECT_EQ(result, ERR_OK);
1479 EXPECT_EQ(isVisible, true);
1480
1481 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1482 EXPECT_EQ(result, ERR_OK);
1483 }
1484
1485 /**
1486 * @tc.name: AppAccountManagerService_SetAuthTokenVisibility_0300
1487 * @tc.desc: Set oauth token visibility with existent authType successfully.
1488 * @tc.type: FUNC
1489 * @tc.require: issueI5N90B
1490 */
1491 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAuthTokenVisibility_0300, TestSize.Level1)
1492 {
1493 ACCOUNT_LOGI("AppAccountManagerService_SetAuthTokenVisibility_0300");
1494
1495 CreateAccountOptions option;
1496 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1497 EXPECT_EQ(result, ERR_OK);
1498
1499 // check self
1500 bool isVisible = false;
1501 result = g_accountManagerService->CheckAuthTokenVisibility(STRING_NAME,
1502 STRING_AUTH_TYPE, STRING_OWNER, isVisible);
1503 EXPECT_EQ(result, ERR_OK);
1504 EXPECT_EQ(isVisible, true);
1505
1506 result = g_accountManagerService->SetAuthTokenVisibility(STRING_NAME,
1507 STRING_AUTH_TYPE, STRING_OWNER, false);
1508 EXPECT_EQ(result, ERR_ACCOUNT_COMMON_INVALID_PARAMETER);
1509
1510 result = g_accountManagerService->CheckAuthTokenVisibility(STRING_NAME,
1511 STRING_AUTH_TYPE, STRING_OWNER, isVisible);
1512 EXPECT_EQ(result, ERR_OK);
1513 EXPECT_EQ(isVisible, true);
1514
1515 // check other owners
1516 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1517 EXPECT_EQ(result, ERR_OK);
1518
1519 result = g_accountManagerService->SetAuthTokenVisibility(STRING_NAME,
1520 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1521 EXPECT_EQ(result, ERR_OK);
1522
1523 std::set<std::string> authList;
1524 result = g_accountManagerService->GetOAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1525 EXPECT_EQ(result, ERR_OK);
1526 ASSERT_EQ(authList.size(), SIZE_ONE);
1527
1528 result = g_accountManagerService->CheckAuthTokenVisibility(STRING_NAME,
1529 STRING_AUTH_TYPE, INVALID_STRING_OWNER, isVisible);
1530 EXPECT_EQ(result, ERR_OK);
1531 EXPECT_EQ(isVisible, false);
1532
1533 result = g_accountManagerService->CheckAuthTokenVisibility(STRING_NAME,
1534 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1535 EXPECT_EQ(result, ERR_OK);
1536 EXPECT_EQ(isVisible, true);
1537
1538 result = g_accountManagerService->SetAuthTokenVisibility(STRING_NAME,
1539 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, false);
1540 EXPECT_EQ(result, ERR_OK);
1541
1542 result = g_accountManagerService->CheckAuthTokenVisibility(STRING_NAME,
1543 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1544 EXPECT_EQ(result, ERR_OK);
1545 EXPECT_EQ(isVisible, false);
1546
1547 authList.clear();
1548 result = g_accountManagerService->GetOAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1549 EXPECT_EQ(result, ERR_OK);
1550 ASSERT_EQ(authList.size(), 0);
1551
1552 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1553 EXPECT_EQ(result, ERR_OK);
1554 }
1555
1556 /**
1557 * @tc.name: AppAccountManagerService_CheckOAuthTokenVisibility_0100
1558 * @tc.desc: Check oauth token visibility successfully.
1559 * @tc.type: FUNC
1560 * @tc.require: issueI5N90B
1561 */
1562 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckOAuthTokenVisibility_0100, TestSize.Level1)
1563 {
1564 ACCOUNT_LOGI("AppAccountManagerService_CheckOAuthTokenVisibility_0100");
1565
1566 bool isVisible = true;
1567 ErrCode result = g_accountManagerService->CheckOAuthTokenVisibility(
1568 STRING_NAME, STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1569 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1570 EXPECT_EQ(isVisible, false);
1571
1572 result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1573 EXPECT_EQ(result, ERR_OK);
1574 std::vector<AppAccountInfo> appAccounts;
1575 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
1576 EXPECT_EQ(result, ERR_OK);
1577 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1578 std::string owner;
1579 appAccounts[0].GetOwner(owner);
1580
1581 isVisible = true;
1582 result = g_accountManagerService->CheckOAuthTokenVisibility(STRING_NAME,
1583 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1584 EXPECT_EQ(result, ERR_OK);
1585 EXPECT_EQ(isVisible, false);
1586
1587 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1588 EXPECT_EQ(result, ERR_OK);
1589
1590 result = g_accountManagerService->SetOAuthTokenVisibility(STRING_NAME,
1591 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1592 EXPECT_EQ(result, ERR_OK);
1593
1594 isVisible = false;
1595 result = g_accountManagerService->CheckOAuthTokenVisibility(STRING_NAME,
1596 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1597 EXPECT_EQ(result, ERR_OK);
1598 EXPECT_EQ(isVisible, true);
1599
1600 result = g_accountManagerService->SetOAuthTokenVisibility(STRING_NAME,
1601 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, false);
1602 EXPECT_EQ(result, ERR_OK);
1603
1604 isVisible = true;
1605 result = g_accountManagerService->CheckOAuthTokenVisibility(STRING_NAME,
1606 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1607 EXPECT_EQ(result, ERR_OK);
1608 EXPECT_EQ(isVisible, false);
1609
1610 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1611 EXPECT_EQ(result, ERR_OK);
1612 }
1613
1614 /**
1615 * @tc.name: AppAccountManagerService_CheckAuthTokenVisibility_0100
1616 * @tc.desc: Check oauth token visibility with non_exist account.
1617 * @tc.type: FUNC
1618 * @tc.require: issueI5N90B
1619 */
1620 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckAuthTokenVisibility_0100, TestSize.Level1)
1621 {
1622 ACCOUNT_LOGI("AppAccountManagerService_CheckAuthTokenVisibility_0100");
1623
1624 bool isVisible = true;
1625 ErrCode result = g_accountManagerService->CheckAuthTokenVisibility(
1626 STRING_NAME, STRING_AUTH_TYPE, STRING_BUNDLE_NAME, isVisible);
1627 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1628 EXPECT_EQ(isVisible, false);
1629 }
1630
1631 /**
1632 * @tc.name: AppAccountManagerService_GetOAuthList_0100
1633 * @tc.desc: Get oauth list failed with non-existent account.
1634 * @tc.type: FUNC
1635 * @tc.require: issueI5N90B
1636 */
1637 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetOAuthList_0100, TestSize.Level1)
1638 {
1639 ACCOUNT_LOGI("AppAccountManagerService_GetOAuthList_0100");
1640
1641 std::set<std::string> authList;
1642 ErrCode result = g_accountManagerService->GetOAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1643 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1644 }
1645
1646 /**
1647 * @tc.name: AppAccountManagerService_GetAuthList_0100
1648 * @tc.desc: Get oauth list failed with non-existent account.
1649 * @tc.type: FUNC
1650 * @tc.require:
1651 */
1652 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthList_0100, TestSize.Level1)
1653 {
1654 ACCOUNT_LOGI("AppAccountManagerService_GetAuthList_0100");
1655
1656 std::set<std::string> authList;
1657 ErrCode result = g_accountManagerService->GetAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1658 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_NOT_EXIST);
1659 }
1660
1661 /**
1662 * @tc.name: AppAccountManagerService_GetOAuthList_0200
1663 * @tc.desc: Get oauth list with non-existent authType successfully.
1664 * @tc.type: FUNC
1665 * @tc.require: issueI5N90B
1666 */
1667 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetOAuthList_0200, TestSize.Level1)
1668 {
1669 ACCOUNT_LOGI("AppAccountManagerService_GetOAuthList_0200");
1670
1671 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1672 EXPECT_EQ(result, ERR_OK);
1673
1674 std::set<std::string> authList;
1675 result = g_accountManagerService->GetOAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1676 EXPECT_EQ(result, ERR_OK);
1677 ASSERT_EQ(authList.size(), SIZE_ZERO);
1678
1679 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1680 EXPECT_EQ(result, ERR_OK);
1681 }
1682
1683 /**
1684 * @tc.name: AppAccountManagerService_GetAuthList_0200
1685 * @tc.desc: Get oauth list with non-existent authType successfully.
1686 * @tc.type: FUNC
1687 * @tc.require: issueI5N90B
1688 */
1689 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthList_0200, TestSize.Level1)
1690 {
1691 ACCOUNT_LOGI("AppAccountManagerService_GetAuthList_0200");
1692
1693 CreateAccountOptions option;
1694 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1695 EXPECT_EQ(result, ERR_OK);
1696
1697 std::set<std::string> authList;
1698 result = g_accountManagerService->GetAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1699 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_TYPE_NOT_EXIST);
1700
1701 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1702 EXPECT_EQ(result, ERR_OK);
1703 }
1704
1705 /**
1706 * @tc.name: AppAccountManagerService_GetOAuthList_0300
1707 * @tc.desc: Get oauth list with existent authType successfully.
1708 * @tc.type: FUNC
1709 * @tc.require: issueI5N90B
1710 */
1711 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetOAuthList_0300, TestSize.Level1)
1712 {
1713 ACCOUNT_LOGI("AppAccountManagerService_GetOAuthList_0300");
1714
1715 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1716 EXPECT_EQ(result, ERR_OK);
1717
1718 result = g_accountManagerService->SetOAuthTokenVisibility(STRING_NAME,
1719 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1720 EXPECT_EQ(result, ERR_OK);
1721
1722 result = g_accountManagerService->SetOAuthTokenVisibility(
1723 STRING_NAME, STRING_AUTH_TYPE, STRING_BUNDLE_NAME_NOT_INSTALLED, true);
1724 EXPECT_EQ(result, ERR_OK);
1725
1726 std::set<std::string> authList;
1727 result = g_accountManagerService->GetOAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1728 EXPECT_EQ(result, ERR_OK);
1729 ASSERT_EQ(authList.size(), SIZE_TWO);
1730
1731 auto it = authList.find(STRING_BUNDLE_NAME);
1732 EXPECT_NE(it, authList.end());
1733 it = authList.find(STRING_BUNDLE_NAME_NOT_INSTALLED);
1734 EXPECT_NE(it, authList.end());
1735
1736 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1737 EXPECT_EQ(result, ERR_OK);
1738 }
1739
1740 /**
1741 * @tc.name: AppAccountManagerService_GetAuthList_0400
1742 * @tc.desc: Get oauth list with existent authType successfully.
1743 * @tc.type: FUNC
1744 * @tc.require: issueI5N90B
1745 */
1746 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthList_0400, TestSize.Level1)
1747 {
1748 ACCOUNT_LOGI("AppAccountManagerService_GetAuthList_0400");
1749
1750 CreateAccountOptions option;
1751 ErrCode result = g_accountManagerService->CreateAccount(STRING_NAME, option);
1752 EXPECT_EQ(result, ERR_OK);
1753
1754 result = g_accountManagerService->SetOAuthToken(STRING_NAME, STRING_AUTH_TYPE, STRING_TOKEN);
1755 EXPECT_EQ(result, ERR_OK);
1756
1757 result = g_accountManagerService->SetAuthTokenVisibility(STRING_NAME,
1758 STRING_AUTH_TYPE, STRING_BUNDLE_NAME, true);
1759 EXPECT_EQ(result, ERR_OK);
1760
1761 std::set<std::string> authList;
1762 result = g_accountManagerService->GetAuthList(STRING_NAME, STRING_AUTH_TYPE, authList);
1763 EXPECT_EQ(result, ERR_OK);
1764 ASSERT_EQ(authList.size(), SIZE_ONE);
1765
1766 auto it = authList.find(STRING_BUNDLE_NAME);
1767 EXPECT_NE(it, authList.end());
1768 it = authList.find(STRING_BUNDLE_NAME_NOT_INSTALLED);
1769 EXPECT_EQ(it, authList.end());
1770
1771 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1772 EXPECT_EQ(result, ERR_OK);
1773 }
1774
1775 /**
1776 * @tc.name: AppAccountManagerService_GetAuthenticatorInfo_0100
1777 * @tc.desc: Get authenticator info failed for non-existent oauth service.
1778 * @tc.type: FUNC
1779 * @tc.require: issueI5N90B
1780 */
1781 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthenticatorInfo_0100, TestSize.Level1)
1782 {
1783 ACCOUNT_LOGI("AppAccountManagerService_GetAuthenticatorInfo_0100");
1784
1785 AuthenticatorInfo info;
1786 ErrCode result = g_accountManagerService->GetAuthenticatorInfo(STRING_OWNER, info);
1787 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_NOT_EXIST);
1788 }
1789
1790 /**
1791 * @tc.name: AppAccountManagerService_GetAuthenticatorCallback_0100
1792 * @tc.desc: Get authenticator callback failed with non-existent sessionId.
1793 * @tc.type: FUNC
1794 * @tc.require: issueI5N90B
1795 */
1796 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAuthenticatorCallback_0100, TestSize.Level1)
1797 {
1798 ACCOUNT_LOGI("AppAccountManagerService_GetAuthenticatorCallback_0100");
1799
1800 sptr<IRemoteObject> callback;
1801 ErrCode result = g_accountManagerService->GetAuthenticatorCallback(STRING_SESSION_ID, callback);
1802 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_SESSION_NOT_EXIST);
1803 }
1804
1805 /**
1806 * @tc.name: AppAccountManagerService_AddAccountImplicitly_0100
1807 * @tc.desc: Add account implicitly failed for non-existent oauth service.
1808 * @tc.type: FUNC
1809 * @tc.require: issueI5N90B
1810 */
1811 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_AddAccountImplicitly_0100, TestSize.Level1)
1812 {
1813 ACCOUNT_LOGI("AppAccountManagerService_AddAccountImplicitly_0100");
1814
1815 AAFwk::Want options;
1816 options.SetParam(AccountSA::Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
1817 sptr<IAppAccountAuthenticatorCallback> callback = nullptr;
1818 ErrCode result = g_accountManagerService->AddAccountImplicitly(
1819 STRING_OWNER, STRING_AUTH_TYPE, options, callback);
1820 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_NOT_EXIST);
1821 }
1822
1823 /**
1824 * @tc.name: AppAccountManagerService_CreateAccountImplicitly_0100
1825 * @tc.desc: Add account implicitly failed for non-existent oauth service.
1826 * @tc.type: FUNC
1827 * @tc.require: issueI5RWXN
1828 */
1829 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CreateAccountImplicitly_0100, TestSize.Level1)
1830 {
1831 ACCOUNT_LOGI("AppAccountManagerService_CreateAccountImplicitly_0100");
1832
1833 CreateAccountImplicitlyOptions options;
1834 options.parameters.SetParam(AccountSA::Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
1835 sptr<IAppAccountAuthenticatorCallback> callback = nullptr;
1836 ErrCode result = g_accountManagerService->CreateAccountImplicitly(
1837 STRING_OWNER, options, callback);
1838 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_NOT_EXIST);
1839 }
1840
1841 /**
1842 * @tc.name: AppAccountManagerService_Authenticate_0100
1843 * @tc.desc: authenticate failed for non-existent oauth service.
1844 * @tc.type: FUNC
1845 * @tc.require: issueI5N90B
1846 */
1847 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_Authenticate_0100, TestSize.Level1)
1848 {
1849 ACCOUNT_LOGI("AppAccountManagerService_Authenticate_0100");
1850
1851 AAFwk::Want options;
1852 options.SetParam(AccountSA::Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
1853 sptr<IAppAccountAuthenticatorCallback> callback = nullptr;
1854 ErrCode result = g_accountManagerService->Authenticate(STRING_NAME,
1855 STRING_OWNER, STRING_AUTH_TYPE, options, callback);
1856 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_NOT_EXIST);
1857 }
1858
1859 /**
1860 * @tc.name: AppAccountManagerService_Authenticate_v9_0100
1861 * @tc.desc: test version9 authenticate failed for non-existent oauth service.
1862 * @tc.type: FUNC
1863 * @tc.require: issueI5RWXN
1864 */
1865 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_Authenticate_v9_0100, TestSize.Level1)
1866 {
1867 ACCOUNT_LOGI("AppAccountManagerService_Authenticate_0100");
1868
1869 AAFwk::Want options;
1870 options.SetParam(AccountSA::Constants::KEY_CALLER_ABILITY_NAME, STRING_ABILITY_NAME);
1871 options.SetParam(AccountSA::Constants::API_V9, true);
1872 sptr<IAppAccountAuthenticatorCallback> callback = nullptr;
1873 ErrCode result = g_accountManagerService->Authenticate(STRING_NAME,
1874 STRING_OWNER, STRING_AUTH_TYPE, options, callback);
1875 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_OAUTH_AUTHENTICATOR_NOT_EXIST);
1876 }
1877
1878 /**
1879 * @tc.name: AppAccountManagerService_GetAllAccounts_0100
1880 * @tc.desc: Get all accounts with valid data.
1881 * @tc.type: FUNC
1882 * @tc.require: issueI5N90B
1883 */
1884 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccounts_0100, TestSize.Level0)
1885 {
1886 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccounts_0100");
1887
1888 std::vector<AppAccountInfo> appAccounts;
1889 ErrCode result = g_accountManagerService->GetAllAccounts(STRING_OWNER, appAccounts);
1890 EXPECT_EQ(result, ERR_OK);
1891 ASSERT_EQ(appAccounts.size(), SIZE_ZERO);
1892 }
1893
1894 /**
1895 * @tc.name: AppAccountManagerService_GetAllAccounts_0200
1896 * @tc.desc: Get all accounts with valid data.
1897 * @tc.type: FUNC
1898 * @tc.require: issueI5N90B
1899 */
1900 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccounts_0200, TestSize.Level1)
1901 {
1902 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccounts_0200");
1903
1904 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
1905 EXPECT_EQ(result, ERR_OK);
1906
1907 result = g_accountManagerService->AddAccount(STRING_NAME_TWO, STRING_EXTRA_INFO);
1908 EXPECT_EQ(result, ERR_OK);
1909
1910 std::vector<AppAccountInfo> appAccounts;
1911 result = g_accountManagerService->GetAllAccounts(STRING_OWNER, appAccounts);
1912 EXPECT_EQ(result, ERR_OK);
1913 ASSERT_EQ(appAccounts.size(), SIZE_TWO);
1914
1915 std::string name;
1916 appAccounts.begin()->GetName(name);
1917 EXPECT_EQ(name, STRING_NAME);
1918
1919 (appAccounts.begin() + SIZE_ONE)->GetName(name);
1920 EXPECT_EQ(name, STRING_NAME_TWO);
1921
1922 result = g_accountManagerService->DeleteAccount(STRING_NAME);
1923 EXPECT_EQ(result, ERR_OK);
1924
1925 result = g_accountManagerService->DeleteAccount(STRING_NAME_TWO);
1926 EXPECT_EQ(result, ERR_OK);
1927 }
1928
1929 /**
1930 * @tc.name: AppAccountManagerService_GetAllAccounts_0300
1931 * @tc.desc: Get all accounts with valid data.
1932 * @tc.type: FUNC
1933 * @tc.require: issueI5N90B
1934 */
1935 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccounts_0300, TestSize.Level1)
1936 {
1937 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccounts_0300");
1938
1939 std::vector<AppAccountInfo> appAccounts;
1940 ErrCode result = g_accountManagerService->GetAllAccounts(STRING_BUNDLE_NAME, appAccounts);
1941 EXPECT_EQ(result, ERR_OK);
1942 EXPECT_EQ(appAccounts.size(), SIZE_ZERO);
1943 }
1944
1945 /**
1946 * @tc.name: AppAccountManagerService_GetAllAccounts_0400
1947 * @tc.desc: Get all accounts with valid data.
1948 * @tc.type: FUNC
1949 * @tc.require: issueI5N90B
1950 */
1951 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccounts_0400, TestSize.Level1)
1952 {
1953 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccounts_0400");
1954
1955 AppAccountInfo appAccountInfo(STRING_NAME, STRING_BUNDLE_NAME);
1956 ErrCode result =
1957 AppAccountControlManager::GetInstance().AddAccount(
1958 STRING_NAME, STRING_EMPTY, UID, STRING_BUNDLE_NAME, appAccountInfo);
1959 EXPECT_EQ(result, ERR_OK);
1960
1961 AppAccountCallingInfo appAccountCallingInfo;
1962 appAccountCallingInfo.callingUid = UID;
1963 appAccountCallingInfo.bundleName = STRING_BUNDLE_NAME;
1964 result = AppAccountControlManager::GetInstance().EnableAppAccess(
1965 STRING_NAME, STRING_OWNER, appAccountCallingInfo, appAccountInfo);
1966 EXPECT_EQ(result, ERR_OK);
1967
1968 std::vector<AppAccountInfo> appAccounts;
1969 result = g_accountManagerService->GetAllAccounts(STRING_BUNDLE_NAME, appAccounts);
1970 EXPECT_EQ(result, ERR_OK);
1971 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
1972
1973 std::string owner;
1974 appAccounts.begin()->GetOwner(owner);
1975 EXPECT_EQ(owner, STRING_BUNDLE_NAME);
1976
1977 result = AppAccountControlManager::GetInstance().DeleteAccount(
1978 STRING_NAME, UID, STRING_BUNDLE_NAME, appAccountInfo);
1979 EXPECT_EQ(result, ERR_OK);
1980 }
1981
1982 /**
1983 * @tc.name: AppAccountManagerService_GetAllAccounts_0500
1984 * @tc.desc: Get all accounts with valid data.
1985 * @tc.type: FUNC
1986 * @tc.require: issueI5N90B
1987 */
1988 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccounts_0500, TestSize.Level1)
1989 {
1990 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccounts_0500");
1991
1992 AppAccountInfo appAccountInfo(STRING_NAME, STRING_BUNDLE_NAME);
1993 ErrCode result = AppAccountControlManager::GetInstance().AddAccount(
1994 STRING_NAME, STRING_EMPTY, UID, STRING_BUNDLE_NAME, appAccountInfo);
1995 EXPECT_EQ(result, ERR_OK);
1996
1997 AppAccountInfo appAccountInfoTwo(STRING_NAME_TWO, STRING_OWNER);
1998 result = AppAccountControlManager::GetInstance().AddAccount(
1999 STRING_NAME_TWO, STRING_EMPTY, UID, STRING_OWNER, appAccountInfoTwo);
2000 EXPECT_EQ(result, ERR_OK);
2001
2002 AppAccountCallingInfo appAccountCallingInfo;
2003 appAccountCallingInfo.callingUid = UID;
2004 appAccountCallingInfo.bundleName = STRING_BUNDLE_NAME;
2005 result = AppAccountControlManager::GetInstance().EnableAppAccess(
2006 STRING_NAME, STRING_OWNER, appAccountCallingInfo, appAccountInfo);
2007 EXPECT_EQ(result, ERR_OK);
2008
2009 std::vector<AppAccountInfo> appAccounts;
2010 result = g_accountManagerService->GetAllAccounts(STRING_BUNDLE_NAME, appAccounts);
2011 EXPECT_EQ(result, ERR_OK);
2012 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
2013
2014 std::string owner;
2015 appAccounts.begin()->GetOwner(owner);
2016 EXPECT_EQ(owner, STRING_BUNDLE_NAME);
2017
2018 std::string name;
2019 appAccounts.begin()->GetName(name);
2020 EXPECT_EQ(name, STRING_NAME);
2021
2022 result = AppAccountControlManager::GetInstance().DeleteAccount(
2023 STRING_NAME, UID, STRING_BUNDLE_NAME, appAccountInfo);
2024 EXPECT_EQ(result, ERR_OK);
2025
2026 result = AppAccountControlManager::GetInstance().DeleteAccount(
2027 STRING_NAME_TWO, UID, STRING_OWNER, appAccountInfoTwo);
2028 EXPECT_EQ(result, ERR_OK);
2029 }
2030
2031 /**
2032 * @tc.name: AppAccountManagerService_GetAllAccounts_0600
2033 * @tc.desc: Get all accounts with invalid data.
2034 * @tc.type: FUNC
2035 * @tc.require: issueI5N90B
2036 */
2037 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccounts_0600, TestSize.Level1)
2038 {
2039 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccounts_0600");
2040
2041 std::vector<AppAccountInfo> appAccounts;
2042 ErrCode result = g_accountManagerService->GetAllAccounts(STRING_BUNDLE_NAME_NOT_INSTALLED, appAccounts);
2043 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_GET_BUNDLE_INFO);
2044 }
2045
2046 /**
2047 * @tc.name: AppAccountManagerService_GetAllAccessibleAccounts_0100
2048 * @tc.desc: Get all accessible accounts with valid data.
2049 * @tc.type: FUNC
2050 * @tc.require: issueI5N90B
2051 */
2052 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccessibleAccounts_0100, TestSize.Level0)
2053 {
2054 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccessibleAccounts_0100");
2055
2056 std::vector<AppAccountInfo> appAccounts;
2057 ErrCode result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
2058 EXPECT_EQ(result, ERR_OK);
2059 EXPECT_EQ(appAccounts.size(), SIZE_ZERO);
2060 }
2061
2062 /**
2063 * @tc.name: AppAccountManagerService_QueryAllAccessibleAccounts_0100
2064 * @tc.desc: Get all accessible accounts with valid data.
2065 * @tc.type: FUNC
2066 * @tc.require: issueI5N90B
2067 */
2068 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_QueryAllAccessibleAccounts_0100, TestSize.Level0)
2069 {
2070 std::vector<AppAccountInfo> appAccounts;
2071 std::string owner = "";
2072 ErrCode result = g_accountManagerService->QueryAllAccessibleAccounts(owner, appAccounts);
2073 EXPECT_EQ(result, ERR_OK);
2074 EXPECT_EQ(appAccounts.size(), SIZE_ZERO);
2075 }
2076
2077 /**
2078 * @tc.name: AppAccountManagerService_GetAllAccessibleAccounts_0200
2079 * @tc.desc: Get all accessible accounts with valid data.
2080 * @tc.type: FUNC
2081 * @tc.require: issueI5N90B
2082 */
2083 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccessibleAccounts_0200, TestSize.Level1)
2084 {
2085 ACCOUNT_LOGI("AppAccountManagerService_GetAllAccessibleAccounts_0200");
2086
2087 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2088 EXPECT_EQ(result, ERR_OK);
2089
2090 std::vector<AppAccountInfo> appAccounts;
2091 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
2092 EXPECT_EQ(result, ERR_OK);
2093 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
2094
2095 std::string name;
2096 appAccounts.begin()->GetName(name);
2097 EXPECT_EQ(name, STRING_NAME);
2098
2099 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2100 EXPECT_EQ(result, ERR_OK);
2101 }
2102
2103 /**
2104 * @tc.name: AppAccountManagerService_QueryAllAccessibleAccounts_0200
2105 * @tc.desc: Get all accessible accounts with valid data.
2106 * @tc.type: FUNC
2107 * @tc.require: issueI5N90B
2108 */
2109 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_QueryAllAccessibleAccounts_0200, TestSize.Level1)
2110 {
2111 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2112 EXPECT_EQ(result, ERR_OK);
2113
2114 std::vector<AppAccountInfo> appAccounts;
2115 std::string owner = "";
2116 result = g_accountManagerService->QueryAllAccessibleAccounts(owner, appAccounts);
2117 EXPECT_EQ(result, ERR_OK);
2118 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
2119
2120 std::string name;
2121 appAccounts.begin()->GetName(name);
2122 EXPECT_EQ(name, STRING_NAME);
2123
2124 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2125 EXPECT_EQ(result, ERR_OK);
2126 }
2127
2128 /**
2129 * @tc.name: AppAccountManagerService_GetAllAccessibleAccounts_0300
2130 * @tc.desc: Get all accessible accounts with valid data.
2131 * @tc.type: FUNC
2132 * @tc.require: issueI5N90B
2133 */
2134 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_GetAllAccessibleAccounts_0300, TestSize.Level1)
2135 {
2136 AppAccountInfo appAccountInfo(STRING_NAME, STRING_BUNDLE_NAME);
2137 ErrCode result = AppAccountControlManager::GetInstance().AddAccount(
2138 STRING_NAME, STRING_EMPTY, UID, STRING_BUNDLE_NAME, appAccountInfo);
2139 EXPECT_EQ(result, ERR_OK);
2140
2141 AppAccountCallingInfo appAccountCallingInfo;
2142 appAccountCallingInfo.callingUid = UID;
2143 appAccountCallingInfo.bundleName = STRING_BUNDLE_NAME;
2144 result = AppAccountControlManager::GetInstance().EnableAppAccess(
2145 STRING_NAME, STRING_OWNER, appAccountCallingInfo, appAccountInfo);
2146 EXPECT_EQ(result, ERR_OK);
2147
2148 std::vector<AppAccountInfo> appAccounts;
2149 result = g_accountManagerService->GetAllAccessibleAccounts(appAccounts);
2150 EXPECT_EQ(result, ERR_OK);
2151 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
2152
2153 std::string owner;
2154 appAccounts.begin()->GetOwner(owner);
2155 EXPECT_EQ(owner, STRING_BUNDLE_NAME);
2156
2157 // test api9 func
2158 appAccounts.clear();
2159 std::string queryOwner = "";
2160 result = g_accountManagerService->QueryAllAccessibleAccounts(queryOwner, appAccounts);
2161 EXPECT_EQ(result, ERR_OK);
2162 ASSERT_EQ(appAccounts.size(), SIZE_ONE);
2163
2164 owner = "";
2165 appAccounts.begin()->GetOwner(owner);
2166 EXPECT_EQ(owner, STRING_BUNDLE_NAME);
2167
2168 result = AppAccountControlManager::GetInstance().DeleteAccount(
2169 STRING_NAME, UID, STRING_BUNDLE_NAME, appAccountInfo);
2170 EXPECT_EQ(result, ERR_OK);
2171 }
2172
2173 /**
2174 * @tc.name: AppAccountManagerService_OnPackageRemoved_0100
2175 * @tc.desc: On package removed with valid data.
2176 * @tc.type: FUNC
2177 * @tc.require: issueI5N90B
2178 */
2179 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_OnPackageRemoved_0100, TestSize.Level1)
2180 {
2181 auto dataStoragePtr = AppAccountControlManager::GetInstance().GetDataStorage(UID);
2182 ASSERT_NE(dataStoragePtr, nullptr);
2183
2184 AppAccountInfo appAccountInfo(STRING_NAME, STRING_BUNDLE_NAME);
2185 ErrCode result = dataStoragePtr->AddAccountInfoIntoDataStorage(appAccountInfo);
2186 EXPECT_EQ(result, ERR_OK);
2187
2188 std::map<std::string, std::shared_ptr<IAccountInfo>> accounts;
2189 result = dataStoragePtr->LoadAllData(accounts);
2190 EXPECT_EQ(result, ERR_OK);
2191 EXPECT_EQ(accounts.size(), SIZE_ONE);
2192
2193 #ifdef HAS_CES_PART
2194 Want want;
2195 want.SetAction(CommonEventSupport::COMMON_EVENT_PACKAGE_REMOVED);
2196
2197 ElementName element;
2198 element.SetBundleName(STRING_BUNDLE_NAME);
2199
2200 want.SetElement(element);
2201 want.SetParam(AppExecFwk::Constants::UID, UID);
2202 want.SetParam(AppExecFwk::Constants::APP_INDEX, 0);
2203
2204 CommonEventData commonEventData;
2205 commonEventData.SetWant(want);
2206
2207 g_accountManagerService->observer_->OnReceiveEvent(commonEventData);
2208 #endif // HAS_CES_PART
2209
2210 bool ready = false;
2211 auto startTime = std::chrono::steady_clock::now();
2212
2213 while (true) {
2214 accounts.clear();
2215 ErrCode ret = dataStoragePtr->LoadAllData(accounts);
2216 if (ret == ERR_OK && accounts.size() == SIZE_ZERO) {
2217 ready = true;
2218 break;
2219 } else if (std::chrono::steady_clock::now() - startTime > std::chrono::seconds(60)) { // wait event
2220 break;
2221 } else {
2222 std::this_thread::sleep_for(std::chrono::milliseconds(100));
2223 }
2224 }
2225
2226 EXPECT_TRUE(ready);
2227 }
2228
2229 /**
2230 * @tc.name: AppAccountManagerService_CheckAppAccess_0100
2231 * @tc.desc: test CheckAppAccess
2232 * @tc.type: FUNC
2233 * @tc.require: issueI5N90B
2234 */
2235
2236 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckAppAccess_0100, TestSize.Level1)
2237 {
2238 ACCOUNT_LOGI("AppAccountManagerService_CheckAppAccess_0100");
2239 bool isAccessible = false;
2240 ErrCode result = g_accountManagerService->CheckAppAccess(
2241 STRING_NAME, STRING_BUNDLE_NAME_NOT_INSTALLED, isAccessible);
2242 EXPECT_NE(result, ERR_OK);
2243 EXPECT_EQ(isAccessible, false);
2244 }
2245
2246 /**
2247 * @tc.name: AppAccountManagerService_CheckAppAccess_0200
2248 * @tc.desc: test CheckAppAccess
2249 * @tc.type: FUNC
2250 * @tc.require: issueI5N90B
2251 */
2252
2253 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckAppAccess_0200, TestSize.Level1)
2254 {
2255 ACCOUNT_LOGI("AppAccountManagerService_CheckAppAccess_0200");
2256 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2257 EXPECT_EQ(result, ERR_OK);
2258
2259 bool isAccessible = false;
2260 result = g_accountManagerService->CheckAppAccess(STRING_NAME, STRING_BUNDLE_NAME, isAccessible);
2261 EXPECT_EQ(result, ERR_OK);
2262 EXPECT_EQ(isAccessible, false);
2263
2264 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2265 EXPECT_EQ(result, ERR_OK);
2266 }
2267
2268 /**
2269 * @tc.name: AppAccountManagerService_CheckAppAccess_0300
2270 * @tc.desc: test CheckAppAccess
2271 * @tc.type: FUNC
2272 * @tc.require: issueI5N90B
2273 */
2274
2275 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckAppAccess_0300, TestSize.Level1)
2276 {
2277 ACCOUNT_LOGI("AppAccountManagerService_CheckAppAccess_0300");
2278 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2279 EXPECT_EQ(result, ERR_OK);
2280
2281 result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
2282 EXPECT_EQ(result, ERR_OK);
2283 bool isAccessible = false;
2284 result = g_accountManagerService->CheckAppAccess(STRING_NAME, STRING_BUNDLE_NAME, isAccessible);
2285 EXPECT_EQ(result, ERR_OK);
2286 EXPECT_EQ(isAccessible, true);
2287
2288 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2289 EXPECT_EQ(result, ERR_OK);
2290 }
2291
2292 /**
2293 * @tc.name: AppAccountManagerService_CheckAppAccess_0400
2294 * @tc.desc: test CheckAppAccess
2295 * @tc.type: FUNC
2296 * @tc.require: issueI5N90B
2297 */
2298
2299 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckAppAccess_0400, TestSize.Level1)
2300 {
2301 ACCOUNT_LOGI("AppAccountManagerService_CheckAppAccess_0400");
2302 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2303 EXPECT_EQ(result, ERR_OK);
2304
2305 result = g_accountManagerService->EnableAppAccess(STRING_NAME, STRING_BUNDLE_NAME);
2306 EXPECT_EQ(result, ERR_OK);
2307
2308 bool isAccessible = false;
2309 AppAccountCallingInfo appAccountCallingInfo;
2310 result = g_accountManagerService->GetCallingInfo(
2311 appAccountCallingInfo.callingUid, appAccountCallingInfo.bundleName, appAccountCallingInfo.appIndex);
2312 EXPECT_EQ(result, ERR_OK);
2313 result = g_accountManagerService->CheckAppAccess(STRING_NAME, appAccountCallingInfo.bundleName, isAccessible);
2314 EXPECT_EQ(result, ERR_OK);
2315 EXPECT_EQ(isAccessible, true);
2316
2317 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2318 EXPECT_EQ(result, ERR_OK);
2319 }
2320
2321 /**
2322 * @tc.name: AppAccountManagerService_DeleteAccountCredential_0100
2323 * @tc.desc: test DeleteAccountCredential
2324 * @tc.type: FUNC
2325 * @tc.require: issueI5N90B
2326 */
2327
2328 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAccountCredential_0100, TestSize.Level1)
2329 {
2330 ACCOUNT_LOGI("AppAccountManagerService_DeleteAccountCredential_0100");
2331
2332 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2333 EXPECT_EQ(result, ERR_OK);
2334
2335 result = g_accountManagerService->SetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL);
2336 EXPECT_EQ(result, ERR_OK);
2337
2338 std::string credential;
2339 result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, credential);
2340 EXPECT_EQ(result, ERR_OK);
2341 EXPECT_EQ(credential, STRING_CREDENTIAL);
2342
2343 result = g_accountManagerService->DeleteAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE);
2344 EXPECT_EQ(result, ERR_OK);
2345
2346 credential = "";
2347 result = g_accountManagerService->GetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, credential);
2348 EXPECT_NE(result, ERR_OK);
2349 EXPECT_EQ(credential, "");
2350
2351 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2352 EXPECT_EQ(result, ERR_OK);
2353 }
2354
2355 /**
2356 * @tc.name: AppAccountManagerService_DeleteAccountCredential_0200
2357 * @tc.desc: test DeleteAccountCredential
2358 * @tc.type: FUNC
2359 * @tc.require: issueI5N90B
2360 */
2361
2362 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAccountCredential_0200, TestSize.Level1)
2363 {
2364 ACCOUNT_LOGI("AppAccountManagerService_DeleteAccountCredential_0200");
2365
2366 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2367 EXPECT_EQ(result, ERR_OK);
2368
2369 result = g_accountManagerService->DeleteAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE);
2370 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_CREDENTIAL_NOT_EXIST);
2371
2372 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2373 EXPECT_EQ(result, ERR_OK);
2374 }
2375
2376 /**
2377 * @tc.name: AppAccountManagerService_DeleteAccountCredential_0300
2378 * @tc.desc: test DeleteAccountCredential
2379 * @tc.type: FUNC
2380 * @tc.require: issueI5N90B
2381 */
2382
2383 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAccountCredential_0300, TestSize.Level1)
2384 {
2385 ACCOUNT_LOGI("AppAccountManagerService_DeleteAccountCredential_0300");
2386
2387 ErrCode result = g_accountManagerService->DeleteAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE);
2388 EXPECT_NE(result, ERR_OK);
2389 }
2390
2391 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_DeleteAccountCredential_0400, TestSize.Level1)
2392 {
2393 ACCOUNT_LOGI("AppAccountManagerService_DeleteAccountCredential_0400");
2394
2395 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2396 EXPECT_EQ(result, ERR_OK);
2397
2398 result = g_accountManagerService->SetAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE, STRING_CREDENTIAL);
2399 EXPECT_EQ(result, ERR_OK);
2400
2401 result = g_accountManagerService->DeleteAccountCredential(STRING_NAME, STRING_CREDENTIAL_TYPE_TWO);
2402 EXPECT_EQ(result, ERR_APPACCOUNT_SERVICE_ACCOUNT_CREDENTIAL_NOT_EXIST);
2403
2404 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2405 EXPECT_EQ(result, ERR_OK);
2406 }
2407
2408 /**
2409 * @tc.name: AppAccountManagerService_SelectAccountsByOptions_0100
2410 * @tc.desc: test SelectAccountsByOptions
2411 * @tc.type: FUNC
2412 * @tc.require: issueI5N90B
2413 */
2414
2415 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SelectAccountsByOptions_0100, TestSize.Level1)
2416 {
2417 ACCOUNT_LOGI("AppAccountManagerService_SelectAccountsByOptions_0100");
2418
2419 SelectAccountsOptions options;
2420 options.hasAccounts = false;
2421 options.hasOwners = false;
2422 options.hasLabels = false;
2423 options.allowedAccounts.emplace_back("test_key", "value");
2424 options.allowedOwners = TEST_LABELS;
2425 options.requiredLabels = TEST_LABELS;
2426 sptr<MockAuthenticatorCallback> callback = new (std::nothrow)MockAuthenticatorCallback();
2427 ASSERT_NE(callback, nullptr);
2428 EXPECT_CALL(*callback, OnResult(0, _)).Times(1);
2429 ErrCode result = g_accountManagerService->SelectAccountsByOptions(options, callback);
2430 EXPECT_EQ(result, ERR_OK);
2431 }
2432
2433 /**
2434 * @tc.name: AppAccountManagerService_VerifyCredential_0100
2435 * @tc.desc: test VerifyCredential
2436 * @tc.type: FUNC
2437 * @tc.require: issueI5N90B
2438 */
2439
2440 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_VerifyCredential_0100, TestSize.Level1)
2441 {
2442 ACCOUNT_LOGI("AppAccountManagerService_VerifyCredential_0100");
2443 VerifyCredentialOptions options;
2444 options.credentialType = STRING_CREDENTIAL_TYPE;
2445 options.credential = STRING_CREDENTIAL;
2446 AAFwk::WantParams want;
2447 options.parameters = want;
2448 sptr<IAppAccountAuthenticatorCallback> callback = new (std::nothrow)MockAuthenticatorCallback();
2449 ASSERT_NE(callback, nullptr);
2450 ErrCode result = g_accountManagerService->VerifyCredential(STRING_NAME, STRING_OWNER, options, callback);
2451 EXPECT_NE(result, ERR_OK);
2452 }
2453
2454 /**
2455 * @tc.name: AppAccountManagerService_VerifyCredential_0200
2456 * @tc.desc: test VerifyCredential
2457 * @tc.type: FUNC
2458 * @tc.require: issueI5N90B
2459 */
2460
2461 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_VerifyCredential_0200, TestSize.Level1)
2462 {
2463 ACCOUNT_LOGI("AppAccountManagerService_VerifyCredential_0200");
2464 VerifyCredentialOptions options;
2465 options.credentialType = STRING_CREDENTIAL_TYPE;
2466 options.credential = STRING_CREDENTIAL;
2467 AAFwk::WantParams want;
2468 options.parameters = want;
2469 sptr<IAppAccountAuthenticatorCallback> callback = new (std::nothrow)MockAuthenticatorCallback();
2470 ASSERT_NE(callback, nullptr);
2471 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2472 EXPECT_EQ(result, ERR_OK);
2473 result = g_accountManagerService->VerifyCredential(STRING_NAME, STRING_OWNER, options, callback);
2474 EXPECT_NE(result, ERR_OK);
2475 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2476 EXPECT_EQ(result, ERR_OK);
2477 }
2478
2479 /**
2480 * @tc.name: AppAccountManagerService_CheckAccountLabels_0100
2481 * @tc.desc: test CheckAccountLabels
2482 * @tc.type: FUNC
2483 * @tc.require: issueI5N90B
2484 */
2485
2486 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckAccountLabels_0100, TestSize.Level1)
2487 {
2488 ACCOUNT_LOGI("AppAccountManagerService_CheckAccountLabels_0100");
2489 sptr<IAppAccountAuthenticatorCallback> callback = new (std::nothrow)MockAuthenticatorCallback();
2490 ASSERT_NE(callback, nullptr);
2491 ErrCode result = g_accountManagerService->AddAccount(STRING_NAME, STRING_EXTRA_INFO);
2492 EXPECT_EQ(result, ERR_OK);
2493 result = g_accountManagerService->CheckAccountLabels(STRING_NAME, STRING_OWNER, TEST_LABELS, callback);
2494 EXPECT_NE(result, ERR_OK);
2495 result = g_accountManagerService->DeleteAccount(STRING_NAME);
2496 EXPECT_EQ(result, ERR_OK);
2497 }
2498
2499 /**
2500 * @tc.name: AppAccountManagerService_CheckAccountLabels_0200
2501 * @tc.desc: test CheckAccountLabels
2502 * @tc.type: FUNC
2503 * @tc.require: issueI5N90B
2504 */
2505
2506 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_CheckAccountLabels_0200, TestSize.Level1)
2507 {
2508 ACCOUNT_LOGI("AppAccountManagerService_CheckAccountLabels_0200");
2509 sptr<IAppAccountAuthenticatorCallback> callback = new (std::nothrow)MockAuthenticatorCallback();
2510 ASSERT_NE(callback, nullptr);
2511 ErrCode result = g_accountManagerService->CheckAccountLabels(STRING_NAME, STRING_OWNER, TEST_LABELS, callback);
2512 EXPECT_NE(result, ERR_OK);
2513 }
2514
2515 /**
2516 * @tc.name: AppAccountManagerService_SetAuthenticatorProperties_0100
2517 * @tc.desc: test SetAuthenticatorProperties
2518 * @tc.type: FUNC
2519 * @tc.require: issueI5N90B
2520 */
2521
2522 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAuthenticatorProperties_0100, TestSize.Level1)
2523 {
2524 ACCOUNT_LOGI("AppAccountManagerService_SetAuthenticatorProperties_0100");
2525 SetPropertiesOptions options;
2526 sptr<IAppAccountAuthenticatorCallback> callback = new (std::nothrow)MockAuthenticatorCallback();
2527 ASSERT_NE(callback, nullptr);
2528 ErrCode result = g_accountManagerService->SetAuthenticatorProperties(STRING_OWNER, options, callback);
2529 EXPECT_NE(result, ERR_OK);
2530 }
2531
2532 /**
2533 * @tc.name: AppAccountManagerService_SetAuthenticatorProperties_0200
2534 * @tc.desc: test SetAuthenticatorProperties
2535 * @tc.type: FUNC
2536 * @tc.require: issueI5N90B
2537 */
2538
2539 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_SetAuthenticatorProperties_0200, TestSize.Level1)
2540 {
2541 ACCOUNT_LOGI("AppAccountManagerService_SetAuthenticatorProperties_0200");
2542 SetPropertiesOptions options;
2543 AAFwk::WantParams want;
2544 options.properties = want;
2545 sptr<IAppAccountAuthenticatorCallback> callback = new (std::nothrow)MockAuthenticatorCallback();
2546 ASSERT_NE(callback, nullptr);
2547 ErrCode result = g_accountManagerService->SetAuthenticatorProperties(STRING_OWNER, options, callback);
2548 EXPECT_NE(result, ERR_OK);
2549 }
2550
2551 /**
2552 * @tc.name: AppAccountManagerService_OnPackageRemoved_0200
2553 * @tc.desc: test OnPackageRemoved
2554 * @tc.type: FUNC
2555 * @tc.require: issueI5N90B
2556 */
2557
2558 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_OnPackageRemoved_0200, TestSize.Level1)
2559 {
2560 ACCOUNT_LOGI("AppAccountManagerService_OnPackageRemoved_0200");
2561 ErrCode result = g_accountManagerService->OnPackageRemoved(UID, STRING_OWNER, 0);
2562 EXPECT_EQ(result, ERR_OK);
2563 }
2564
2565 /**
2566 * @tc.name: AppAccountManagerService_OnUserRemoved_0100
2567 * @tc.desc: test OnUserRemoved
2568 * @tc.type: FUNC
2569 * @tc.require: issueI5N90B
2570 */
2571
2572 HWTEST_F(AppAccountManagerServiceModuleTest, AppAccountManagerService_OnUserRemoved_0100, TestSize.Level1)
2573 {
2574 ACCOUNT_LOGI("AppAccountManagerService_OnUserRemoved_0100");
2575 ErrCode result = g_accountManagerService->OnUserRemoved(TEST_USER_ID);
2576 EXPECT_EQ(result, ERR_OK);
2577 }