1 /*
2 * Copyright (c) 2022-2024 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 "addaccountimplicitly_fuzzer.h"
17
18 #include <string>
19 #include <vector>
20 #include "account_log_wrapper.h"
21 #define private public
22 #include "app_account_authenticator_callback_stub.h"
23 #include "app_account_manager.h"
24 #undef private
25 #include "fuzz_data.h"
26 #include "want.h"
27
28 using namespace std;
29 using namespace OHOS::AccountSA;
30
31 class MockAuthenticatorCallback : public OHOS::AccountSA::IAppAccountAuthenticatorCallback {
32 public:
OnResult(int32_t resultCode,const OHOS::AAFwk::Want & result)33 void OnResult(int32_t resultCode, const OHOS::AAFwk::Want& result) override
34 {
35 return;
36 }
OnRequestRedirected(OHOS::AAFwk::Want & request)37 void OnRequestRedirected(OHOS::AAFwk::Want& request) override
38 {
39 return;
40 }
OnRequestContinued()41 void OnRequestContinued() override
42 {
43 return;
44 }
AsObject()45 OHOS::sptr<OHOS::IRemoteObject> AsObject() override
46 {
47 return nullptr;
48 }
49 };
50 namespace OHOS {
AddAccountImplicitlyFuzzTest(const uint8_t * data,size_t size)51 bool AddAccountImplicitlyFuzzTest(const uint8_t* data, size_t size)
52 {
53 bool result = false;
54 if (size > 0) {
55 FuzzData fuzzData(data, size);
56 std::string testOwner(fuzzData.GenerateRandomString());
57 std::string testAuthType(fuzzData.GenerateRandomString());
58 std::string testKey(fuzzData.GenerateRandomString());
59 std::string testValue(fuzzData.GenerateRandomString());
60 AAFwk::Want options;
61 options.SetParam(testKey, testValue);
62 sptr<MockAuthenticatorCallback> callback = new (std::nothrow) MockAuthenticatorCallback();
63 result = AppAccountManager::AddAccountImplicitly(testOwner, testAuthType, options, callback);
64 }
65 return result;
66 }
67 }
68
69 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)70 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
71 {
72 /* Run your code on data */
73 OHOS::AddAccountImplicitlyFuzzTest(data, size);
74 return 0;
75 }
76
77