| #include <memory> |
| #include <string> |
| #include <utility> |
| |
| #include "testing/fuzzing/fuzztest.h" |
| #include "absl/types/span.h" |
| #include "mock_ssh_client.h" |
| #include "proxy.h" |
| #include "proxy_config.pb.h" |
| #include "redfish_plugin.h" |
| #include "request_response.h" |
| #include "ssh_actions_plugin.h" |
| #include "voyager/deferrable_priority_queue.hpp" |
| |
| namespace milotic { |
| namespace { |
| |
| using milotic_grpc_proxy::Plugin; |
| |
| void FuzzSshHandleRequest(const std::string& json_body) { |
| Plugin::SshActions config; |
| auto* action = config.add_actions(); |
| action->set_action_path("/google/v1/Test/Actions/Action.p1"); |
| action->set_ssh_command("ls $0"); |
| action->set_args_count(1); |
| |
| auto plugin = std::make_unique<SshActionsPlugin>(config); |
| auto* plugin_ptr = plugin.get(); |
| |
| // Create a minimal Proxy environment to properly Initialize the plugin. |
| // The Proxy constructor calls plugin->Initialize(this). |
| voyager::DeferrablePriorityQueue queue(1); |
| std::unique_ptr<RedfishPlugin> handlers[] = {std::move(plugin)}; |
| Proxy proxy(Host::CreateTestHosts("test_endpoint"), absl::MakeSpan(handlers), |
| &queue, {.ssh_client = std::make_unique<MockSshClient>()}); |
| |
| auto request = std::make_unique<ProxyRequest>(); |
| request->SetPath("/google/v1/Test/Actions/Action.p1"); |
| request->SetBody(json_body); |
| |
| (void)plugin_ptr->HandleRequest(RedfishPlugin::RequestVerb::kPost, |
| std::move(request)); |
| } |
| |
| FUZZ_TEST(SshActionsPluginFuzzTest, FuzzSshHandleRequest); |
| |
| } // namespace |
| } // namespace milotic |