• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 { paramMock } from "../utils"
17
18export function mockUserAuth() {
19
20  const SUCCESS = 0
21
22  const contextId = 1234
23
24  const IUserAuthCallback = {
25    onResult: function (...args) {
26      console.warn("uerAuth.onResult interface mocked in the Previewer. How this interface works" +
27        " on the Previewer may be different from that on a real device.")
28    },
29
30    onAcquireInfo: function (...args) {
31      console.warn("uerAuth.onAcquireInfo interface mocked in the Previewer. How this interface works" +
32        " on the Previewer may be different from that on a real device.")
33    },
34  }
35
36  const AuthResult = {
37    token : paramMock.paramArrayMock,
38    remainTimes : "[PC Preview] unknown remainTimes",
39    freezingTime : "[PC Preview] unknown freezingTime",
40  }
41
42  const Authenticator = {
43    execute: function (...args) {
44      console.warn("uerAuth.execute interface mocked in the Previewer." +
45        " How this interface works on the Previewer may be different from that on a real device.")
46        const len = args.length;
47        if (len > 0 && typeof args[len - 1] === 'function') {
48          args[len - 1].call(this, SUCCESS);
49        } else {
50          return new Promise((resolve, reject) => {
51            resolve(SUCCESS);
52          })
53        }
54    }
55  }
56
57  const UserAuthClass = class UserAuth {
58    constructor() {
59      console.warn("uerAuth.constructor interface mocked in the Previewer." +
60        " How this interface works on the Previewer may be different from that on a real device.")
61      this.getVersion = function (...args) {
62        console.warn("uerAuth.getVersion interface mocked in the Previewer." +
63          " How this interface works on the Previewer may be different from that on a real device.")
64        return paramMock.paramNumberMock;
65      };
66
67      this.getAvailableStatus = function (...args) {
68        console.warn("uerAuth.getAvailableStatus interface mocked in the Previewer." +
69          " How this interface works on the Previewer may be different from that on a real device.")
70        return SUCCESS;
71      };
72
73      this.auth = function (...args) {
74        console.warn("uerAuth.auth interface mocked in the Previewer." +
75          " How this interface works on the Previewer may be different from that on a real device.")
76        const len = args.length;
77        if (len > 0 && typeof args[len - 1] === 'function') {
78          args[len - 1].call(this, IUserAuthCallback);
79        }
80        return contextId;
81      };
82
83      this.cancelAuth = function (...args) {
84        console.warn("uerAuth.cancelAuth interface mocked in the Previewer." +
85          " How this interface works on the Previewer may be different from that on a real device.")
86        return SUCCESS;
87      };
88
89    }
90  }
91
92  const AuthEvent = {
93    callback: function (...args) {
94      console.warn("uerAuth.callback interface mocked in the Previewer. How this interface works" +
95        " on the Previewer may be different from that on a real device.")
96    }
97  }
98
99  const AuthResultInfo = {
100    result : "[PC Preview] unknown result",
101    token : paramMock.paramArrayMock,
102    remainAttempts : "[PC Preview] unknown remainAttempts",
103    lockoutDuration : "[PC Preview] unknown lockoutDuration",
104  }
105
106  const TipInfo = {
107      module : "[PC Preview] unknown module",
108      tip : "[PC Preview] unknown tip",
109  }
110
111  const AuthInstance = {
112    on: function (...args) {
113      console.warn("uerAuth.on interface mocked in the Previewer." +
114        " How this interface works on the Previewer may be different from that on a real device.")
115      const len = args.length;
116      if (len > 0 && typeof args[len - 1] === 'function') {
117        args[len - 1].call(this, AuthEvent);
118      }
119    },
120    off: function (...args) {
121      console.warn("uerAuth.off interface mocked in the Previewer." +
122        " How this interface works on the Previewer may be different from that on a real device.")
123    },
124    start: function (...args) {
125      console.warn("uerAuth.start interface mocked in the Previewer." +
126        " How this interface works on the Previewer may be different from that on a real device.")
127    },
128    cancel: function (...args) {
129      console.warn("uerAuth.cancel interface mocked in the Previewer." +
130        " How this interface works on the Previewer may be different from that on a real device.")
131    },
132  }
133
134  const userAuth = {
135    AuthenticationResult: {
136      NO_SUPPORT : -1,
137      SUCCESS : 0,
138      COMPARE_FAILURE : 1,
139      CANCELED : 2,
140      TIMEOUT : 3,
141      CAMERA_FAIL : 4,
142      BUSY : 5,
143      INVALID_PARAMETERS : 6,
144      LOCKED : 7,
145      NOT_ENROLLED : 8,
146      GENERAL_ERROR : 100
147    },
148
149    ResultCode : {
150      SUCCESS : 0,
151      FAIL : 1,
152      GENERAL_ERROR : 2,
153      CANCELED : 3,
154      TIMEOUT : 4,
155      TYPE_NOT_SUPPORT : 5,
156      TRUST_LEVEL_NOT_SUPPORT : 6,
157      BUSY : 7,
158      INVALID_PARAMETERS : 8,
159      LOCKED : 9,
160      NOT_ENROLLED : 10
161    },
162
163    FaceTips : {
164      FACE_AUTH_TIP_TOO_BRIGHT : 1,
165      FACE_AUTH_TIP_TOO_DARK : 2,
166      FACE_AUTH_TIP_TOO_CLOSE : 3,
167      FACE_AUTH_TIP_TOO_FAR : 4,
168      FACE_AUTH_TIP_TOO_HIGH : 5,
169      FACE_AUTH_TIP_TOO_LOW : 6,
170      FACE_AUTH_TIP_TOO_RIGHT : 7,
171      FACE_AUTH_TIP_TOO_LEFT : 8,
172      FACE_AUTH_TIP_TOO_MUCH_MOTION : 9,
173      FACE_AUTH_TIP_POOR_GAZE : 10,
174      FACE_AUTH_TIP_NOT_DETECTED : 11
175    },
176
177    FingerprintTips : {
178      FINGERPRINT_AUTH_TIP_GOOD : 0,
179      FINGERPRINT_AUTH_TIP_DIRTY : 1,
180      FINGERPRINT_AUTH_TIP_INSUFFICIENT : 2,
181      FINGERPRINT_AUTH_TIP_PARTIAL : 3,
182      FINGERPRINT_AUTH_TIP_TOO_FAST : 4,
183      FINGERPRINT_AUTH_TIP_TOO_SLOW : 5
184    },
185
186    UserAuthType : {
187      FACE : 2,
188      FINGERPRINT : 4
189    },
190
191    AuthTrustLevel : {
192      ATL1 : 10000,
193      ATL2 : 20000,
194      ATL3 : 30000,
195      ATL4 : 40000
196    },
197
198    getAuthenticator : function (...args) {
199      console.warn("uerAuth.getAuthenticator interface mocked in the Previewer. How this interface works on the" +
200        " Previewer may be different from that on a real device.")
201      return Authenticator;
202    },
203
204    getVersion : function (...args) {
205      console.warn("uerAuth.getVersion interface mocked in the Previewer." +
206        " How this interface works on the Previewer may be different from that on a real device.")
207        return paramMock.paramNumberMock;
208    },
209
210    getAvailableStatus : function (...args) {
211      console.warn("uerAuth.getAvailableStatus interface mocked in the Previewer." +
212        " How this interface works on the Previewer may be different from that on a real device.")
213    },
214
215    getAuthInstance : function (...args) {
216      console.warn("uerAuth.getAuthInstance interface mocked in the Previewer." +
217        " How this interface works on the Previewer may be different from that on a real device.")
218      return AuthInstance;
219    },
220
221    ResultCodeV9 : {
222      SUCCESS : 12500000,
223      FAIL : 12500001,
224      GENERAL_ERROR : 12500002,
225      CANCELED : 12500003,
226      TIMEOUT : 12500004,
227      TYPE_NOT_SUPPORT : 12500005,
228      TRUST_LEVEL_NOT_SUPPORT : 12500006,
229      BUSY : 12500007,
230      INVALID_PARAMETERS : 12500008,
231      LOCKED : 12500009,
232      NOT_ENROLLED : 12500010
233    },
234    UserAuth : UserAuthClass
235  }
236  return userAuth;
237}