diff --git a/account/appaccount/actsaccountoperatetest/src/main/js/test/AccountErrCode.test.js b/account/appaccount/actsaccountoperatetest/src/main/js/test/AccountErrCode.test.js new file mode 100644 index 0000000000000000000000000000000000000000..820a54f28331fe872dfeb5afbdf72fb099346158 --- /dev/null +++ b/account/appaccount/actsaccountoperatetest/src/main/js/test/AccountErrCode.test.js @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2022 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. + */ + +export const AccountErrCode = { + "ERR_JS_SUCCESS" : 0, + "ERR_JS_PERMISSION_DENIED" : 201, + "ERR_JS_PARAMETER_ERROR" : 401, + "ERR_JS_CAPABILITY_NOT_SUPPORTED" : 801, + "ERR_JS_SYSTEM_SERVICE_EXCEPTION" : 12300001, + "ERR_JS_INVALID_PARAMETER" : 12300002, + "ERR_JS_ACCOUNT_NOT_FOUND" : 12300003, + "ERR_JS_ACCOUNT_ALREADY_EXIST" : 12300004, + "ERR_JS_MULTI_USER_NOT_SUPPORT" : 12300005, + "ERR_JS_ACCOUNT_TYPE_NOT_SUPPORT" : 12300006, + "ERR_JS_ACCOUNT_NUMBER_REACH_LIMIT" : 12300007, + "ERR_JS_ACCOUNT_RESTRICTED" : 12300008, + "ERR_JS_ACCOUNT_ALREADY_ACTIVATED" : 12300009, + "ERR_JS_ACCOUNT_SERVICE_BUSY" : 12300010, + "ERR_JS_LISTENER_ALREADY_REGISTERED" : 12300011, + "ERR_JS_LISTENER_NOT_REGISTERED" : 12300012, + + "ERR_JS_AUTH_CREDENTIAL_WRONG_ERROR" : 12300101, + "ERR_JS_CREDENTIAL_NOT_EXIST" : 12300102, + "ERR_JS_CREDENTIAL_INPUTER_ALREADY_EXIST" : 12300103, + "ERR_JS_CREDENTIAL_INPUTER_NOT_EXIST" : 12300104, + "ERR_JS_TRUST_LEVEL_NOT_SUPPORTED" : 12300105, + "ERR_JS_AUTH_TYPE_NOT_SUPPORTED" : 12300106, + "ERR_JS_AUTH_TYPE_NOT_FOUND" : 12300107, + "ERR_JS_SESSION_NOT_EXIST" : 12300108, + "ERR_JS_AUTH_CANCELLED" : 12300109, + "ERR_JS_AUTH_SERVICE_LOCKED" : 12300110, + "ERR_JS_AUTH_TIMEOUT" : 12300111, + "ERR_JS_AUTH_SERVICE_BUSY" : 12300112, + "ERR_JS_ACCOUNT_AUTHENTICATOR_NOT_EXIST" : 12300113, + "ERR_JS_ACCOUNT_AUTHENTICATOR_SERVICE_EXCEPTION" : 12300114, + + "ERR_JS_INVALID_CONTEXT_ID" : 12300002, + + "ERR_JS_APPLICATION_NOT_EXIST" : 12400001, + "ERR_JS_CUSTOM_DATA_NOT_FOUND" : 12400002, + "ERR_JS_CUSTOM_DATA_NUMBER_REACH_LIMIT" : 12400003, + "ERR_JS_TOKEN_NUMBER_REACH_LIMIT" : 12400004, + "ERR_JS_AUTHORIZATION_LIST_TOO_LARGE" : 12400005 +} diff --git a/account/appaccount/actsaccountoperatetest/src/main/js/test/AuthToken.test.js b/account/appaccount/actsaccountoperatetest/src/main/js/test/AuthToken.test.js index 79ca1a2ecc5ca64bdbfe15d2de1ef77ae777b609..ceb7a224bde04ebfda220834795ad0e1c0781562 100644 --- a/account/appaccount/actsaccountoperatetest/src/main/js/test/AuthToken.test.js +++ b/account/appaccount/actsaccountoperatetest/src/main/js/test/AuthToken.test.js @@ -17,6 +17,7 @@ import account from '@ohos.account.appAccount' import resmgr from '@ohos.resourceManager' import featureAbility from '@ohos.ability.featureAbility' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import {AccountErrCode} from './AccountErrCode.test.js' const TIMEOUT = 1000; @@ -61,7 +62,7 @@ export default function ActsAccountAuthToken() { * @tc.level : Level 1 */ - + var valid_owner_name = "com.example.actsaccountOauthtoken"; it('ActsAccountAuthToken_9100', 0, async function (done) { console.debug("====>ActsAccountAuthToken_9100 start===="); var appAccountManager = account.createAppAccountManager(); @@ -74,7 +75,7 @@ export default function ActsAccountAuthToken() { appAccountManager.setAuthToken("account_tokenTest_name","authType1","test_token2",(err)=>{ console.debug("====>ActsAccountAuthToken_9100 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType1","other_app_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType1",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_9100 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.setAuthToken("account_tokenTest_name","authType2","test_token2",(err)=>{ @@ -92,7 +93,7 @@ export default function ActsAccountAuthToken() { console.debug("====>ActsAccountAuthToken_9100 getAllAuthTokens err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_9100 getAllAuthTokens ArrayData:" + JSON.stringify(ArrayData)); expect(err).assertEqual(null); - expect(ArrayData.length).assertEqual(2); + expect(ArrayData.length).assertEqual(1); appAccountManager.removeAccount("account_tokenTest_name",(err)=>{ console.debug("====>ActsAccountAuthToken_9100 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -101,7 +102,7 @@ export default function ActsAccountAuthToken() { appAccountManager.getAuthToken("account_tokenTest_name",OWNERSELF,"authType",(err,data)=>{ console.debug("====>ActsAccountAuthToken_9100 getAuthToken err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_9100 getAuthToken data:" + data); - expect(err.code==12300003).assertEqual(true); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_ACCOUNT_NOT_FOUND); console.debug("====>ActsAccountAuthToken_9100 end===="); done(); }); @@ -131,7 +132,7 @@ export default function ActsAccountAuthToken() { console.debug("====>ActsAccountAuthToken_9000 getAuthToken data:" + data); expect(err).assertEqual(null); expect(data).assertEqual("test_token"); - appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType","other_app_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_9000 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.getAuthList("account_tokenTest_name","authType",(err,dataArray)=>{ @@ -139,7 +140,7 @@ export default function ActsAccountAuthToken() { expect(err).assertEqual(null); console.debug("====>ActsAccountAuthToken_9000 getAuthList dataArray:" + JSON.stringify(dataArray)); expect(dataArray.length).assertEqual(1); - expect(dataArray[0]).assertEqual("other_app_bundleName"); + expect(dataArray[0]).assertEqual(valid_owner_name); appAccountManager.deleteAuthToken("account_tokenTest_name",OWNERSELF,"authType","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_9000 deleteAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -147,16 +148,14 @@ export default function ActsAccountAuthToken() { console.debug("====>ActsAccountAuthToken_9000 getAllAuthTokens err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_9000 getAllAuthTokens ArrayData:" + JSON.stringify(ArrayData)); expect(err).assertEqual(null); - expect(ArrayData.length).assertEqual(1); - expect(ArrayData[0].authType).assertEqual("authType"); - expect(ArrayData[0].token).assertEqual(""); + expect(ArrayData.length).assertEqual(0); appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType",OWNERSELF,false,(err)=>{ console.debug("====>ActsAccountAuthToken_9000 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err).assertEqual(null); + expect(err.code).assertEqual(12300002); appAccountManager.getAuthToken("account_tokenTest_name",OWNERSELF,"authType",(err,data)=>{ console.debug("====>ActsAccountAuthToken_9000 getAuthToken err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_9000 getAuthToken data:" + data); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); expect(data).assertEqual(null); appAccountManager.removeAccount("account_tokenTest_name",(err)=>{ console.debug("====>ActsAccountAuthToken_9000 removeAccount err:" + JSON.stringify(err)); @@ -287,7 +286,7 @@ export default function ActsAccountAuthToken() { expect(stateBack).assertEqual(true); appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType",OWNERSELF,false,(err)=>{ console.debug("====>ActsAccountAuthToken_7300 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err).assertEqual(null); + expect(err.code).assertEqual(12300002); appAccountManager.checkAuthTokenVisibility("account_tokenTest_name","authType",OWNERSELF,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_7300 checkAuthTokenVisibility err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_7300 checkAuthTokenVisibility stateBack:" + stateBack); @@ -427,7 +426,7 @@ export default function ActsAccountAuthToken() { expect(err).assertEqual(null); appAccountManager.deleteAuthToken("account_callback_empty_authType",OWNERSELF,"","callback_empty_authType_token",(err)=>{ console.debug("====>ActsAccountAuthToken_7800 deleteAuthToken err:" + JSON.stringify(err)); - expect(err).assertEqual(null); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); appAccountManager.getAuthToken("account_callback_empty_authType",OWNERSELF,"authType",(err,data)=>{ console.debug("====>ActsAccountAuthToken_7800 getAuthToken err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_7800 getAuthToken data:" + data); @@ -452,15 +451,22 @@ export default function ActsAccountAuthToken() { await appAccountManager.createAccount("account_promise_empty_authType"); console.debug("====>ActsAccountAuthToken_7900 setAuthToken start===="); await appAccountManager.setAuthToken("account_promise_empty_authType","authType","promise_empty_authType_token"); - console.debug("====>ActsAccountAuthToken_7900 deleteAuthToken start===="); - await appAccountManager.deleteAuthToken("account_promise_empty_authType",OWNERSELF,"","promise_empty_authType_token"); - console.debug("====>ActsAccountAuthToken_7900 getAuthToken start===="); - var data = await appAccountManager.getAuthToken("account_promise_empty_authType",OWNERSELF,"authType"); - expect(data).assertEqual("promise_empty_authType_token"); - console.debug("====>ActsAccountAuthToken_7900 removeAccount start===="); - await appAccountManager.removeAccount("account_promise_empty_authType"); - console.debug("====>ActsAccountAuthToken_7900 end===="); - done(); + + try { + console.debug("====>ActsAccountAuthToken_7900 deleteAuthToken start===="); + await appAccountManager.deleteAuthToken("account_promise_empty_authType",OWNERSELF,"","promise_empty_authType_token"); + } catch(err) { + console.debug("====>ActsAccountAuthToken_7900 deleteAuthToken err:" + JSON.stringify(err)); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); + console.debug("====>ActsAccountAuthToken_7900 getAuthToken start===="); + var data = await appAccountManager.getAuthToken("account_promise_empty_authType",OWNERSELF,"authType"); + expect(data).assertEqual("promise_empty_authType_token"); + console.debug("====>ActsAccountAuthToken_7900 removeAccount start===="); + await appAccountManager.removeAccount("account_promise_empty_authType"); + console.debug("====>ActsAccountAuthToken_7900 end===="); + done(); + + } }); @@ -2549,17 +2555,19 @@ export default function ActsAccountAuthToken() { appAccountManager.createAccount("account_setAuthTokenVisibility_name",(err,)=>{ console.debug("====>ActsAccountAuthToken_9900 createAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","authType","test_BundleName",true).then(()=>{ + appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","authType",valid_owner_name,true).then(()=>{ + expect().assertFail(); + done(); + }).catch((err)=>{ + console.debug("====>ActsAccountAuthToken_9900 setAuthTokenVisibility err:" + JSON.stringify(err)); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); appAccountManager.getAuthToken("account_setAuthTokenVisibility_name",OWNERSELF,"authType",(err,data)=>{ console.debug("====>ActsAccountAuthToken_9900 getAuthToken err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_9900 getAuthToken data:" + data); expect(err.code!=0).assertEqual(true); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","authType",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_9900 getAuthList err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountAuthToken_9900 getAuthList dataArray:" + JSON.stringify(dataArray)); - expect(dataArray.length).assertEqual(1); - expect(dataArray[0]).assertEqual("test_BundleName"); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); appAccountManager.removeAccount("account_setAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_9900 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -2568,9 +2576,6 @@ export default function ActsAccountAuthToken() { }); }); }); - }).catch((err)=>{ - expect(err).assertEqual(null); - done(); }) }); }); @@ -2673,13 +2678,12 @@ export default function ActsAccountAuthToken() { expect(err).assertEqual(null); appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","authType"," ",true,(err)=>{ console.debug("====>ActsAccountAuthToken_10300 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err).assertEqual(null); + expect(err.code).assertEqual(12400001); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","authType",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_10300 getAuthList err:" + JSON.stringify(err)); expect(err).assertEqual(null); console.debug("====>ActsAccountAuthToken_10300 getAuthList dataArray:" + JSON.stringify(dataArray)); - expect(dataArray.length).assertEqual(1); - expect(dataArray[0]).assertEqual(" "); + expect(dataArray.length).assertEqual(0); appAccountManager.removeAccount("account_setAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_10300 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -2707,7 +2711,7 @@ export default function ActsAccountAuthToken() { expect(err).assertEqual(null); appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","authType",limitBundleName,true,(err)=>{ console.debug("====>ActsAccountAuthToken_10400 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300002); appAccountManager.removeAccount("account_setAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_10400 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -2725,10 +2729,10 @@ export default function ActsAccountAuthToken() { appAccountManager.createAccount("account_setAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_10500 createAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthToken("account_setAuthTokenVisibility_name","authType","test_token",(err)=>{ + appAccountManager.setAuthToken("account_setAuthTokenVisibility_name","","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_10500 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_10500 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","",(err,dataArray)=>{ @@ -2736,12 +2740,10 @@ export default function ActsAccountAuthToken() { expect(err).assertEqual(null); console.debug("====>ActsAccountAuthToken_10500 getAuthList dataArray:" + JSON.stringify(dataArray)); expect(dataArray.length).assertEqual(1); - expect(dataArray[0]).assertEqual("test_bundleName"); + expect(dataArray[0]).assertEqual(valid_owner_name); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","authType",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_10500 getAuthList authType:\"authType\" err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountAuthToken_10500 getAuthList authType:\"authType\" dataArray:" + JSON.stringify(dataArray)); - expect(dataArray.length).assertEqual(0); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); appAccountManager.removeAccount("account_setAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_10500 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -2761,10 +2763,10 @@ export default function ActsAccountAuthToken() { appAccountManager.createAccount("account_setAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_10600 createAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthToken("account_setAuthTokenVisibility_name","authType","test_token",(err)=>{ + appAccountManager.setAuthToken("account_setAuthTokenVisibility_name"," ","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_10600 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name"," ","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name"," ",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_10600 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.getAuthList("account_setAuthTokenVisibility_name"," ",(err,dataArray)=>{ @@ -2772,12 +2774,12 @@ export default function ActsAccountAuthToken() { expect(err).assertEqual(null); console.debug("====>ActsAccountAuthToken_10600 getAuthList dataArray:" + JSON.stringify(dataArray)); expect(dataArray.length).assertEqual(1); - expect(dataArray[0]).assertEqual("test_bundleName"); + expect(dataArray[0]).assertEqual(valid_owner_name); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","authType",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_10600 getAuthList authType:\"authType\" err:" + JSON.stringify(err)); - expect(err).assertEqual(null); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); console.debug("====>ActsAccountAuthToken_10600 getAuthList authType:\"authType\" dataArray:" + JSON.stringify(dataArray)); - expect(dataArray.length).assertEqual(0); + expect(dataArray).assertEqual(null); appAccountManager.removeAccount("account_setAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_10600 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -2807,7 +2809,7 @@ export default function ActsAccountAuthToken() { expect(err).assertEqual(null); appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name",limitAuthType,"test_bundleName",true,(err)=>{ console.debug("====>ActsAccountAuthToken_10700 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300002); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","authType",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_10700 getAuthList authType:\"authType\" err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -2834,15 +2836,14 @@ export default function ActsAccountAuthToken() { appAccountManager.setAuthToken("account_setAuthTokenVisibility_name","authType","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_10800 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","invalid_authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_setAuthTokenVisibility_name","invalid_authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_10800 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err).assertEqual(null); + expect(err.code).assertEqual(12300107); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","invalid_authType",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_10800 getAuthList err:" + JSON.stringify(err)); - expect(err).assertEqual(null); + expect(err.code).assertEqual(12300107); console.debug("====>ActsAccountAuthToken_10800 getAuthList dataArray:" + JSON.stringify(dataArray)); - expect(dataArray.length).assertEqual(1); - expect(dataArray[0]).assertEqual("test_bundleName"); + expect(dataArray).assertEqual(null); appAccountManager.getAuthList("account_setAuthTokenVisibility_name","authType",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_10800 getAuthList authType:\"authType\" err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -2864,9 +2865,9 @@ export default function ActsAccountAuthToken() { it('ActsAccountAuthToken_10900', 0, async function (done) { console.debug("====>ActsAccountAuthToken_10900 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.setAuthTokenVisibility("","authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_10900 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300002); done(); }); }); @@ -2874,9 +2875,9 @@ export default function ActsAccountAuthToken() { it('ActsAccountAuthToken_11000', 0, async function (done) { console.debug("====>ActsAccountAuthToken_11000 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.setAuthTokenVisibility(" ","authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility(" ","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_11000 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300003); done(); }); }); @@ -2888,9 +2889,9 @@ export default function ActsAccountAuthToken() { } console.debug("====>ActsAccountAuthToken_11100 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.setAuthTokenVisibility(limitName,"authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility(limitName,"authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_11100 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300002); done(); }); }); @@ -2898,9 +2899,9 @@ export default function ActsAccountAuthToken() { it('ActsAccountAuthToken_11200', 0, async function (done) { console.debug("====>ActsAccountAuthToken_11200 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.setAuthTokenVisibility("no_add_account","authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("no_add_account","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_11200 setAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300003); done(); }); }); @@ -2908,9 +2909,9 @@ export default function ActsAccountAuthToken() { it('ActsAccountAuthToken_11300', 0, async function (done) { console.debug("====>ActsAccountAuthToken_11300 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.checkAuthTokenVisibility("","authType","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("","authType",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_11300 checkAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300002); done(); }); }); @@ -2918,9 +2919,9 @@ export default function ActsAccountAuthToken() { it('ActsAccountAuthToken_11400', 0, async function (done) { console.debug("====>ActsAccountAuthToken_11400 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.checkAuthTokenVisibility(" ","authType","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility(" ","authType",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_11400 checkAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300003); done(); }); }); @@ -2932,9 +2933,9 @@ export default function ActsAccountAuthToken() { } console.debug("====>ActsAccountAuthToken_11500 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.checkAuthTokenVisibility(limitName,"authType","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility(limitName,"authType",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_11500 checkAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300002); done(); }); }); @@ -2942,9 +2943,9 @@ export default function ActsAccountAuthToken() { it('ActsAccountAuthToken_11600', 0, async function (done) { console.debug("====>ActsAccountAuthToken_11600 start===="); var appAccountManager = account.createAppAccountManager(); - appAccountManager.checkAuthTokenVisibility("no_add_account","authType","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("no_add_account","authType",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_11600 checkAuthTokenVisibility err:" + JSON.stringify(err)); - expect(err.code!=0).assertEqual(true); + expect(err.code).assertEqual(12300003); done(); }); }); @@ -2955,10 +2956,10 @@ export default function ActsAccountAuthToken() { appAccountManager.createAccount("account_checkAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_11700 createAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthToken("account_checkAuthTokenVisibility_name","authType","test_token",(err)=>{ + appAccountManager.setAuthToken("account_checkAuthTokenVisibility_name","","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_11700 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name","","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name","",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_11700 checkAuthTokenVisibility err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_11700 checkAuthTokenVisibility stateBack:" + stateBack); expect(err).assertEqual(null); @@ -2986,10 +2987,10 @@ export default function ActsAccountAuthToken() { appAccountManager.createAccount("account_checkAuthTokenVisibility_name",(err)=>{ console.debug("====>ActsAccountAuthToken_11800 createAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthToken("account_checkAuthTokenVisibility_name","authType","test_token",(err)=>{ + appAccountManager.setAuthToken("account_checkAuthTokenVisibility_name"," ","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_11800 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name"," ","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name"," ",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_11800 checkAuthTokenVisibility err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_11800 checkAuthTokenVisibility stateBack:" + stateBack); expect(err).assertEqual(null); @@ -3024,7 +3025,7 @@ export default function ActsAccountAuthToken() { appAccountManager.setAuthToken("account_checkAuthTokenVisibility_name","authType","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_11900 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name",limitAuthType,"test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name",limitAuthType,valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_11900 checkAuthTokenVisibility err:" + JSON.stringify(err)); expect(err.code!=0).assertEqual(true); appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name",limitAuthType,OWNERSELF,(err,stateBack)=>{ @@ -3051,11 +3052,10 @@ export default function ActsAccountAuthToken() { appAccountManager.setAuthToken("account_checkAuthTokenVisibility_name","authType","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_12000 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name","invalid_authType","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name","invalid_authType",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_12000 checkAuthTokenVisibility err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_12000 checkAuthTokenVisibility stateBack:" + stateBack); - expect(err).assertEqual(null); - expect(stateBack).assertEqual(false); + expect(err.code).assertEqual(12300107); appAccountManager.checkAuthTokenVisibility("account_checkAuthTokenVisibility_name","invalid_authType",OWNERSELF,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_12000 checkAuthTokenVisibility err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_12000 checkAuthTokenVisibility stateBack:" + stateBack); @@ -3159,14 +3159,12 @@ export default function ActsAccountAuthToken() { appAccountManager.setAuthToken("account_testgetAuthList_name","authType","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_12400 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_testgetAuthList_name","authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_testgetAuthList_name","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_12400 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.getAuthList("account_testgetAuthList_name","",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_12400 getAuthList err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountAuthToken_12400 getAuthList dataArray:" + JSON.stringify(dataArray)); - expect(dataArray.length).assertEqual(0); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); appAccountManager.removeAccount("account_testgetAuthList_name",(err)=>{ console.debug("====>ActsAccountAuthToken_12400 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -3188,14 +3186,12 @@ export default function ActsAccountAuthToken() { appAccountManager.setAuthToken("account_testgetAuthList_name","authType","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_12500 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_testgetAuthList_name","authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_testgetAuthList_name","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_12500 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.getAuthList("account_testgetAuthList_name"," ",(err,dataArray)=>{ console.debug("====>ActsAccountAuthToken_12500 getAuthList err:" + JSON.stringify(err)); - expect(err).assertEqual(null); - console.debug("====>ActsAccountAuthToken_12500 getAuthList dataArray:" + JSON.stringify(dataArray)); - expect(dataArray.length).assertEqual(0); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_AUTH_TYPE_NOT_FOUND); appAccountManager.removeAccount("account_testgetAuthList_name",(err)=>{ console.debug("====>ActsAccountAuthToken_12500 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -3221,7 +3217,7 @@ export default function ActsAccountAuthToken() { appAccountManager.setAuthToken("account_testgetAuthList_name","authType","test_token",(err)=>{ console.debug("====>ActsAccountAuthToken_12600 setAuthToken err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.setAuthTokenVisibility("account_testgetAuthList_name","authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_testgetAuthList_name","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_12600 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.getAuthList("account_testgetAuthList_name",limitAuthType,(err,dataArray)=>{ @@ -3308,7 +3304,7 @@ export default function ActsAccountAuthToken() { console.debug("====>ActsAccountAuthToken_13100 getAuthToken stateBack:" + data); expect(err).assertEqual(null); expect(data).assertEqual("test_token"); - appAccountManager.checkAuthTokenVisibility("account_tokenTest_name","authType","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("account_tokenTest_name","authType",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_13100 checkAuthTokenVisibility err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_13100 checkAuthTokenVisibility stateBack:" + stateBack); expect(err).assertEqual(null); @@ -3318,10 +3314,10 @@ export default function ActsAccountAuthToken() { console.debug("====>ActsAccountAuthToken_13100 getAuthList dataArray:" + JSON.stringify(dataArray)); expect(err).assertEqual(null); expect(dataArray.length).assertEqual(0); - appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType","test_bundleName",true,(err)=>{ + appAccountManager.setAuthTokenVisibility("account_tokenTest_name","authType",valid_owner_name,true,(err)=>{ console.debug("====>ActsAccountAuthToken_13100 setAuthTokenVisibility err:" + JSON.stringify(err)); expect(err).assertEqual(null); - appAccountManager.checkAuthTokenVisibility("account_tokenTest_name","authType","test_bundleName",(err,stateBack)=>{ + appAccountManager.checkAuthTokenVisibility("account_tokenTest_name","authType",valid_owner_name,(err,stateBack)=>{ console.debug("====>ActsAccountAuthToken_13100 checkAuthTokenVisibility err:" + JSON.stringify(err)); console.debug("====>ActsAccountAuthToken_13100 checkAuthTokenVisibility stateBack:" + stateBack); expect(err).assertEqual(null); @@ -3331,7 +3327,7 @@ export default function ActsAccountAuthToken() { console.debug("====>ActsAccountAuthToken_13100 getAuthList dataArray:" + JSON.stringify(dataArray)); expect(err).assertEqual(null); expect(dataArray.length).assertEqual(1); - expect(dataArray[0]).assertEqual("test_bundleName"); + expect(dataArray[0]).assertEqual(valid_owner_name); appAccountManager.removeAccount("account_tokenTest_name",(err)=>{ console.debug("====>ActsAccountAuthToken_13100 removeAccount err:" + JSON.stringify(err)); expect(err).assertEqual(null); diff --git a/account/appaccount/actsaccountoperatetest/src/main/js/test/CreateAccount.test.js b/account/appaccount/actsaccountoperatetest/src/main/js/test/CreateAccount.test.js index c0ca011f263c946a744fe7d09c4025f0beab6b5b..3a10bb9a0ea84db3f549ca5212adb551a1916ef7 100644 --- a/account/appaccount/actsaccountoperatetest/src/main/js/test/CreateAccount.test.js +++ b/account/appaccount/actsaccountoperatetest/src/main/js/test/CreateAccount.test.js @@ -14,12 +14,12 @@ */ import account from '@ohos.account.appAccount' import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' +import {AccountErrCode} from './AccountErrCode.test.js' const NAMELIMIT = 512; const LENGTHLIMIT = 1024; const ERR_PARAMETER_CHECK_FAILD =401 const ERR_INVALID_PARAMETER = 12300002 -const ERR_ACCOUNT_EXIST = 12300004 const createAccountOptions = {customData:{age:'12'}} //k and v length 1024 ,k and v size 1024 const createAccountOptionsDiff = {customData:{sex:'male'}} export default function ActsAccountCreateAccount() { @@ -129,7 +129,8 @@ export default function ActsAccountCreateAccount() { expect(err).assertEqual(null); appAccountManager.createAccount("account_name_callback_third", createAccountOptions, (err)=>{ console.debug("====>add account second time ActsAccountCreateAccount_0500 err:" + JSON.stringify(err)); - expect(err.code).assertEqual(ERR_ACCOUNT_EXIST); + console.debug("====>ActsAccountCreateAccount_0500 AccountErrCode.JsErrCode:" + AccountErrCode.ERR_JS_ACCOUNT_ALREADY_EXIST); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_ACCOUNT_ALREADY_EXIST); appAccountManager.removeAccount("account_name_callback_third", (err)=>{ console.debug("====>delete Account ActsAccountCreateAccount_0500 err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -156,7 +157,7 @@ export default function ActsAccountCreateAccount() { } catch(err){ console.debug("====>add account for the second time 0600 err:" + JSON.stringify(err)); - expect(err.code).assertEqual(ERR_ACCOUNT_EXIST); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_ACCOUNT_ALREADY_EXIST); await appAccountManager.removeAccount("account_name_promise_third"); console.debug("====>ActsAccountCreateAccount_0600 end===="); done(); @@ -521,7 +522,7 @@ export default function ActsAccountCreateAccount() { expect(err).assertEqual(null); appAccountManager.createAccount("account_name_callback_same", createAccountOptionsDiff, (err)=>{ console.debug("====>add account second time ActsAccountCreateAccount_2300 err:" + JSON.stringify(err)); - expect(err.code).assertEqual(ERR_ACCOUNT_EXIST); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_ACCOUNT_ALREADY_EXIST); appAccountManager.removeAccount("account_name_callback_same", (err)=>{ console.debug("====>delete Account ActsAccountCreateAccount_2300 err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -548,7 +549,7 @@ export default function ActsAccountCreateAccount() { } catch(err){ console.debug("====>add account for the second time err:" + JSON.stringify(err)); - expect(err.code).assertEqual(ERR_ACCOUNT_EXIST); + expect(err.code).assertEqual(AccountErrCode.ERR_JS_ACCOUNT_ALREADY_EXIST); appAccountManager.removeAccount("account_name_promise_same"); console.debug("====>ActsAccountCreateAccount_2400 end===="); done(); diff --git a/account/appaccount/actsaccountoperatetest/src/main/js/test/SetAppAccess.test.js b/account/appaccount/actsaccountoperatetest/src/main/js/test/SetAppAccess.test.js index fc09f2e4640779572a7b3b7604a58374702b4e96..38b0c1c37dfdeecff835f062874ace822194c7c0 100644 --- a/account/appaccount/actsaccountoperatetest/src/main/js/test/SetAppAccess.test.js +++ b/account/appaccount/actsaccountoperatetest/src/main/js/test/SetAppAccess.test.js @@ -427,7 +427,7 @@ export default function ActsAccountSetAppAccess() { expect(err).assertEqual(null); appAccountManager.setAppAccess("AppAccess_callback_account", enableBundle, false, (err)=>{ console.debug("====>setAppAccess ActsAccountSetAppAccess_1500 err:" + JSON.stringify(err)); - expect(err.code == 12400001).assertEqual(true); + expect(err).assertEqual(null); appAccountManager.removeAccount("AppAccess_callback_account", (err)=>{ console.debug("====>delete Account ActsAccountSetAppAccess_1500 err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -459,17 +459,17 @@ export default function ActsAccountSetAppAccess() { } console.debug("====>disableAppAccess ActsAccountSetAppAccess_1600 start===="); try{ - await appAccountManager.setAppAccess("AppAccess_promise_account", enableBundle,false); - expect().assertFail(); - done(); + await appAccountManager.setAppAccess("AppAccess_promise_account", enableBundle, false); } catch(err){ - console.debug("====>disableAppAccess ActsAccountSetAppAccess_1600 err:" + JSON.stringify(err)); - expect(err.code == 12400001).assertEqual(true); + console.debug("====>disableAppAccess ActsAccountSetAppAccess_1800 err:" + JSON.stringify(err)); await appAccountManager.removeAccount("AppAccess_promise_account"); - console.debug("====>ActsAccountSetAppAccess_1600 end===="); + expect().assertFail(); done(); } + await appAccountManager.removeAccount("AppAccess_promise_account"); + console.debug("====>ActsAccountSetAppAccess_1600 end===="); + done(); }); /* @@ -486,7 +486,7 @@ export default function ActsAccountSetAppAccess() { console.debug("====>add account ActsAccountSetAppAccess_1700 err:" + JSON.stringify(err)); expect(err).assertEqual(null); appAccountManager.setAppAccess("AppAccess_callback_notExistBundle", notExistBundle, false, (err)=>{ - expect(err.code == 12400001).assertEqual(true); + expect(err).assertEqual(null); appAccountManager.removeAccount("AppAccess_callback_notExistBundle", (err)=>{ console.debug("====>delete Account ActsAccountSetAppAccess_1700 err:" + JSON.stringify(err)); expect(err).assertEqual(null); @@ -515,13 +515,15 @@ export default function ActsAccountSetAppAccess() { } catch(err){ console.debug("====>disableAppAccess ActsAccountSetAppAccess_1800 err:" + JSON.stringify(err)); - expect(err.code == 12400001).assertEqual(true); - console.debug("====>delete account ActsAccountSetAppAccess_1800 start===="); - await appAccountManager.removeAccount("AppAccess_promise_notExistBundle"); - console.debug("====>ActsAccountSetAppAccess_1600 end===="); + await appAccountManager.removeAccount("AppAccess_promise_account"); + expect().assertFail(); done(); } - }); + console.debug("====>delete account ActsAccountSetAppAccess_1800 start===="); + await appAccountManager.removeAccount("AppAccess_promise_notExistBundle"); + console.debug("====>ActsAccountSetAppAccess_1600 end===="); + done(); + }); /* * @tc.number : ActsAccountSetAppAccess_1900