diff --git a/src/runtime/rpc/network.sim.h b/src/runtime/rpc/network.sim.h index 2c4adbfd7e..4573f3c54b 100644 --- a/src/runtime/rpc/network.sim.h +++ b/src/runtime/rpc/network.sim.h @@ -93,6 +93,13 @@ class sim_network_provider : public connection_oriented_network return rpc_session_ptr(new sim_client_session(*this, server_addr, parser)); } + virtual rpc_session_ptr create_server_session(::dsn::rpc_address client_addr, + rpc_session_ptr client_session) + { + message_parser_ptr parser(new_message_parser(_client_hdr_format)); + return rpc_session_ptr(new sim_server_session(*this, client_addr, client_session, parser)); + } + uint32_t net_delay_milliseconds() const; private: @@ -102,5 +109,5 @@ class sim_network_provider : public connection_oriented_network }; //------------- inline implementations ------------- -} -} // end namespace +} // namespace tools +} // namespace dsn diff --git a/src/runtime/security/negotiation_service.h b/src/runtime/security/negotiation_service.h index fcc4d587d9..1ed7e06311 100644 --- a/src/runtime/security/negotiation_service.h +++ b/src/runtime/security/negotiation_service.h @@ -34,6 +34,7 @@ class negotiation_service : public serverlet, negotiation_service(); void on_negotiation_request(negotiation_rpc rpc); friend class utils::singleton; + friend class negotiation_service_test; }; } // namespace security diff --git a/src/runtime/test/negotiation_service_test.cpp b/src/runtime/test/negotiation_service_test.cpp new file mode 100644 index 0000000000..70ef3ad0b9 --- /dev/null +++ b/src/runtime/test/negotiation_service_test.cpp @@ -0,0 +1,61 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +#include "runtime/security/negotiation_service.h" +#include "runtime/security/negotiation_utils.h" +#include "runtime/rpc/network.sim.h" + +#include +#include + +namespace dsn { +namespace security { +DSN_DECLARE_bool(enable_auth); + +class negotiation_service_test : public testing::Test +{ +public: + negotiation_rpc create_fake_rpc() + { + std::unique_ptr sim_net( + new tools::sim_network_provider(nullptr, nullptr)); + auto sim_session = + sim_net->create_server_session(rpc_address("localhost", 10086), rpc_session_ptr()); + auto rpc = negotiation_rpc(make_unique(), RPC_NEGOTIATION); + rpc.dsn_request()->io_session = sim_session; + return rpc; + } + + void on_negotiation_request(negotiation_rpc rpc) + { + negotiation_service::instance().on_negotiation_request(rpc); + } +}; + +TEST_F(negotiation_service_test, disable_auth) +{ + RPC_MOCKING(negotiation_rpc) + { + FLAGS_enable_auth = false; + auto rpc = create_fake_rpc(); + on_negotiation_request(rpc); + + ASSERT_EQ(rpc.response().status, negotiation_status::type::SASL_AUTH_DISABLE); + } +} +} // namespace security +} // namespace dsn