1 /*
2 * Copyright (c) 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 "isauthenticationexpired_fuzzer.h"
17
18 #include "account_log_wrapper.h"
19 #include "domain_account_client.h"
20 #include "fuzz_data.h"
21 #include <string>
22
23 using namespace std;
24 using namespace OHOS::AccountSA;
25
26 namespace OHOS {
27 namespace {
28 const int ENUM_MAX = 4;
29 const int TEST_ENUM = 5;
30 }
IsAuthenticationExpiredFuzzTest(const uint8_t * data,size_t size)31 bool IsAuthenticationExpiredFuzzTest(const uint8_t* data, size_t size)
32 {
33 bool ret = true;
34 if ((data == nullptr) || (size == 0)) {
35 return false;
36 }
37 FuzzData fuzzData(data, size);
38 DomainAccountInfo info;
39 info.domain_ = fuzzData.GenerateString();
40 info.accountName_ = fuzzData.GenerateString();
41 info.accountId_ = fuzzData.GenerateString();
42 info.isAuthenticated = fuzzData.GenerateBool();
43 info.serverConfigId_ = fuzzData.GenerateString();
44 int typeNumber = fuzzData.GenerateBool() ? TEST_ENUM : fuzzData.GetData<int>() % ENUM_MAX;
45 info.status_ = static_cast<DomainAccountStatus>(typeNumber);
46 bool isExpired = fuzzData.GenerateBool();
47 ret = DomainAccountClient::GetInstance().IsAuthenticationExpired(info, isExpired);
48 return ret == ERR_OK;
49 }
50 }
51
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
54 {
55 /* Run your code on data */
56 OHOS::IsAuthenticationExpiredFuzzTest(data, size);
57 return 0;
58 }
59
60