1 /*
2 * Copyright (c) 2024-2025 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
16 #include "auth_hichain_deps_mock.h"
17
18 using namespace testing;
19 using namespace testing::ext;
20
21 namespace OHOS {
22 constexpr int64_t TEST_AUTH_SEQ = 1;
23 void *g_hichainMockInterface;
24
AuthHichainInterfaceMock()25 AuthHichainInterfaceMock::AuthHichainInterfaceMock()
26 {
27 g_hichainMockInterface = reinterpret_cast<void *>(this);
28 }
29
~AuthHichainInterfaceMock()30 AuthHichainInterfaceMock::~AuthHichainInterfaceMock()
31 {
32 g_hichainMockInterface = nullptr;
33 }
34
GetAuthHichainMockInterface()35 static AuthHichainInterface *GetAuthHichainMockInterface()
36 {
37 return reinterpret_cast<AuthHichainInterfaceMock *>(g_hichainMockInterface);
38 }
39
40 extern "C" {
cJSON_CreateObject()41 cJSON *cJSON_CreateObject()
42 {
43 return GetAuthHichainMockInterface()->cJSON_CreateObject();
44 }
45
AddStringToJsonObject(cJSON * json,const char * const string,const char * value)46 bool AddStringToJsonObject(cJSON *json, const char * const string, const char *value)
47 {
48 return GetAuthHichainMockInterface()->AddStringToJsonObject(json, string, value);
49 }
50
AddBoolToJsonObject(cJSON * json,const char * const string,bool value)51 bool AddBoolToJsonObject(cJSON *json, const char * const string, bool value)
52 {
53 return GetAuthHichainMockInterface()->AddBoolToJsonObject(json, string, value);
54 }
55
AddNumberToJsonObject(cJSON * json,const char * const string,int32_t num)56 bool AddNumberToJsonObject(cJSON *json, const char * const string, int32_t num)
57 {
58 return GetAuthHichainMockInterface()->AddNumberToJsonObject(json, string, num);
59 }
60
cJSON_PrintUnformatted(const cJSON * json)61 char *cJSON_PrintUnformatted(const cJSON *json)
62 {
63 return GetAuthHichainMockInterface()->cJSON_PrintUnformatted(json);
64 }
65
AuthSessionPostAuthData(int64_t authSeq,const uint8_t * data,uint32_t len)66 int32_t AuthSessionPostAuthData(int64_t authSeq, const uint8_t *data, uint32_t len)
67 {
68 return GetAuthHichainMockInterface()->AuthSessionPostAuthData(authSeq, data, len);
69 }
70
LnnEventExtraInit(LnnEventExtra * extra)71 void LnnEventExtraInit(LnnEventExtra *extra)
72 {
73 return GetAuthHichainMockInterface()->LnnEventExtraInit(extra);
74 }
75
GetLnnTriggerInfo(LnnTriggerInfo * triggerInfo)76 void GetLnnTriggerInfo(LnnTriggerInfo *triggerInfo)
77 {
78 return GetAuthHichainMockInterface()->GetLnnTriggerInfo(triggerInfo);
79 }
80
SoftBusGetSysTimeMs(void)81 uint64_t SoftBusGetSysTimeMs(void)
82 {
83 return GetAuthHichainMockInterface()->SoftBusGetSysTimeMs();
84 }
85
GetAuthFsmByAuthSeq(int64_t authSeq)86 AuthFsm *GetAuthFsmByAuthSeq(int64_t authSeq)
87 {
88 return GetAuthHichainMockInterface()->GetAuthFsmByAuthSeq(authSeq);
89 }
90
ReleaseAuthLock(void)91 void ReleaseAuthLock(void)
92 {
93 return GetAuthHichainMockInterface()->ReleaseAuthLock();
94 }
95
AuthSessionSaveSessionKey(int64_t authSeq,const uint8_t * key,uint32_t len)96 int32_t AuthSessionSaveSessionKey(int64_t authSeq, const uint8_t *key, uint32_t len)
97 {
98 return GetAuthHichainMockInterface()->AuthSessionSaveSessionKey(authSeq, key, len);
99 }
100
AuthSessionHandleAuthFinish(int64_t authSeq,AclWriteState aclState)101 int32_t AuthSessionHandleAuthFinish(int64_t authSeq, AclWriteState aclState)
102 {
103 return GetAuthHichainMockInterface()->AuthSessionHandleAuthFinish(authSeq, aclState);
104 }
105
GetAuthSideStr(bool isServer)106 const char *GetAuthSideStr(bool isServer)
107 {
108 return GetAuthHichainMockInterface()->GetAuthSideStr(isServer);
109 }
110
AuthFailNotifyProofInfo(int32_t errCode,const char * errorReturn,uint32_t errorReturnLen)111 int32_t AuthFailNotifyProofInfo(int32_t errCode, const char *errorReturn, uint32_t errorReturnLen)
112 {
113 return GetAuthHichainMockInterface()->AuthFailNotifyProofInfo(errCode, errorReturn, errorReturnLen);
114 }
115
LnnAsyncCallbackDelayHelper(SoftBusLooper * looper,LnnAsyncCallbackFunc callback,void * para,uint64_t delayMillis)116 int32_t LnnAsyncCallbackDelayHelper(SoftBusLooper *looper, LnnAsyncCallbackFunc callback,
117 void *para, uint64_t delayMillis)
118 {
119 return GetAuthHichainMockInterface()->LnnAsyncCallbackDelayHelper(looper, callback, para, delayMillis);
120 }
121
AuthSessionHandleAuthError(int64_t authSeq,int32_t reason)122 int32_t AuthSessionHandleAuthError(int64_t authSeq, int32_t reason)
123 {
124 return GetAuthHichainMockInterface()->AuthSessionHandleAuthError(authSeq, reason);
125 }
126
AuthSessionGetUdid(int64_t authSeq,char * udid,uint32_t size)127 int32_t AuthSessionGetUdid(int64_t authSeq, char *udid, uint32_t size)
128 {
129 return GetAuthHichainMockInterface()->AuthSessionGetUdid(authSeq, udid, size);
130 }
131
LnnGetLocalStrInfo(InfoKey key,char * info,uint32_t len)132 int32_t LnnGetLocalStrInfo(InfoKey key, char *info, uint32_t len)
133 {
134 return GetAuthHichainMockInterface()->LnnGetLocalStrInfo(key, info, len);
135 }
136
SoftBusGenerateStrHash(const unsigned char * str,uint32_t len,unsigned char * hash)137 int32_t SoftBusGenerateStrHash(const unsigned char *str, uint32_t len, unsigned char *hash)
138 {
139 return GetAuthHichainMockInterface()->SoftBusGenerateStrHash(str, len, hash);
140 }
141
ConvertBytesToHexString(char * outBuf,uint32_t outBufLen,const unsigned char * inBuf,uint32_t inLen)142 int32_t ConvertBytesToHexString(char *outBuf, uint32_t outBufLen,
143 const unsigned char *inBuf, uint32_t inLen)
144 {
145 return GetAuthHichainMockInterface()->ConvertBytesToHexString(outBuf, outBufLen, inBuf, inLen);
146 }
147
GetNodeFromPcRestrictMap(const char * udidHash,uint32_t * count)148 int32_t GetNodeFromPcRestrictMap(const char *udidHash, uint32_t *count)
149 {
150 return GetAuthHichainMockInterface()->GetNodeFromPcRestrictMap(udidHash, count);
151 }
152
DeleteNodeFromPcRestrictMap(const char * udidHash)153 void DeleteNodeFromPcRestrictMap(const char *udidHash)
154 {
155 return GetAuthHichainMockInterface()->DeleteNodeFromPcRestrictMap(udidHash);
156 }
157
GetJsonObjectStringItem(const cJSON * json,const char * const string,char * target,uint32_t targetLen)158 bool GetJsonObjectStringItem(const cJSON *json, const char * const string, char *target, uint32_t targetLen)
159 {
160 return GetAuthHichainMockInterface()->GetJsonObjectStringItem(json, string, target, targetLen);
161 }
162
GetJsonObjectNumberItem(const cJSON * json,const char * const string,int32_t * target)163 bool GetJsonObjectNumberItem(const cJSON *json, const char * const string, int32_t *target)
164 {
165 return GetAuthHichainMockInterface()->GetJsonObjectNumberItem(json, string, target);
166 }
167
RequireAuthLock(void)168 bool RequireAuthLock(void)
169 {
170 return GetAuthHichainMockInterface()->RequireAuthLock();
171 }
172
AuthSessionGetAuthVersion(int64_t authSeq,int32_t * version)173 int32_t AuthSessionGetAuthVersion(int64_t authSeq, int32_t *version)
174 {
175 if (authSeq == TEST_AUTH_SEQ) {
176 return SOFTBUS_AUTH_GET_SESSION_INFO_FAIL;
177 }
178
179 *version = AUTH_VERSION_V2;
180 return SOFTBUS_OK;
181 }
182
AuthSessionGetIsSameAccount(int64_t authSeq)183 bool AuthSessionGetIsSameAccount(int64_t authSeq)
184 {
185 (void)authSeq;
186 return true;
187 }
188
AuthSessionGetUserId(int64_t authSeq)189 int32_t AuthSessionGetUserId(int64_t authSeq)
190 {
191 (void)authSeq;
192 return 0;
193 }
194
LnnGetLocalByteInfo(InfoKey key,uint8_t * info,uint32_t len)195 int32_t LnnGetLocalByteInfo(InfoKey key, uint8_t *info, uint32_t len)
196 {
197 return GetAuthHichainMockInterface()->LnnGetLocalByteInfo(key, info, len);
198 }
199
JSON_GetStringFromObject(const JsonObj * obj,const char * key,char * value,uint32_t size)200 bool JSON_GetStringFromObject(const JsonObj *obj, const char *key, char *value, uint32_t size)
201 {
202 return GetAuthHichainMockInterface()->JSON_GetStringFromObject(obj, key, value, size);
203 }
204
LnnGetLocalNodeInfoSafe(NodeInfo * info)205 int32_t LnnGetLocalNodeInfoSafe(NodeInfo *info)
206 {
207 return GetAuthHichainMockInterface()->LnnGetLocalNodeInfoSafe(info);
208 }
209
LnnIsDefaultOhosAccount(void)210 bool LnnIsDefaultOhosAccount(void)
211 {
212 return GetAuthHichainMockInterface()->LnnIsDefaultOhosAccount();
213 }
214
IdServiceQueryCredential(int32_t userId,const char * udidHash,const char * accountidHash,bool isSameAccount,char ** credList)215 int32_t IdServiceQueryCredential(int32_t userId, const char *udidHash, const char *accountidHash,
216 bool isSameAccount, char **credList)
217 {
218 return GetAuthHichainMockInterface()->IdServiceQueryCredential(userId, udidHash, accountidHash, isSameAccount,
219 credList);
220 }
221
AuthIdServiceQueryCredential(int32_t peerUserId,const char * udidHash,const char * accountidHash,bool isSameAccount,char ** credList)222 int32_t AuthIdServiceQueryCredential(int32_t peerUserId, const char *udidHash, const char *accountidHash,
223 bool isSameAccount, char **credList)
224 {
225 return GetAuthHichainMockInterface()->AuthIdServiceQueryCredential(peerUserId, udidHash, accountidHash,
226 isSameAccount, credList);
227 }
228
IdServiceGetCredIdFromCredList(int32_t userId,const char * credList)229 char *IdServiceGetCredIdFromCredList(int32_t userId, const char *credList)
230 {
231 return GetAuthHichainMockInterface()->IdServiceGetCredIdFromCredList(userId, credList);
232 }
233
AuthSessionGetCredId(int64_t authSeq)234 char *AuthSessionGetCredId(int64_t authSeq)
235 {
236 return GetAuthHichainMockInterface()->AuthSessionGetCredId(authSeq);
237 }
238
IdServiceGenerateAuthParam(HiChainAuthParam * hiChainParam)239 char *IdServiceGenerateAuthParam(HiChainAuthParam *hiChainParam)
240 {
241 return GetAuthHichainMockInterface()->IdServiceGenerateAuthParam(hiChainParam);
242 }
243
IdServiceAuthCredential(int32_t userId,int64_t authReqId,const char * authParams,const DeviceAuthCallback * cb)244 int32_t IdServiceAuthCredential(int32_t userId, int64_t authReqId, const char *authParams,
245 const DeviceAuthCallback *cb)
246 {
247 return GetAuthHichainMockInterface()->IdServiceAuthCredential(userId, authReqId, authParams, cb);
248 }
249
IdServiceProcessCredData(int64_t authSeq,const uint8_t * data,uint32_t len,DeviceAuthCallback * cb)250 int32_t IdServiceProcessCredData(int64_t authSeq, const uint8_t *data, uint32_t len,
251 DeviceAuthCallback *cb)
252 {
253 return GetAuthHichainMockInterface()->IdServiceProcessCredData(authSeq, data, len, cb);
254 }
255
JSON_AddStringToObject(JsonObj * obj,const char * key,const char * value)256 bool JSON_AddStringToObject(JsonObj *obj, const char *key, const char *value)
257 {
258 return GetAuthHichainMockInterface()->JSON_AddStringToObject(obj, key, value);
259 }
260
IdServiceDestroyCredentialList(char ** returnData)261 void IdServiceDestroyCredentialList(char **returnData)
262 {
263 return GetAuthHichainMockInterface()->IdServiceDestroyCredentialList(returnData);
264 }
265
GetActiveOsAccountIds(void)266 int32_t GetActiveOsAccountIds(void)
267 {
268 return GetAuthHichainMockInterface()->GetActiveOsAccountIds();
269 }
270
IsSKIdInvalid(int32_t sessionKeyId,const char * accountHash,const char * udidShortHash,int32_t userId)271 bool IsSKIdInvalid(int32_t sessionKeyId, const char *accountHash, const char *udidShortHash,
272 int32_t userId)
273 {
274 return GetAuthHichainMockInterface()->IsSKIdInvalid(sessionKeyId, accountHash, udidShortHash, userId);
275 }
276 } // extern "C"
277 } // namespace OHOS
278