1/* 2 * Copyright (c) 2021 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 account from '@ohos.account.appAccount' 16import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from 'deccjsunit/index' 17 18const TIMEOUT = 5000; 19const ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED = 4521993; 20describe('ActsAccountNoPermission', function () { 21 function sleep(delay) { 22 return new Promise((resolve, reject) => { 23 setTimeout(() => { 24 resolve() 25 }, delay) 26 }).then(() => { 27 console.info(`sleep #{time} over ...`) 28 }) 29 } 30 beforeAll(async function (done) { 31 console.debug("====>beforeAll start===="); 32 await sleep(TIMEOUT); 33 console.debug("====>beforeAll end===="); 34 done(); 35 }); 36 37 /* 38 * @tc.number : ActsAccountNoPermission_0100 39 * @tc.name : setAppAccountSyncEnable callback 40 * @tc.desc : Set the added account to allow synchronization without permission 41 */ 42 it('ActsAccountNoPermission_0100', 0, async function (done) { 43 console.debug("====>ActsAccountNoPermission_0100 start===="); 44 var appAccountManager = account.createAppAccountManager(); 45 console.debug("====>creat finish===="); 46 appAccountManager.addAccount("syncenable_callback_setnopermission", (err)=>{ 47 console.debug("====>add account ActsAccountNoPermission_0100 err:" + JSON.stringify(err)); 48 expect(err).assertEqual(null); 49 appAccountManager.setAppAccountSyncEnable("syncenable_callback_setnopermission", true, (err)=>{ 50 console.debug("====>setAppAccountSyncEnable 0100 err:" + JSON.stringify(err)); 51 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 52 appAccountManager.deleteAccount("syncenable_callback_setnopermission", (err)=>{ 53 console.debug("====>delete Account ActsAccountNoPermission_0100 err:" + JSON.stringify(err)); 54 expect(err).assertEqual(null); 55 console.debug("====>ActsAccountNoPermission_0100 end===="); 56 done(); 57 }); 58 }) 59 }); 60 }); 61 62 /* 63 * @tc.number : ActsAccountNoPermission_0200 64 * @tc.name : setAppAccountSyncEnable promise 65 * @tc.desc : Set the added account to allow synchronization without permission 66 */ 67 it('ActsAccountNoPermission_0200', 0, async function (done) { 68 console.debug("====>ActsAccountNoPermission_0200 start===="); 69 var appAccountManager = account.createAppAccountManager(); 70 console.debug("====>creat finish===="); 71 console.debug("====>add account ActsAccountNoPermission_0200 start===="); 72 await appAccountManager.addAccount("syncenable_promise_setnopermission"); 73 console.debug("====>setAppAccountSyncEnable ActsAccountNoPermission_0200 start===="); 74 try{ 75 await appAccountManager.setAppAccountSyncEnable("syncenable_promise_setnopermission", true); 76 } 77 catch(err){ 78 console.debug("====>setAppAccountSyncEnable 0200 err:" + JSON.stringify(err)); 79 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 80 console.debug("====>delete account ActsAccountNoPermission_0200 start===="); 81 await appAccountManager.deleteAccount("syncenable_promise_setnopermission"); 82 console.debug("====>ActsAccountNoPermission_0200 end===="); 83 done(); 84 } 85 }); 86 87 /* 88 * @tc.number : ActsAccountNoPermission_0300 89 * @tc.name : Check sync flag callback form 90 * @tc.desc : Check the added account synchronization without permission 91 */ 92 it('ActsAccountNoPermission_0300', 0, async function (done) { 93 console.debug("====>ActsAccountNoPermission_0300 start===="); 94 var appAccountManager = account.createAppAccountManager(); 95 console.debug("====>creat finish===="); 96 appAccountManager.addAccount("syncenable_callback_checknopermission", (err)=>{ 97 console.debug("====>add account ActsAccountNoPermission_0300 err:" + JSON.stringify(err)); 98 expect(err).assertEqual(null); 99 appAccountManager.checkAppAccountSyncEnable("syncenable_callback_checknopermission", (err, data)=>{ 100 console.debug("====>checkAppAccountSyncEnable 0300 err:" + JSON.stringify(err)); 101 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 102 appAccountManager.deleteAccount("syncenable_callback_checknopermission", (err)=>{ 103 console.debug("====>delete Account ActsAccountNoPermission_0300 err:" + JSON.stringify(err)); 104 expect(err).assertEqual(null); 105 console.debug("====>ActsAccountNoPermission_0300 end===="); 106 done(); 107 }); 108 }) 109 }); 110 }); 111 112 /* 113 * @tc.number : ActsAccountNoPermission_0400 114 * @tc.name : Check sync flag promise form 115 * @tc.desc : Check the added account synchronization without permission 116 */ 117 it('ActsAccountNoPermission_0400', 0, async function (done) { 118 console.debug("====>ActsAccountNoPermission_0400 start===="); 119 var appAccountManager = account.createAppAccountManager(); 120 console.debug("====>creat finish===="); 121 console.debug("====>add account ActsAccountNoPermission_0400 start===="); 122 await appAccountManager.addAccount("syncenable_promise_checknopermission"); 123 console.debug("====>checkAppAccountSyncEnable ActsAccountNoPermission_0400 start===="); 124 try{ 125 var data = await appAccountManager.checkAppAccountSyncEnable("syncenable_promise_checknopermission"); 126 } 127 catch(err){ 128 console.debug("====>checkAppAccountSyncEnable 0400 err:" + JSON.stringify(err)); 129 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 130 await appAccountManager.deleteAccount("syncenable_promise_checknopermission"); 131 console.debug("====>ActsAccountNoPermission_0400 end===="); 132 done(); 133 } 134 }); 135 136 /* 137 * @tc.number : ActsAccountNoPermission_0500 138 * @tc.name : getAllAccessibleAccounts callback 139 * @tc.desc : This application gets authorization after adding a single account without permission 140 */ 141 it('ActsAccountNoPermission_0500', 0, async function (done) { 142 console.debug("====>ActsAccountNoPermission_0500 start===="); 143 var appAccountManager = account.createAppAccountManager(); 144 console.debug("====>creat finish===="); 145 appAccountManager.addAccount("accessibleAccount_callback_nopermission", (err)=>{ 146 console.debug("====> add account ActsAccountNoPermission_0500 err:" + JSON.stringify(err)); 147 expect(err).assertEqual(null); 148 appAccountManager.getAllAccessibleAccounts((err, data)=>{ 149 console.debug("====>getAllAccessibleAccounts 0500 err:" + JSON.stringify(err)); 150 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 151 appAccountManager.deleteAccount("accessibleAccount_callback_nopermission", (err)=>{ 152 console.debug("====>delete Account ActsAccountNoPermission_0500 err:" + JSON.stringify(err)); 153 expect(err).assertEqual(null); 154 console.debug("====>ActsAccountNoPermission_0500 end===="); 155 done(); 156 }) 157 }); 158 }); 159 }); 160 161 /* 162 * @tc.number : ActsAccountNoPermission_0600 163 * @tc.name : getAllAccessibleAccounts promise 164 * @tc.desc : This application gets authorization after adding a single account without permission 165 */ 166 it('ActsAccountNoPermission_0600', 0, async function (done) { 167 console.debug("====>ActsAccountNoPermission_0600 start===="); 168 var appAccountManager = account.createAppAccountManager(); 169 console.debug("====>creat finish===="); 170 console.debug("====>add account ActsAccountNoPermission_0600 start===="); 171 await appAccountManager.addAccount("accessibleAccount_promise_nopermission"); 172 console.debug("====>getAllAccessibleAccounts 0600 start===="); 173 try{ 174 var data = await appAccountManager.getAllAccessibleAccounts(); 175 } 176 catch(err){ 177 console.debug("====>getAllAccessibleAccounts 0600 err:" + JSON.stringify(err)); 178 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 179 await appAccountManager.deleteAccount("accessibleAccount_promise_nopermission"); 180 console.debug("====>ActsAccountNoPermission_0600 end===="); 181 done(); 182 } 183 }); 184 185 /* 186 * @tc.number : ActsAccountNoPermission_0700 187 * @tc.name : getAllAccounts callback 188 * @tc.desc : This application gets its own application information after adding an account without permission 189 */ 190 it('ActsAccountNoPermission_0700', 0, async function (done) { 191 console.debug("====>ActsAccountNoPermission_0700 start===="); 192 var appAccountManager = account.createAppAccountManager(); 193 console.debug("====>creat finish===="); 194 var selfBundle = "com.example.actsaccounttest"; 195 appAccountManager.addAccount("getAll_callback_nopermission", (err)=>{ 196 console.debug("====>add account 0700 err:" + JSON.stringify(err)); 197 expect(err).assertEqual(null); 198 appAccountManager.getAllAccounts(selfBundle, (err, data)=>{ 199 console.debug("====>getAllAccounts 0700 err:" + JSON.stringify(err)); 200 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 201 appAccountManager.deleteAccount("getAll_callback_nopermission", (err)=>{ 202 console.debug("====>delete account 0700 err:" + JSON.stringify(err)); 203 expect(err).assertEqual(null); 204 console.debug("====>ActsAccountNoPermission_0700 end===="); 205 done(); 206 }); 207 }) 208 }); 209 }); 210 211 /* 212 * @tc.number : ActsAccountNoPermission_0800 213 * @tc.name : getAllAccounts promise 214 * @tc.desc : This application gets its own application information after adding an account without permission 215 */ 216 it('ActsAccountNoPermission_0800', 0, async function (done) { 217 console.debug("====>ActsAccountNoPermission_0800 start===="); 218 var appAccountManager = account.createAppAccountManager(); 219 console.debug("====>creat finish===="); 220 var selfBundle = "com.example.actsaccounttest"; 221 console.debug("====>add account 0800 start===="); 222 await appAccountManager.addAccount("getAll_promise_nopermission"); 223 console.debug("====>getAllAccounts 0800 start===="); 224 try{ 225 var data = await appAccountManager.getAllAccounts(selfBundle); 226 } 227 catch(err){ 228 console.error("====>getAllAccounts 0800 err:" + JSON.stringify(err)); 229 expect(err.code).assertEqual(ERR_APPACCOUNT_SERVICE_PERMISSION_DENIED); 230 await appAccountManager.deleteAccount("getAll_promise_nopermission"); 231 console.debug("====>ActsAccountNoPermission_0800 end===="); 232 done(); 233 } 234 }); 235})