1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import userAuth from '@ohos.userIAM.userAuth' 17 18let UserAuthKit = new userAuth.UserAuth() 19var index = require('../../../main/js/MainAbility/pages/index/index.js'); 20var waitFlag = false; 21import { describe, beforeAll, beforeEach, afterEach, afterAll, it, expect } from '@ohos/hypium' 22 23/** 24 * test case 25 */ 26export default function userAuthTestExecute() { 27describe('userAuthTestExecute', function () { 28 beforeEach(function(done) { 29 let waitTime = 1000; 30 if (waitFlag) { 31 waitTime = 30000; 32 } 33 setTimeout(function() { 34 done(); 35 }, waitTime); 36 }) 37 afterEach(function() { 38 }) 39 40 41 /** 42 * @tc.name execute_authentication_promise_Type_is_null 43 * @tc.number JSAPI_Function_Execute_2100 44 * @tc.size MEDIUM 45 * @tc.type FUNC 46 * @tc.level Level2 47 */ 48 it('JSAPI_Function_Nopermission_2100', 0, function (done) { 49 console.log("JSAPI_Function_Nopermission_2100 start"); 50 const auth = userAuth.getAuthenticator(); 51 auth.execute("FACE_ONLY", "S1").catch(function(data) { 52 console.log("JSAPI_Function_Nopermission_2100 auth.execute:" + data); 53 // general error 54 expect(data).assertEqual(100); 55 setTimeout(function() { 56 done(); 57 }, 1); 58 }); 59 console.log("JSAPI_Function_Nopermission_2100 end"); 60 }) 61 62 /** 63 * @tc.name execute_authentication_callback_Type_is_null 64 * @tc.number JSAPI_Function_Execute_1800 65 * @tc.size MEDIUM 66 * @tc.type FUNC 67 * @tc.level Level2 68 */ 69 it('JSAPI_Function_Nopermission_1800', 0, function () { 70 console.log("JSAPI_Function_Nopermission_1800 start"); 71 const auth = userAuth.getAuthenticator(); 72 auth.execute("FACE_ONLY", "S1", function(data) { 73 console.log("JSAPI_Function_Nopermission_1800 auth.execute:" + data); 74 // general error 75 expect(data).assertEqual(100); 76 }); 77 console.log("JSAPI_Function_Nopermission_1800 end"); 78 }) 79 80 /* 81 * @tc.number : Security_IAM_Nopermission_API8_Func_0101 82 * @tc.name : Kit interface get version 83 * @tc.size : MediumTest 84 * @tc.type : Function 85 * @tc.level : Level 0 86 */ 87 it('Security_IAM_Nopermission_API8_Func_0101', 0, async function (done) { 88 try { 89 let getversionresult = null; 90 getversionresult = UserAuthKit.getVersion(); 91 console.info('Security_IAM_Nopermission_API8_Func_0101 getversionresult = ' + getversionresult); 92 //mini version 0 93 expect(getversionresult).assertEqual(0); 94 done(); 95 } catch (e) { 96 console.log("testFace Security_IAM_Nopermission_API8_Func_0101 fail " + e.code); 97 expect(null).assertFail(); 98 done(); 99 } 100 }) 101 102 /* 103 * @tc.number : Security_IAM_Nopermission_API8_Func_0112 104 * @tc.name : Kit interface get AvailabeStatus 105 * @tc.size : MediumTest 106 * @tc.type : Function 107 * @tc.level : Level 0 108 */ 109 it('Security_IAM_Nopermission_API8_Func_0112', 0, async function (done) { 110 console.info('testFace Security_IAM_Nopermission_API8_Func_0112 start'); 111 let authType = [2, 4] 112 for (let idx0 = 0; idx0 < authType.length; idx0++){ 113 try { 114 let AvailabeStatus = null 115 AvailabeStatus = UserAuthKit.getAvailableStatus(authType[idx0], 10000); 116 console.info('testFace Security_IAM_Nopermission_API8_Func_0112,2,10000 result = ' + JSON.stringify(AvailabeStatus)); 117 //201 118 expect(201).assertEqual(AvailabeStatus); 119 done() 120 } catch (e) { 121 console.log("Security_IAM_Nopermission_API8_Func_0112 fail " + e.code); 122 expect(201).assertEqual(e.code); 123 done() 124 } 125 } 126 }) 127 128 /* 129 * @tc.number : Security_IAM_Nopermission_API8_Func_0103 130 * @tc.name : Kit interface auth & cancel auth 131 * @tc.size : MediumTest 132 * @tc.type : Function 133 * @tc.level : Level 0 134 */ 135 it('Security_IAM_Nopermission_API8_Func_0103', 0, async function (done) { 136 let contextID1 = null 137 let challenge = new Uint8Array([253, 19, 58, 160, 67, 200, 247, 37]) 138 let onresult = { 139 authresult: null, 140 authextr: null, 141 } 142 let onacquireinfo = { 143 authmodule : null, 144 authacquire : null, 145 authextr : null 146 } 147 let authType = [userAuth.UserAuthType.FACE, userAuth.UserAuthType.FINGERPRINT] 148 for (let idx0 = 0; idx0 < authType.length; idx0++) { 149 console.log("Security_IAM_Nopermission_API8_Func_0103 authtype:" + authType[idx0] + "trustlevel:10000"); 150 contextID1 = UserAuthKit.auth(challenge, authType[idx0], userAuth.AuthTrustLevel.ATL1, { 151 onResult: function(result,extraInfo){ 152 console.log("Security_IAM_Nopermission_API8_Func_0103 auth result = " + result); 153 onresult.authresult = result; 154 //201 155 expect(201).assertEqual(result); 156 console.info('Security_IAM_Nopermission_API8_Func_0103 contextID1 = ' + contextID1); 157 let cancelResult = UserAuthKit.cancelAuth(contextID1); 158 console.info('Security_IAM_Nopermission_API8_Func_0103 cancelResult = ' + cancelResult); 159 done(); 160 }, 161 onAcquireInfo: function (modulea,acquire,extr){ 162 console.info('faceTest publicauth auth onAcquireInfo in'); 163 onacquireinfo.authmodule = modulea; 164 onacquireinfo.authacquire = acquire; 165 onacquireinfo.authextr = extr; 166 console.log("testFace faceDemo auth module = " + JSON.stringify(modulea)); 167 console.info('testFace publicauth auth onAcquireInfo = ' + JSON.stringify(onacquireinfo)); 168 } 169 }); 170 done(); 171 } 172 }) 173 174 /* 175 * @tc.number : Security_IAM_Nopermission_API9_Func_0104 176 * @tc.name : getAvailableStatus invalid parameters 177 * @tc.size : MediumTest 178 * @tc.type : Function 179 * @tc.level : Level 0 180 */ 181 it('Security_IAM_Nopermission_API9_Func_0104', 0, async function (done) { 182 console.info('testFace Security_IAM_Nopermission_API9_Func_0104 start'); 183 let authType = [userAuth.UserAuthType.FACE, userAuth.UserAuthType.FINGERPRINT]; 184 for (let idx0 = 0; idx0 < authType.length; idx0++) { 185 try { 186 userAuth.getAvailableStatus(authType[idx0], userAuth.AuthTrustLevel.ATL1); 187 console.log("Security_IAM_Nopermission_API9_Func_0104 success " ); 188 done() 189 } catch (e) { 190 console.log("Security_IAM_Nopermission_API9_Func_0104 fail " + e.code); 191 expect(e.code).assertEqual(201); 192 done() 193 } 194 } 195 }) 196 197 198 /* 199 * @tc.number : Security_IAM_Nopermission_API9_Func_0110 200 * @tc.name : getAuthInstance faceType ATL4 201 * @tc.size : MediumTest 202 * @tc.type : Function 203 * @tc.level : Level 0 204 */ 205 it('Security_IAM_Nopermission_API9_Func_0110', 0, async function (done) { 206 let challenge = new Uint8Array([253, 19, 58, 160, 67, 200, 247, 37]) 207 let authType = [userAuth.UserAuthType.FACE, userAuth.UserAuthType.FINGERPRINT]; 208 let authTrustLevel = userAuth.AuthTrustLevel.ATL1; 209 for (let idx0 = 0; idx0 <authType.length; idx0++) { 210 try { 211 var authInstance = userAuth.getAuthInstance(challenge, authType[idx0], authTrustLevel); 212 console.log("Security_IAM_Nopermission_API9_Func_0110 FACE ATL1 success"); 213 done(); 214 } catch (e) { 215 console.log("Security_IAM_Nopermission_API9_Func_0110 FACE ATL1 fail" + e.code); 216 expect(e.code).assertEqual(201); 217 done(); 218 } 219 } 220 }) 221 222 /* 223 * @tc.number : Security_IAM_Nopermission_API9_Func_0103 224 * @tc.name : Kit interface auth 225 * @tc.size : MediumTest 226 * @tc.type : Function 227 * @tc.level : Level 0 228 */ 229 it('Security_IAM_Nopermission_API9_Func_0103', 0, async function (done) { 230 let challenge = new Uint8Array([253, 19, 58, 160, 67, 200, 247, 37]) 231 let authType = [userAuth.UserAuthType.FACE, userAuth.UserAuthType.FINGERPRINT]; 232 let authTrustLevel = userAuth.AuthTrustLevel.ATL1; 233 234 for (let idx0 = 0; idx0 <authType.length; idx0++) { 235 try { 236 var authInstance = userAuth.getAuthInstance(challenge, authType[idx0], authTrustLevel); 237 // register result and tip 238 authInstance.on("result", { 239 callback: (result) => { 240 console.log("authV9 result " + result.result); 241 console.log("authV9 token " + result.token); 242 console.log("authV9 remainAttempts " + result.remainAttempts); 243 console.log("authV9 lockoutDuration " + result.lockoutDuration); 244 expect(result.result).assertEqual(userAuth.UserAuthResultCode.NOT_ENROLLED); 245 } 246 }); 247 248 authInstance.on("tip", { 249 callback: (result) => { 250 console.log("authV9 module " + result.module); 251 console.log("authV9 tip " + result.tip); 252 } 253 }); 254 255 //start auth 256 authInstance.start(); 257 } catch (e) { 258 console.log("Security_IAM_Nopermission_API9_Func_0103 fail " + e.code); 259 expect(e.code).assertEqual(201); 260 } 261 262 // unregister result and tip 263 try { 264 authInstance.off("result"); 265 authInstance.off("tip"); 266 done(); 267 } catch (e) { 268 console.log("Security_IAM_Nopermission_API9_Func_0103 fail " + e.code); 269 done(); 270 } 271 } 272 }) 273}) 274} 275