-
Notifications
You must be signed in to change notification settings - Fork 4.9k
/
Copy pathconfig_fuzz_test.cc
40 lines (32 loc) · 1.32 KB
/
config_fuzz_test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <fstream>
#include "common/common/thread.h"
#include "common/network/address_impl.h"
#include "server/config_validation/server.h"
#include "server/proto_descriptors.h"
#include "test/fuzz/fuzz_runner.h"
#include "test/integration/server.h"
#include "test/mocks/server/mocks.h"
#include "test/test_common/environment.h"
namespace Envoy {
namespace Server {
// Derived from //test/server:server_fuzz_test.cc, but starts the server in configuration validation
// mode (quits upon validation of the given config)
DEFINE_PROTO_FUZZER(const envoy::config::bootstrap::v2::Bootstrap& input) {
testing::NiceMock<MockOptions> options;
TestComponentFactory component_factory;
Fuzz::PerTestEnvironment test_env;
RELEASE_ASSERT(validateProtoDescriptors(), "");
const std::string bootstrap_path = test_env.temporaryPath("bootstrap.pb_text");
std::ofstream bootstrap_file(bootstrap_path);
bootstrap_file << input.DebugString();
options.config_path_ = bootstrap_path;
options.log_level_ = Fuzz::Runner::logLevel();
try {
validateConfig(options, Network::Address::InstanceConstSharedPtr(), component_factory,
Thread::threadFactoryForTest());
} catch (const EnvoyException& ex) {
ENVOY_LOG_MISC(debug, "Controlled EnvoyException exit: {}", ex.what());
}
}
} // namespace Server
} // namespace Envoy