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 */ 15import osAccount from '@ohos.account.osAccount' 16import distributedAccount from '@ohos.account.distributedAccount' 17import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' 18 19const TIMEOUT = 1000; 20const ERR_PERMISSION_DENIED = 201; 21const ERR_PARAMETER_CHECK_FAILED = 401; 22const ERR_SYSTEM_SERVICE_ABNORMAL = 12300001; 23const ERR_INVALID_PARAMETER = 12300002; 24const ERR_ACCOUNT_NOT_EXIST = 12300003; 25export default function ActsOsAccountThirdPartyTest_third_3() { 26 describe('ActsOsAccountThirdPartyTest_third_3', function () { 27 /* 28 * @tc.number : ActsOsAccountDeviceId_0100 29 * @tc.name : queryDistributedVirtualDeviceId callback 30 * @tc.desc : get distributed virtual device ID 31 */ 32 it('ActsOsAccountDeviceId_0100', 0, async function (done) { 33 console.info("====>ActsOsAccountDeviceId_0100 start===="); 34 var AccountManager = osAccount.getAccountManager(); 35 console.info("====>get os AccountManager finish===="); 36 const accountAbility = distributedAccount.getDistributedAccountAbility(); 37 accountAbility.updateOsAccountDistributedInfo( 38 { 39 name: 'ZhangSan', 40 id: '12345', 41 event: "Ohos.account.event.LOGIN" 42 }, (err) => { 43 console.info("====>update distributedInfo err:" + JSON.stringify(err)); 44 AccountManager.queryDistributedVirtualDeviceId((err, id) => { 45 console.info("====>queryDistributedVirtualDeviceId err:" + JSON.stringify(err)); 46 console.info("====>queryDistributedVirtualDeviceId deviceId:" + id); 47 expect(err).assertEqual(null); 48 expect(id !== 'ohosAnonymousUid').assertTrue() 49 console.info("====>ActsOsAccountDeviceId_0100 end===="); 50 done(); 51 }) 52 }) 53 }) 54 55 /* 56 * @tc.number : ActsOsAccountDeviceId_0200 57 * @tc.name : queryDistributedVirtualDeviceId promise 58 * @tc.desc : get distributed virtual device ID 59 */ 60 it('ActsOsAccountDeviceId_0200', 0, async function (done) { 61 console.info("====>ActsOsAccountDeviceId_0200 start===="); 62 var AccountManager = osAccount.getAccountManager(); 63 console.info("====>get os AccountManager finish===="); 64 const accountAbility = distributedAccount.getDistributedAccountAbility(); 65 accountAbility.updateOsAccountDistributedInfo( 66 { 67 name: 'ZhangSan', 68 id: '12345', 69 event: "Ohos.account.event.LOGIN" 70 }, async (err) => { 71 console.info("====>update distributedInfo err:" + JSON.stringify(err)); 72 console.info("====>queryDistributedVirtualDeviceId start===="); 73 var id = await AccountManager.queryDistributedVirtualDeviceId(); 74 console.info("====>queryDistributedVirtualDeviceId:" + id); 75 expect(id !== 'ohosAnonymousUid').assertTrue() 76 console.info("====>ActsOsAccountDeviceId_0200 end===="); 77 done(); 78 }) 79 }) 80 81 /* 82 * @tc.number : ActsOsAccountCheckActived_0100 83 * @tc.name : checkOsAccountActivated callback 84 * @tc.desc : Verify query 0 user status is true 85 */ 86 it('ActsOsAccountCheckActived_0100', 0, async function (done) { 87 console.info("====>ActsOsAccountCheckActived_0100 start===="); 88 var AccountManager = osAccount.getAccountManager(); 89 console.info("====>get os AccountManager finish===="); 90 AccountManager.checkOsAccountActivated(0, (err, isActived) => { 91 console.info("====>checkOsAccountActivated err:" + JSON.stringify(err)); 92 console.info("====>checkOsAccountActivated isActived:" + isActived); 93 expect(err).assertEqual(null); 94 expect(isActived).assertEqual(true); 95 console.info("====>ActsOsAccountCheckActived_0100 end"); 96 done(); 97 }) 98 }) 99 100 /* 101 * @tc.number : ActsOsAccountCheckActived_0200 102 * @tc.name : checkOsAccountActivated promise 103 * @tc.desc : Verify query 0 user status is true 104 */ 105 it('ActsOsAccountCheckActived_0200', 0, async function (done) { 106 console.info("====>ActsOsAccountCheckActived_0200 start===="); 107 var AccountManager = osAccount.getAccountManager(); 108 console.info("====>get os AccountManager finish===="); 109 try { 110 var isActived = await AccountManager.checkOsAccountActivated(0); 111 } catch (err) { 112 console.info("====>catch checkOsAccountActivated err:" + JSON.stringify(err)); 113 expect().assertFail(); 114 done(); 115 } 116 console.info("====>checkOsAccountActivated:" + isActived); 117 expect(isActived).assertEqual(true); 118 console.info("====>ActsOsAccountCheckActived_0200 end"); 119 done(); 120 }) 121 122 /* 123 * @tc.number : ActsOsAccountCheckActived_0300 124 * @tc.name : checkOsAccountActivated callback 125 * @tc.desc : Authentication failed to query the active status of the user that does not exist 126 */ 127 it('ActsOsAccountCheckActived_0300', 0, async function (done) { 128 console.info("====>ActsOsAccountCheckActived_0300 start"); 129 var AccountManager = osAccount.getAccountManager(); 130 console.info("====>get os AccountManager finish===="); 131 var nonExistLocalId = 1000; 132 AccountManager.checkOsAccountActivated(nonExistLocalId, (err) => { 133 console.info("====>checkOsAccountActivated err:" + JSON.stringify(err)); 134 expect(err.code).assertEqual(ERR_ACCOUNT_NOT_EXIST); 135 console.info("====>ActsOsAccountCheckActived_0300 end"); 136 done(); 137 }) 138 }) 139 140 /* 141 * @tc.number : ActsOsAccountCheckActived_0400 142 * @tc.name : checkOsAccountActivated promise 143 * @tc.desc : Authentication failed to query the active status of the user that does not exist 144 */ 145 it('ActsOsAccountCheckActived_0400', 0, async function (done) { 146 console.info("====>ActsOsAccountCheckActived_0400 start===="); 147 var AccountManager = osAccount.getAccountManager(); 148 console.info("====>get os AccountManager finish===="); 149 var nonExistLocalId = 1000; 150 try { 151 await AccountManager.checkOsAccountActivated(nonExistLocalId); 152 } catch (err) { 153 console.info("====>checkOsAccountActivated err:" + JSON.stringify(err)); 154 expect(err.code).assertEqual(ERR_ACCOUNT_NOT_EXIST); 155 console.info("====>ActsOsAccountCheckActived_0400 end"); 156 done(); 157 } 158 }) 159 160 /* 161 * @tc.number : ActsOsAccountCheckActived_0500 162 * @tc.name : checkOsAccountActivated callback 163 * @tc.desc : Verify that the query active state is not received with parameter type mismatch 164 */ 165 it('ActsOsAccountCheckActived_0500', 0, async function (done) { 166 console.info("====>ActsOsAccountCheckActived_0500 start"); 167 var AccountManager = osAccount.getAccountManager(); 168 console.info("====>get os AccountManager finish===="); 169 var localIdStr = "100"; 170 try { 171 AccountManager.checkOsAccountActivated(localIdStr, () => { 172 expect().assertFail(); 173 done(); 174 }) 175 } catch (err) { 176 expect(err.code).assertEqual(ERR_PARAMETER_CHECK_FAILED) 177 done(); 178 } 179 }) 180 181 /* 182 * @tc.number : ActsOsAccountCheckActived_0600 183 * @tc.name : checkOsAccountActivated promise 184 * @tc.desc : Verify that the query active state is not received with parameter type mismatch 185 */ 186 it('ActsOsAccountCheckActived_0600', 0, async function (done) { 187 console.info("====>ActsOsAccountCheckActived_0600 start===="); 188 var AccountManager = osAccount.getAccountManager(); 189 console.info("====>get os AccountManager finish===="); 190 var localIdStr = "100"; 191 try { 192 AccountManager.checkOsAccountActivated(localIdStr).then(() => { 193 expect().assertFail(); 194 done(); 195 }) 196 } catch (err) { 197 expect(err.code).assertEqual(ERR_PARAMETER_CHECK_FAILED) 198 done(); 199 } 200 }) 201 202 /* 203 * @tc.number : ActsOsAccountCheckActived_0700 204 * @tc.name : checkOsAccountActivated callback 205 * @tc.desc : Verify that the query active state is not received with parameter undefined 206 */ 207 it('ActsOsAccountCheckActived_0700', 0, async function (done) { 208 console.info("====>ActsOsAccountCheckActived_0700 start"); 209 var AccountManager = osAccount.getAccountManager(); 210 console.info("====>get os AccountManager finish===="); 211 try { 212 AccountManager.checkOsAccountActivated(undefined, () => { 213 expect().assertFail(); 214 done(); 215 }) 216 } catch (err) { 217 expect(err.code).assertEqual(ERR_PARAMETER_CHECK_FAILED) 218 done(); 219 } 220 }) 221 222 /* 223 * @tc.number : ActsOsAccountCheckActived_0800 224 * @tc.name : checkOsAccountActivated promise 225 * @tc.desc : Verify that the query active state is not received with parameter undefined 226 */ 227 it('ActsOsAccountCheckActived_0800', 0, async function (done) { 228 console.info("====>ActsOsAccountCheckActived_0800 start===="); 229 var AccountManager = osAccount.getAccountManager(); 230 console.info("====>ActsOsAccountCheckActived_0800 get os AccountManager finish===="); 231 try { 232 AccountManager.checkOsAccountActivated(undefined).then(() => { 233 expect().assertFail(); 234 done(); 235 }) 236 } catch (err) { 237 expect(err.code).assertEqual(ERR_PARAMETER_CHECK_FAILED) 238 done(); 239 } 240 }) 241 242 /* 243 * @tc.number : ActsOsAccountCheckMulty_0100 244 * @tc.name : checkMultiOsAccountEnabled callback 245 * @tc.desc : Check whether the function of supporting multiple os account is enabled 246 */ 247 it('ActsOsAccountCheckMulty_0100', 0, async function (done) { 248 console.info("====>ActsOsAccountCheckMulty_0100 start===="); 249 var AccountManager = osAccount.getAccountManager(); 250 console.info("====>get os AccountManager finish===="); 251 AccountManager.checkMultiOsAccountEnabled((err, data) => { 252 console.info("====>checkMultiOsAccountEnabled err:" + JSON.stringify(err)); 253 console.info("====>checkMultiOsAccountEnabled data:" + data); 254 expect(err).assertEqual(null); 255 expect(data !== null).assertTrue(); 256 console.info("====>ActsOsAccountCheckMulty_0100 end===="); 257 done(); 258 }) 259 }) 260 261 /* 262 * @tc.number : ActsOsAccountCheckMulty_0200 263 * @tc.name : checkMultiOsAccountEnabled promise 264 * @tc.desc : Check whether the function of supporting multiple os account is enabled 265 */ 266 it('ActsOsAccountCheckMulty_0200', 0, async function (done) { 267 console.info("====>ActsOsAccountCheckMulty_0200 start===="); 268 var AccountManager = osAccount.getAccountManager(); 269 console.info("====>get os AccountManager finish===="); 270 try { 271 var data = await AccountManager.checkMultiOsAccountEnabled(); 272 } catch (err) { 273 console.info("====>catch checkMultiOsAccountEnabled err:" + JSON.stringify(err)); 274 expect().assertFail(); 275 done(); 276 } 277 console.info("====>checkMultiOsAccountEnabled data:" + JSON.stringify(data)); 278 expect(data !== null).assertTrue(); 279 console.info("====>ActsOsAccountCheckMulty_0200 end===="); 280 done(); 281 }) 282 283 /* 284 * @tc.number : ActsOsAccountCheckVerified_0100 285 * @tc.name : checkOsAccountVerified callback 286 * @tc.desc : Verify that the initial state query is unlocked to false 287 */ 288 it('ActsOsAccountCheckVerified_0100', 0, async function (done) { 289 console.info("====>checkOsAccountVerified_0100 start===="); 290 var AccountManager = osAccount.getAccountManager(); 291 console.info("====>get os AccountManager finish===="); 292 AccountManager.checkOsAccountVerified((err, data) => { 293 console.info("====>checkOsAccountVerified err:" + JSON.stringify(err)); 294 console.info("====>checkOsAccountVerified data:" + data); 295 expect(err).assertEqual(null); 296 expect(data).assertEqual(true); 297 console.info("====>ActsOsAccountCheckVerified_0100 end===="); 298 done(); 299 }) 300 }) 301 302 /* 303 * @tc.number : ActsOsAccountCheckVerified_0200 304 * @tc.name : checkOsAccountVerified promise 305 * @tc.desc : Verify that the initial state query is unlocked to false 306 */ 307 it('ActsOsAccountCheckVerified_0200', 0, async function (done) { 308 console.info("====>checkOsAccountVerified_0200 start===="); 309 var AccountManager = osAccount.getAccountManager(); 310 console.info("====>get os AccountManager finish===="); 311 var checkOsAccountVerified = await AccountManager.checkOsAccountVerified(); 312 console.info("====>checkOsAccountVerified data:" + JSON.stringify(checkOsAccountVerified)); 313 expect(checkOsAccountVerified).assertEqual(true); 314 console.info("====>ActsOsAccountCheckVerified_0200 end===="); 315 done(); 316 }) 317 318 /* 319 * @tc.number : ActsOsAccountCheckVerified_0300 320 * @tc.name : checkOsAccountVerified callback 321 * @tc.desc : Verify that the initial state query 0 user is unlocked to false 322 */ 323 it('ActsOsAccountCheckVerified_0300', 0, async function (done) { 324 console.info("====>ActsOsAccountCheckVerified_0300 start===="); 325 var AccountManager = osAccount.getAccountManager(); 326 console.info("====>get os AccountManager finish===="); 327 AccountManager.checkOsAccountVerified(0, (err, data) => { 328 console.info("====>checkOsAccountVerified err:" + JSON.stringify(err)); 329 expect(err).assertEqual(null); 330 expect(data).assertFalse(); 331 console.info("====>ActsOsAccountCheckVerified_0300 end===="); 332 done(); 333 }) 334 }) 335 336 /* 337 * @tc.number : ActsOsAccountCheckVerified_0400 338 * @tc.name : checkOsAccountVerified promise 339 * @tc.desc : Verify that the initial state query 0 user is unlocked to false 340 */ 341 it('ActsOsAccountCheckVerified_0400', 0, async function (done) { 342 console.info("====>ActsOsAccountCheckVerified_0400 start===="); 343 var AccountManager = osAccount.getAccountManager(); 344 console.info("====>get os AccountManager finish===="); 345 var checkOsAccountVerified = await AccountManager.checkOsAccountVerified(0); 346 console.info("====>checkOsAccountVerified data:" + JSON.stringify(checkOsAccountVerified)); 347 expect(checkOsAccountVerified).assertFalse(); 348 console.info("====>ActsOsAccountCheckVerified_0400 end===="); 349 done(); 350 }) 351 352 /* 353 * @tc.number : ActsOsAccountCheckVerified_0500 354 * @tc.name : checkOsAccountVerified callback 355 * @tc.desc : Verify query "100" user is unlocked failed 356 */ 357 it('ActsOsAccountCheckVerified_0500', 0, async function (done) { 358 console.info("====>ActsOsAccountCheckVerified_0500 start===="); 359 var AccountManager = osAccount.getAccountManager(); 360 console.info("====>get os AccountManager finish===="); 361 var localIdStr = "100"; 362 try { 363 AccountManager.checkOsAccountVerified(localIdStr, () => { 364 expect().assertFail(); 365 done(); 366 }) 367 } catch (err) { 368 expect(err.code).assertEqual(ERR_PARAMETER_CHECK_FAILED); 369 console.info("====>ActsOsAccountCheckVerified_0500 end===="); 370 done(); 371 } 372 }) 373 374 /* 375 * @tc.number : ActsOsAccountCheckVerified_0600 376 * @tc.name : checkOsAccountVerified promise 377 * @tc.desc : Verify query "100" user is unlocked failed 378 */ 379 it('ActsOsAccountCheckVerified_0600', 0, async function (done) { 380 console.info("====>ActsOsAccountCheckVerified_0600 start===="); 381 var AccountManager = osAccount.getAccountManager(); 382 console.info("====>get os AccountManager finish===="); 383 var localIdStr = "100"; 384 try { 385 AccountManager.checkOsAccountVerified(localIdStr).then(() => { 386 expect().assertFail(); 387 done(); 388 }) 389 } catch (err) { 390 expect(err.code).assertEqual(ERR_PARAMETER_CHECK_FAILED) 391 console.info("====>ActsOsAccountCheckVerified_0600 end===="); 392 done(); 393 } 394 }) 395 396 /* 397 * @tc.number : ActsOsAccountCheckVerified_0700 398 * @tc.name : checkOsAccountVerified callback 399 * @tc.desc : Verify query undefined user is unlocked failed 400 */ 401 it('ActsOsAccountCheckVerified_0700', 0, async function (done) { 402 console.info("====>ActsOsAccountCheckVerified_0700 start===="); 403 var AccountManager = osAccount.getAccountManager(); 404 console.info("====>get os AccountManager finish===="); 405 var localIdUndefined = undefined; 406 try { 407 AccountManager.checkOsAccountVerified(localIdUndefined, () => { 408 console.info("====>ActsOsAccountCheckVerified_0800 end===="); 409 done(); 410 }) 411 } catch (err) { 412 expect().assertFail(); 413 console.info("====>ActsOsAccountCheckVerified_0700 end===="); 414 done(); 415 } 416 }) 417 418 /* 419 * @tc.number : ActsOsAccountCheckVerified_0800 420 * @tc.name : checkOsAccountVerified promise 421 * @tc.desc : Verify query undefined user is unlocked failed 422 */ 423 it('ActsOsAccountCheckVerified_0800', 0, async function (done) { 424 console.info("====>ActsOsAccountCheckVerified_0800 start===="); 425 var AccountManager = osAccount.getAccountManager(); 426 console.info("====>get os AccountManager finish===="); 427 var localIdUndefined = undefined; 428 try { 429 AccountManager.checkOsAccountVerified(localIdUndefined).then(() => { 430 console.info("====>ActsOsAccountCheckVerified_0800 end===="); 431 done(); 432 }) 433 } catch (err) { 434 expect().assertFail(); 435 console.info("====>ActsOsAccountCheckVerified_0800 end===="); 436 done(); 437 } 438 }) 439 440 /* 441 * @tc.number : ActsOsAccountCheckVerified_0900 442 * @tc.name : checkOsAccountVerified callback 443 * @tc.desc : Verify query does not exist user unlock failed 444 */ 445 it('ActsOsAccountCheckVerified_0900', 0, async function (done) { 446 console.info("====>ActsOsAccountCheckVerified_0900 start===="); 447 var AccountManager = osAccount.getAccountManager(); 448 console.info("====>get os AccountManager finish===="); 449 var osAccountLocalId = 1000; 450 AccountManager.checkOsAccountVerified(osAccountLocalId, (err) => { 451 console.info("====>checkOsAccountVerified err:" + JSON.stringify(err)); 452 expect(err.code).assertEqual(ERR_ACCOUNT_NOT_EXIST) 453 console.info("====>ActsOsAccountCheckVerified_0900 end===="); 454 done(); 455 }) 456 }) 457 458 /* 459 * @tc.number : ActsOsAccountCheckVerified_1000 460 * @tc.name : checkOsAccountVerified promise 461 * @tc.desc : Verify query does not exist user unlock failed 462 */ 463 it('ActsOsAccountCheckVerified_1000', 0, async function (done) { 464 console.info("====>ActsOsAccountCheckVerified_1000 start===="); 465 var AccountManager = osAccount.getAccountManager(); 466 console.info("====>get os AccountManager finish===="); 467 var osAccountLocalId = 1000; 468 try { 469 await AccountManager.checkOsAccountVerified(osAccountLocalId); 470 } catch (err) { 471 console.info("====>checkOsAccountVerified err:" + JSON.stringify(err)); 472 expect(err.code).assertEqual(ERR_ACCOUNT_NOT_EXIST) 473 console.info("====>ActsOsAccountCheckVerified_1000 end===="); 474 done(); 475 } 476 }) 477 478 /* 479 * @tc.number : ActsOsAccountCheckTest_0100 480 * @tc.name : checkOsAccountTestable callback 481 * @tc.desc : check whether this OS account is a test OS account 482 */ 483 it('ActsOsAccountCheckTest_0100', 0, async function (done) { 484 console.info("====>ActsOsAccountCheckTest_0100 start===="); 485 var AccountManager = osAccount.getAccountManager(); 486 console.info("====>get os AccountManager finish===="); 487 AccountManager.checkOsAccountTestable((err, data) => { 488 console.info("====>checkOsAccountTestable err:" + JSON.stringify(err)); 489 console.info("====>checkOsAccountTestable data:" + JSON.stringify(data)); 490 expect(err).assertEqual(null); 491 expect(data).assertEqual(false); 492 console.info("====>ActsOsAccountCheckTest_0100 end===="); 493 done(); 494 }) 495 }) 496 497 /* 498 * @tc.number : ActsOsAccountCheckTest_0200 499 * @tc.name : checkOsAccountTestable promise 500 * @tc.desc : check whether this OS account is a test OS account 501 */ 502 it('ActsOsAccountCheckTest_0200', 0, async function (done) { 503 console.info("====>ActsOsAccountCheckTest_0200 start===="); 504 var AccountManager = osAccount.getAccountManager(); 505 console.info("====>get os AccountManager finish===="); 506 var isTest = await AccountManager.checkOsAccountTestable(); 507 expect(isTest).assertFalse(); 508 console.info("====>ActsOsAccountCheckTest_0200 end===="); 509 done(); 510 }) 511 512 /* 513 * @tc.number : ActsOsAccountIsOsAccountUnlocked_0100 514 * @tc.name : IsOsAccountUnlocked promise 515 * @tc.desc : Verify that the initial state query is unlocked to false 516 * @tc.level : Level2 517 * @tc.size : MediumTest 518 * @tc.type : Function 519 */ 520 it('ActsOsAccountIsOsAccountUnlocked_0100', 0, async function (done) { 521 console.info("====>ActsOsAccountIsOsAccountUnlocked_0100 start===="); 522 var AccountManager = osAccount.getAccountManager(); 523 console.info("====>get os AccountManager finish===="); 524 var IsOsAccountUnlocked = await AccountManager.isOsAccountUnlocked(); 525 console.info("====>IsOsAccountUnlocked data:" + JSON.stringify(IsOsAccountUnlocked)); 526 expect(IsOsAccountUnlocked).assertEqual(true); 527 console.info("====>ActsOsAccountIsOsAccountUnlocked_0100 end===="); 528 done(); 529 }) 530 }) 531}