Debian Codegraph @

tests/fuzz/http-client.cpp

raw symbols SCIP
1 // Copyright (c) 2017-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #include <boost/utility/string_ref.hpp>
30 #include "include_base_utils.h"
31 #include "file_io_utils.h"
32 #include "net/http_client.h"
33 #include "net/net_ssl.h"
34 #include "fuzzer.h"
35
36 class dummy_client
37 {
38 public:
39 bool connect(const std::string& addr, int port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
40 bool connect(const std::string& addr, const std::string& port, std::chrono::milliseconds timeout, bool ssl = false, const std::string& bind_ip = "0.0.0.0") { return true; }
41 bool disconnect() { return true; }
42 bool send(const boost::string_ref buff, std::chrono::milliseconds timeout) { return true; }
43 bool send(const void* data, size_t sz) { return true; }
44 bool is_connected() { return true; }
45 bool recv(std::string& buff, std::chrono::milliseconds timeout)
46 {
47 buff = data;
48 data.clear();
49 return true;
50 }
51 void set_ssl(epee::net_utils::ssl_options_t ssl_options) { }
52 bool is_connected(bool *ssl = NULL) { return true; }
53 uint64_t get_bytes_sent() const { return 1; }
54 uint64_t get_bytes_received() const { return 1; }
55
56 void set_test_data(const std::string &s) { data = s; }
57
58 private:
59 std::string data;
60 };
61
62 static epee::net_utils::http::http_simple_client_template<dummy_client> client;
63
64 BEGIN_INIT_SIMPLE_FUZZER()
65 END_INIT_SIMPLE_FUZZER()
66
67 BEGIN_SIMPLE_FUZZER()
68 client.test(std::string((const char*)buf, len), std::chrono::milliseconds(1000));
69 END_SIMPLE_FUZZER()