Credential.test.js 38.6 KB
Newer Older
J
jiyong_sd 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
/*
 * Copyright (c) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import account from '@ohos.account.appAccount'
import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium'

const TIMEOUT = 5000;
const EACHTIMEOUT = 500;
export default function ActsAccountCredential() {
    describe('ActsAccountCredential', function () {
        function sleep(delay) {
            return new Promise((resolve, reject) => {
                setTimeout(() => {
                    resolve()
                }, delay)
            }).then(() => {
                console.info(`sleep #{time} over ...`)
            })
        }

        beforeAll(async function (done) {
            console.debug("====>beforeAll start====");
            await sleep(TIMEOUT);
            console.debug("====>beforeAll end====");
            done();
        })

        beforeEach(async function (done) {
            console.debug("====>beforeEach enter====");
            await sleep(EACHTIMEOUT);
            done();
        })

        /*
        * @tc.number    : ActsAccountCredential_0100
        * @tc.name      : The correct calls setAssociatedData and getAccountCredential get the credential
        * @tc.desc      : The setAccountCredential setting credential is called when the forwarding parameters
        *                 are correct, and then getAccountCredential is called for the credential(callback)
        */
        it('ActsAccountCredential_0100', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0100 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_0100", (err)=>{
                console.debug("====>add account ActsAccountCredential_0100 err:" + JSON.stringify(err));
57
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
58 59
                appAccountManager.setAccountCredential("account_name_0100", "credentialType1", "credential1",(err)=>{
                    console.debug("====>ActsAccountCredential_0100 setAccountCredential:" + JSON.stringify(err));
60
                    expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
61 62 63
                    appAccountManager.getAccountCredential("account_name_0100", "credentialType1", (err,data)=>{
                        console.debug("====>getAccountCredential 0100 err:" + JSON.stringify(err));
                        console.debug("====>getAccountCredential 0100 data:" + JSON.stringify(data));
64
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
65 66 67
                        expect(data).assertEqual("credential1");
                        appAccountManager.deleteAccount("account_name_0100", (err)=>{
                            console.debug("====>delete Account 0100 err:" + JSON.stringify(err));
68
                            expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
                            console.debug("====>ActsAccountCredential_0100 end====");
                            done();
                        });
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_0200
        * @tc.name      : The correct calls setAccountCredential and getAccountCredential get the credential
        * @tc.desc      : The setAssociatedData setting credential is called when the forwarding parameters
        *                 are correct, and then getAccountCredential is called for the credential(promise)
        */
        it('ActsAccountCredential_0200', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0200 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add accountActsAccountCredential_0200 start====");
            await appAccountManager.addAccount("account_name_0200");
            console.debug("====>setAccountCredential ActsAccountCredential_0200 start====");
            try{
                await appAccountManager.setAccountCredential("account_name_0200", "credentialType2", "credential2");
            }
            catch(err){
                console.error("setAccountCredential ActsAccountCredential_0200 err:" + JSON.stringify(err));
                expect().assertFail();
                done();
            }
            console.debug("====>getAccountCredential ActsAccountCredential_0200 start====");
            try{
                var data = await appAccountManager.getAccountCredential("account_name_0200", "credentialType2");
            }
            catch(err){
                console.error("getAccountCredential ActsAccountCredential_0200 err:" + JSON.stringify(err));
                expect().assertFail();
                done();
            }
            console.debug("====>getAccountCredential ActsAccountCredential_0200 data:" + JSON.stringify(data));
            expect(data).assertEqual("credential2");
            console.debug("====>delete account ActsAccountCredential_0200 start====");
            appAccountManager.deleteAccount("account_name_0200")
            console.debug("====>ActsAccountCredential_0200 end====");
            done();
        });

        /*
        * @tc.number    : ActsAccountCredential_0300
        * @tc.name      : Whether getAssociatedData can get the correct value when calling setAccountCredential two times
        * @tc.desc      : When the first setAccountCredential is called and the second setAccountCredential
        *                 is called,the setting of the credential is different if the call getAccountCredential
        *                 can get the second credential(callback)
        */
        it('ActsAccountCredential_0300', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0300 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_0300",(err)=>{
                console.debug("====>add account ActsAccountCredential_0300 err:" + JSON.stringify(err));
128
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
129 130
                appAccountManager.setAccountCredential("account_name_0300", "credentialType3", "credential3",(err)=>{
                    console.debug("====>setAccountCredential first time 0300 err:" + JSON.stringify(err));
131
                    expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
132 133
                    appAccountManager.setAccountCredential("account_name_0300", "credentialType3", "newcredential3",(err)=>{
                        console.debug("====>setAccountCredential second time 0300 err:" + JSON.stringify(err));
134
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
135 136 137
                        appAccountManager.getAccountCredential("account_name_0300", "credentialType3", (err, data)=>{
                            console.debug("====>getAccountCredential 0300 err:" + JSON.stringify(err));
                            console.debug("====>getAccountCredential 0300 data:" + JSON.stringify(data));
138
                            expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
139 140 141
                            expect(data).assertEqual("newcredential3");
                            appAccountManager.deleteAccount("account_name_0300", (err)=>{
                                console.debug("====>delete Account 0300 err:" + JSON.stringify(err));
142
                                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
                                console.debug("====>ActsAccountCredential_0300 end====");
                                done();
                            });
                        });
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_0400
        * @tc.name      : Whether getAssociatedData can get the correct value when calling setAccountCredential two times
        * @tc.desc      : When the first setAccountCredential is called and the second setAccountCredential
        *                 is called,the setting of the credential is different if the call getAccountCredential
        *                 can get the second credential(promise)
        */
        it('ActsAccountCredential_0400', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0400 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_0400 start====");
            await appAccountManager.addAccount("account_name_0400");
            try{
                await appAccountManager.setAccountCredential("account_name_0400", "credentialType4", "credential4");
                await appAccountManager.setAccountCredential("account_name_0400", "credentialType4", "newcredential4")
            }
            catch(err){
                console.error("setAccountCredential ActsAccountCredential_0400 err:" + JSON.stringify(err));
                expect().assertFail();
                done();
            }
            try{
                var data = await appAccountManager.getAccountCredential("account_name_0400", "credentialType4");
            }
            catch(err){
                console.error("getAccountCredential ActsAccountCredential_0400 err:" + JSON.stringify(err));
                expect().assertFail();
                done();
            }
            console.debug("====>ActsAccountCredential_0400 getAccountCredential data:" + JSON.stringify(data));
            expect(data).assertEqual("newcredential4");
            console.debug("====>delete account ActsAccountCredential_0400 start====");
            appAccountManager.deleteAccount("account_name_0400")
            console.debug("====>ActsAccountCredential_0400 end====");
            done();
        });

        /*
        * @tc.number    : ActsAccountCredential_0500
        * @tc.name      : setAssociatedData and getAssociatedData are called when the argument is null
        * @tc.desc      : Call setAssociatedData and then getAssociatedData when the incoming credential is null(callback)
        */
        it('ActsAccountCredential_0500', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0500 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_0500",(err)=>{
                console.debug("====>add account ActsAccountCredential_0500 err:" + JSON.stringify(err));
201
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
202 203
                appAccountManager.setAccountCredential("account_name_0500", "credentialType5", "", (err)=>{
                    console.debug("====>setAccountCredential ActsAccountCredential_0500 err:" + JSON.stringify(err));
204
                    expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
205 206 207
                    appAccountManager.getAccountCredential("account_name_0500", "credentialType5", (err,data)=>{
                        console.debug("====>getAccountCredential ActsAccountCredential_0500 err:" + JSON.stringify(err));
                        console.debug("====>getAccountCredential ActsAccountCredential_0500 data:" + JSON.stringify(data));
208
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
209 210 211
                        expect(data).assertEqual("");
                        appAccountManager.deleteAccount("account_name_0500", (err)=>{
                            console.debug("====>delete Account ActsAccountCredential_0500 err:" + JSON.stringify(err));
212
                            expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
                            console.debug("====>ActsAccountCredential_0500 end====");
                            done();
                        });
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_0600
        * @tc.name      : setAssociatedData and getAssociatedData are called when the argument is null
        * @tc.desc      : Call setAssociatedData and then getAssociatedData when the incoming credential is null(promise)
        */
        it('ActsAccountCredential_0600', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0600 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_0600 start====");
            await appAccountManager.addAccount("account_name_0600");
            console.debug("====>setAccountCredential ActsAccountCredential_0600 start====");
            await appAccountManager.setAccountCredential("account_name_0600", "credentialType6", "");
            console.debug("====>getAccountCredential ActsAccountCredential_0600 start====");
            var data = await appAccountManager.getAccountCredential("account_name_0600", "credentialType6");
            console.debug("====>getAccountCredential ActsAccountCredential_0600 data" + JSON.stringify(data));
            expect(data).assertEqual("");
            console.debug("====>delete account ActsAccountCredential_0600 start====");
            await appAccountManager.deleteAccount("account_name_0600");
            console.debug("====>ActsAccountCredential_0600 end====");
            done();
        });

        /*
        * @tc.number    : ActsAccountCredential_0700
        * @tc.name      : setAssociatedData setting value is called when the argument is wrong
        * @tc.desc      : Call setAssociatedData setting credential when the incoming parameter type is null(callback)
        */
        it('ActsAccountCredential_0700', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0700 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_0700", (err)=>{
                console.debug("====>add account ActsAccountCredential_0700 err:" + JSON.stringify(err));
255
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
256 257 258 259 260
                appAccountManager.setAccountCredential("account_name_0700", "", "credential7", (err)=>{
                    console.debug("====>setAccountCredential ActsAccountCredential_0700 err:" + JSON.stringify(err));
                    expect(err.code != 0).assertEqual(true);
                    appAccountManager.deleteAccount("account_name_0700", (err)=>{
                        console.debug("====>delete Account ActsAccountCredential_0700 err:" + JSON.stringify(err));
261
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303
                        console.debug("====>ActsAccountCredential_0700 end====");
                        done();
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_0800
        * @tc.name      : setAssociatedData setting value is called when the argument is wrong
        * @tc.desc      : Call setAssociatedData setting credential when the incoming parameter type is null(promise)
        */
        it('ActsAccountCredential_0800', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0800 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ccountActsAccountCredential_0800 start====");
            await appAccountManager.addAccount("account_name_0800");
            try{
                await appAccountManager.setAccountCredential("account_name_0800", "", "credential8");
            }
            catch(err){
                console.debug("====>setAccountCredential ActsAccountCredential_0800 err:" + JSON.stringify(err));
                expect(err.code != 0).assertEqual(true);
                console.debug("====>delete account ActsAccountCredential_0800 start====");
                appAccountManager.deleteAccount("account_name_0800");
                console.debug("====>ActsAccountCredential_0800 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountCredential_0900
        * @tc.name      : getAccountCredential getting value is called when the argument is wrong
        * @tc.desc      : Call getAccountCredential getting credential when the incoming parameter type is wrong(callback)
        */
        it('ActsAccountCredential_0900', 0, async function (done) {
            console.debug("====>ActsAccountCredential_0900 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_0900", (err)=>{
                console.debug("====>add account ActsAccountCredential_0900 err:" + JSON.stringify(err));
304
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
305 306 307 308 309
                appAccountManager.getAccountCredential("account_name_0900", "", (err)=>{
                    console.debug("====>getAccountCredential ActsAccountCredential_0900 err:" + JSON.stringify(err));
                    expect(err.code != 0).assertEqual(true);
                    appAccountManager.deleteAccount("account_name_0900", (err)=>{
                        console.debug("====>delete Account ActsAccountCredential_0900 err:" + JSON.stringify(err));
310
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353
                        console.debug("====>ActsAccountCredential_0900 end====");
                        done();
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_1000
        * @tc.name      : getAccountCredential getting value is called when the argument is wrong
        * @tc.desc      : Call getAccountCredential getting credential when the incoming parameter type is wrong(promise)
        */
        it('ActsAccountCredential_1000', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1000 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_1000 start====");
            await appAccountManager.addAccount("account_name_1000");
            try{
                await appAccountManager.getAccountCredential("account_name_1000","");
            }
            catch(err){
                console.debug("====>getAccountCredential ActsAccountCredential_1000 err:" + JSON.stringify(err));
                expect(err.code != 0).assertEqual(true);
                console.debug("====>delete account ActsAccountCredential_1000 start====");
                await appAccountManager.deleteAccount("account_name_1000");
                console.debug("====>ActsAccountCredential_1000 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountCredential_1100
        * @tc.name      : setAssociatedData setting credential is called when the argument is sapce
        * @tc.desc      : Call setAssociatedData setting credential when the incoming parameter type is space
        *                 then use getAccountCredential getting the credential(callback)
        */
        it('ActsAccountCredential_1100', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1100 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_1100",(err)=>{
                console.debug("====>add account ActsAccountCredential_1100 err:" + JSON.stringify(err));
354
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
355 356
                appAccountManager.setAccountCredential("account_name_1100", " ", "credential11",(err)=>{
                    console.debug("====>setAccountCredential ActsAccountCredential_1100 err:" + JSON.stringify(err));
357
                    expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
358 359 360
                    appAccountManager.getAccountCredential("account_name_1100", " ", (err, data)=>{
                        console.debug("====>getAccountCredential 1100 err:" + JSON.stringify(err));
                        console.debug("====>getAccountCredential 1100 data:" + JSON.stringify(data));
361
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
362 363 364
                        expect(data).assertEqual("credential11");
                        appAccountManager.deleteAccount("account_name_1100", (err)=>{
                            console.debug("====>delete Account 1100 err:" + JSON.stringify(err));
365
                            expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408
                            console.debug("====>ActsAccountCredential_1100 end====");
                            done();
                        });
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_1200
        * @tc.name      : setAssociatedData setting credential is called when the argument is sapce
        * @tc.desc      : Call setAssociatedData setting credential when the incoming parameter type is space
        *                 then use getAccountCredential getting the credential(promise)
        */
        it('ActsAccountCredential_1200', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1200 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_1200 start====");
            await appAccountManager.addAccount("account_name_1200");
            console.debug("====>setAccountCredential ActsAccountCredential_1200 start====");
            await appAccountManager.setAccountCredential("account_name_1200", " ", "credential12");
            console.debug("====>getAccountCredential ActsAccountCredential_1200 start====");
            var data = await appAccountManager.getAccountCredential("account_name_1200", " ");
            console.debug("====>getAccountCredential ActsAccountCredential_1200 data" + JSON.stringify(data));
            expect(data).assertEqual("credential12");
            console.debug("====>delete account ActsAccountCredential_1200 start====");
            await appAccountManager.deleteAccount("account_name_1200");
            console.debug("====>ActsAccountCredential_1200 end====");
            done(); 
        });

        /*
        * @tc.number    : ActsAccountCredential_1300
        * @tc.name      : setAssociatedData setting credential is called when the argument is wrong
        * @tc.desc      : Call setAssociatedData setting credential when the incoming parameter name is null(callback)
        */
        it('ActsAccountCredential_1300', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1300 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_1300",(err)=>{
                console.debug("====>add account ActsAccountCredential_1300 err:" + JSON.stringify(err));
409
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
410 411 412 413 414
                appAccountManager.setAccountCredential("", "credentialType13", "credential13", (err)=>{
                    console.debug("====>setAccountCredential ActsAccountCredential_1300 err:" + JSON.stringify(err));
                    expect(err.code != 0).assertEqual(true);
                    appAccountManager.deleteAccount("account_name_1300", (err)=>{
                        console.debug("====>delete Account ActsAccountCredential_1300 err:" + JSON.stringify(err));
415
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
                        console.debug("====>ActsAccountCredential_1300 end====");
                        done();
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_1400
        * @tc.name      : setAssociatedData setting credential is called when the argument is wrong
        * @tc.desc      : Call setAssociatedData setting credential when the incoming parameter name is null(promise)
        */
        it('ActsAccountCredential_1400', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1400 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_1400 start====");
            await appAccountManager.addAccount("account_name_1400");
            try{
                await appAccountManager.setAccountCredential("", "credentialType14", "credential14");
            }
            catch(err){
                console.debug("====>setAccountCredential ActsAccountCredential_1400 err:" + JSON.stringify(err));
                expect(err.code != 0).assertEqual(true);
                console.debug("====>delete account ActsAccountCredential_1400 start====");
                await appAccountManager.deleteAccount("account_name_1400");
                console.debug("====>ActsAccountCredential_1400 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountCredential_1500
        * @tc.name      : Get it directly without setting credential callback
        * @tc.desc      : Call getAccountCredential directly to get credential without calling setAccountCredential
        */
        it('ActsAccountCredential_1500', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1500 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_1500", (err)=>{
                console.debug("====>add account ActsAccountCredential_1500 err:" + JSON.stringify(err));
458
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
459 460 461 462 463
                appAccountManager.getAccountCredential("account_name_1500", "credentialType15", (err)=>{
                    console.debug("====>getAccountCredential ActsAccountCredential_1500 err:" + JSON.stringify(err));
                    expect(err.code != 0).assertEqual(true);
                    appAccountManager.deleteAccount("account_name_1500", (err)=>{
                        console.debug("====>delete Account ActsAccountCredential_1500 err:" + JSON.stringify(err));
464
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509
                        console.debug("====>ActsAccountCredential_1500 end====");
                        done();
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_1600
        * @tc.name      : Get it directly without setting credential promise
        * @tc.desc      : Call getAccountCredential directly to get credential without calling setAccountCredential
        */
        it('ActsAccountCredential_1600', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1600 start====");
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_1600 start====");
            await appAccountManager.addAccount("account_name_1600");
            try{
                await appAccountManager.getAccountCredential("account_name_1600", "credentialType16");
            }
            catch(err){
                console.debug("====>getAccountCredential ActsAccountCredential_1600 err:" + JSON.stringify(err));
                expect(err.code != 0).assertEqual(true);
                console.debug("====>delete account ActsAccountCredential_1600 start====");
                await appAccountManager.deleteAccount("account_name_1600");
                console.debug("====>ActsAccountCredential_1600 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountCredential_1700
        * @tc.name      : setAccountCredential setting credential is called when the argument is wrong callback
        * @tc.desc      : Call setAccountCredential setting credential when the incoming parameter credential is wrong
        */
        it('ActsAccountCredential_1700', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1700 start====");
            var CREDENTIALOVERSIZE = "K"
            for(var i = 0;i < 256;i++)
            CREDENTIALOVERSIZE = CREDENTIALOVERSIZE + "K!@#";
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_1700", (err)=>{
                console.debug("====>add account ActsAccountCredential_1700 err:" + JSON.stringify(err));
510
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
511 512 513 514 515 516 517
                appAccountManager.setAccountCredential("account_name_1700", "credentialType17", CREDENTIALOVERSIZE, (err)=>{
                    console.debug("====>CREDENTIALOVERSIZE.length:" + JSON.stringify(CREDENTIALOVERSIZE.length));
                    expect(CREDENTIALOVERSIZE.length).assertEqual(1025);
                    console.debug("====>setAccountCredential ActsAccountCredential_1700 err:" + JSON.stringify(err));
                    expect(err.code != 0).assertEqual(true);
                    appAccountManager.deleteAccount("account_name_1700", (err)=>{
                        console.debug("====>delete Account ActsAccountCredential_1700 err:" + JSON.stringify(err));
518
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568
                        console.debug("====>ActsAccountCredential_1700 end====");
                        done();
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_1800
        * @tc.name      : setAccountCredential setting credential is called when the argument is wrong promise
        * @tc.desc      : Call setAccountCredential setting credential when the incoming parameter credential is wrong
        */
        it('ActsAccountCredential_1800', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1800 start====");
            var bigStr = "K"
            for(var i = 0;i < 256;i++)
            bigStr = bigStr + "K!@#";
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_1800 start====");
            await appAccountManager.addAccount("account_name_1800");
            try{
                await appAccountManager.setAccountCredential("account_name_1800", "credentialType18", bigStr);
            }
            catch(err){
                console.debug("====>bigStr.length:" + JSON.stringify(bigStr.length));
                expect(bigStr.length).assertEqual(1025);
                console.debug("====>setAccountCredential ActsAccountCredential_1800 err:" + JSON.stringify(err));
                expect(err.code != 0).assertEqual(true);
                console.debug("====>delete account ActsAccountCredential_1800 start====");
                await appAccountManager.deleteAccount("account_name_1800");
                console.debug("====>ActsAccountCredential_1800 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountCredential_1900
        * @tc.name      : setAccountCredential setting credential is called when the argument is wrong
        * @tc.desc      : Call setAccountCredential setting type when the incoming parameter credential is wrong(callback)
        */
        it('ActsAccountCredential_1900', 0, async function (done) {
            console.debug("====>ActsAccountCredential_1900 start====");
            var CREDENTIALTYPEOVERSIZE = "K"
            for(var i = 0;i < 256;i++)
            CREDENTIALTYPEOVERSIZE = CREDENTIALTYPEOVERSIZE + "K!@#";
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_1900", (err)=>{
                console.debug("====>add account ActsAccountCredential_1900 err:" + JSON.stringify(err));
569
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
570 571 572 573 574 575 576
                appAccountManager.setAccountCredential("account_name_1900", CREDENTIALTYPEOVERSIZE, "credential19", (err)=>{
                    console.debug("====>CREDENTIALTYPEOVERSIZE.length:" + JSON.stringify(CREDENTIALTYPEOVERSIZE.length));
                    expect(CREDENTIALTYPEOVERSIZE.length).assertEqual(1025);
                    console.debug("====>setAccountCredential ActsAccountCredential_1900 err:" + JSON.stringify(err));
                    expect(err.code != 0).assertEqual(true);
                    appAccountManager.deleteAccount("account_name_1900", (err)=>{
                        console.debug("====>delete Account ActsAccountCredential_1900 err:" + JSON.stringify(err));
577
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
                        console.debug("====>ActsAccountCredential_1900 end====");
                        done();
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_2000
        * @tc.name      : setAccountCredential setting credential is called when the argument is wrong
        * @tc.desc      : Call setAccountCredential setting type when the incoming parameter credential is wrong(promise)
        */
        it('ActsAccountCredential_2000', 0, async function (done) {
            console.debug("====>ActsAccountCredential_2000 start====");
            var CREDENTIALTYPEOVERSIZE = "K"
            for(var i = 0;i < 256;i++)
            CREDENTIALTYPEOVERSIZE=CREDENTIALTYPEOVERSIZE+"K!@#";
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_2000 start====");
            await appAccountManager.addAccount("account_name_2000");
            try{
                await appAccountManager.setAccountCredential("account_name_2000", CREDENTIALTYPEOVERSIZE , "credential20");
            }
            catch(err){
                console.debug("====>CREDENTIALTYPEOVERSIZE.length:" + JSON.stringify(CREDENTIALTYPEOVERSIZE.length));
                expect(CREDENTIALTYPEOVERSIZE.length).assertEqual(1025);
                console.debug("====>setAccountCredential ActsAccountCredential_2000 err:" + JSON.stringify(err));
                expect(err.code != 0).assertEqual(true);
                console.debug("====>delete account ActsAccountCredential_2000 start====");
                await appAccountManager.deleteAccount("account_name_2000");
                console.debug("====>ActsAccountCredential_2000 end====");
                done();
            }
        });

        /*
        * @tc.number    : ActsAccountCredential_2100
        * @tc.name      : setAccountCredential setting credential is called when the argument is wrong
        * @tc.desc      : Call setAccountCredential setting name when the incoming parameter name is wrong(callback)
        */
        it('ActsAccountCredential_2100', 0, async function (done) {
            console.debug("====>ActsAccountCredential_2100 start====");
            var NAMEOVERSIZE = "n"
            for(var i = 0;i < 256;i++)
            NAMEOVERSIZE = NAMEOVERSIZE + "name";
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            appAccountManager.addAccount("account_name_2100", (err)=>{
                console.debug("====>add account ActsAccountCredential_2100 err:" + JSON.stringify(err));
628
                expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
629 630 631 632 633 634
                appAccountManager.setAccountCredential(NAMEOVERSIZE, "credentialType21", "credential21", (err)=>{
                    console.debug("====>setAccountCredential ActsAccountCredential_2100 err:" + JSON.stringify(err));
                    expect(err.code != 0).assertEqual(true);
                    appAccountManager.deleteAccount("account_name_2100", (err)=>{
                        console.debug("====>delete Account ActsAccountCredential_2100 err:" + JSON.stringify(err));
                        console.debug("====>ActsAccountCredential_2100 end====");
635
                        expect(err).assertEqual(undefined);
J
jiyong_sd 已提交
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
                        done();
                    });
                });
            });
        });

        /*
        * @tc.number    : ActsAccountCredential_2200
        * @tc.name      : setAccountCredential setting credential is called when the argument is wrong
        * @tc.desc      : Call setAccountCredential setting name when the incoming parameter name is wrong(promise)
        */
        it('ActsAccountCredential_2200', 0, async function (done) {
            console.debug("====>ActsAccountCredential_2200 start====");
            var NAMEOVERSIZE ="n"
            for(var i=0;i<256;i++)
            NAMEOVERSIZE=NAMEOVERSIZE+"name";
            var appAccountManager = account.createAppAccountManager();
            console.debug("====>creat finish====");
            console.debug("====>add account ActsAccountCredential_2200 start====");
            try{
                await appAccountManager.addAccount("account_name_2200");
            }
            catch(err){
                console.debug("====>add account ActsAccountCredential_2200 err:" + JSON.stringify(err));
                expect().assertFail();
                done();
            }
            console.debug("====>setAccountCredential ActsAccountCredential_2200 start====");
            try{
                await appAccountManager.setAccountCredential(NAMEOVERSIZE, "credentialType22", "credential22");
            }
            catch(err){
                console.debug("====>setAccountCredential ActsAccountCredential_2200 err:" + JSON.stringify(err));
                expect(err.code != 0).assertEqual(true);
                console.debug("====>delete account ActsAccountCredential_2200 start====");
                await appAccountManager.deleteAccount("account_name_2200");
                console.debug("====>ActsAccountCredential_2200 end====");
                done();
            }
        });
    })
}