| #include <memory> |
| #include <string> |
| #include <utility> |
| |
| #include "gmock.h" |
| #include "gunit.h" |
| #include "testing/fuzzing/fuzztest.h" |
| #include "absl/strings/str_cat.h" |
| #include "absl/strings/string_view.h" |
| #include "fake_auth_context.h" |
| #include "proxy.h" |
| #include "proxy_config.pb.h" |
| #include "redfish_plugin.h" |
| #include "request_response.h" |
| #include "resource_authz.h" |
| |
| namespace milotic { |
| namespace { |
| |
| using ::testing::_; |
| using ::testing::Return; |
| |
| using ProxyRequest = milotic::ProxyRequest; |
| using RequestVerb = milotic::RedfishPlugin::RequestVerb; |
| |
| class MockPermissionChecker : public milotic::PermissionChecker { |
| public: |
| MOCK_METHOD(bool, Check, |
| (const milotic::AuthorizationContext& context, |
| absl::string_view permission_id), |
| (override)); |
| }; |
| |
| // Original fuzzer from proxy_test.cc |
| void ExpectQueryArbitraryParametersAreRemoved(absl::string_view parameters) { |
| auto permission_checker = std::make_unique<MockPermissionChecker>(); |
| EXPECT_CALL(*permission_checker, Check(_, "test-permission")) |
| .WillRepeatedly(Return(true)); |
| |
| milotic_grpc_proxy::AuthorizationPolicy policy; |
| auto* mapping = policy.add_mappings(); |
| mapping->set_name("test_mapping"); |
| mapping->set_request_verb(milotic_grpc_proxy::REQUEST_VERB_GET); |
| mapping->add_resource_path("/some/resource"); |
| (*mapping->mutable_allow())["permission"].set_permission_id( |
| "test-permission"); |
| |
| milotic::Proxy proxy(milotic::Host::CreateTestHosts("test_endpoint"), {}, |
| nullptr, {}, policy, std::move(permission_checker)); |
| milotic::FakeAuthContext auth_context(false); |
| |
| auto result = proxy.CreateAuthorizedRequest( |
| RequestVerb::kGet, absl::StrCat("/some/resource?", parameters), |
| auth_context); |
| if (result.ok()) { |
| EXPECT_EQ((*result)->GetPath(), "/some/resource"); |
| } |
| } |
| |
| FUZZ_TEST(ProxyFuzzTest, ExpectQueryArbitraryParametersAreRemoved); |
| |
| } // namespace |
| } // namespace milotic |