diff options
author | David Storch <david.storch@10gen.com> | 2016-10-20 18:16:51 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2016-10-24 19:15:36 -0400 |
commit | 9af567fdd5b5bf58e76209fc375502c8ee08b08d (patch) | |
tree | d388046fbb387278d6a29501208e538504e15f9e /src/mongo/client | |
parent | fe6ce934697d4f8d483829e275ef1f41d2d0e847 (diff) | |
download | mongo-9af567fdd5b5bf58e76209fc375502c8ee08b08d.tar.gz |
SERVER-26420 fix shell to not send internalClient info in isMaster
Diffstat (limited to 'src/mongo/client')
-rw-r--r-- | src/mongo/client/dbclient.cpp | 4 | ||||
-rw-r--r-- | src/mongo/client/scoped_db_conn_test.cpp | 57 |
2 files changed, 52 insertions, 9 deletions
diff --git a/src/mongo/client/dbclient.cpp b/src/mongo/client/dbclient.cpp index a2aff7de7b1..5479addd638 100644 --- a/src/mongo/client/dbclient.cpp +++ b/src/mongo/client/dbclient.cpp @@ -752,7 +752,9 @@ executor::RemoteCommandResponse initWireVersion(DBClientConnection* conn, conn->getCompressorManager().clientBegin(&bob); - WireSpec::appendInternalClientWireVersion(WireSpec::instance().outgoing, &bob); + if (WireSpec::instance().isInternalClient) { + WireSpec::appendInternalClientWireVersion(WireSpec::instance().outgoing, &bob); + } Date_t start{Date_t::now()}; auto result = diff --git a/src/mongo/client/scoped_db_conn_test.cpp b/src/mongo/client/scoped_db_conn_test.cpp index 47e0b6cb415..b58e4fd9903 100644 --- a/src/mongo/client/scoped_db_conn_test.cpp +++ b/src/mongo/client/scoped_db_conn_test.cpp @@ -125,7 +125,7 @@ private: /** * Subclasses can override this in order to make assertions about the command request. */ - virtual void commandRequestHook(const rpc::RequestInterface* request) {} + virtual void commandRequestHook(const rpc::RequestInterface* request) const {} std::vector<stdx::thread> _threads; }; @@ -221,6 +221,8 @@ private: class DummyServerFixture : public unittest::Test { public: void setUp() { + WireSpec::instance().isInternalClient = isInternalClient(); + _maxPoolSizePerHost = globalConnPool.getMaxPoolSize(); _dummyServer = stdx::make_unique<DummyServer>(TARGET_PORT); @@ -322,10 +324,18 @@ private: /** * Subclasses can override this in order to use a specialized service entry point. */ - virtual std::unique_ptr<DummyServiceEntryPoint> makeServiceEntryPoint() { + virtual std::unique_ptr<DummyServiceEntryPoint> makeServiceEntryPoint() const { return stdx::make_unique<DummyServiceEntryPoint>(); } + /** + * Subclasses can override this to make the client code behave like an internal client (e.g. + * mongod or mongos) as opposed to an external one (e.g. the shell). + */ + virtual bool isInternalClient() const { + return false; + } + std::unique_ptr<DummyServer> _dummyServer; std::unique_ptr<DummyServiceEntryPoint> _dummyServiceEntryPoint; uint32_t _maxPoolSizePerHost; @@ -444,9 +454,9 @@ TEST_F(DummyServerFixture, DontReturnConnGoneBadToPool) { conn1Again.done(); } -class DummyServiceEntryPointWithIsMasterCheck : public DummyServiceEntryPoint { +class DummyServiceEntryPointWithInternalClientInfoCheck final : public DummyServiceEntryPoint { private: - virtual void commandRequestHook(const rpc::RequestInterface* request) { + void commandRequestHook(const rpc::RequestInterface* request) const final { if (request->getCommandName() != "isMaster") { // It's not an isMaster request. Nothing to do. return; @@ -464,14 +474,45 @@ private: } }; -class DummyServerFixtureWithIsMasterCheck : public DummyServerFixture { +class DummyServerFixtureWithInternalClientInfoCheck : public DummyServerFixture { +private: + std::unique_ptr<DummyServiceEntryPoint> makeServiceEntryPoint() const final { + return stdx::make_unique<DummyServiceEntryPointWithInternalClientInfoCheck>(); + } + + bool isInternalClient() const final { + return true; + } +}; + +TEST_F(DummyServerFixtureWithInternalClientInfoCheck, VerifyIsMasterRequestOnConnectionOpen) { + // The isMaster handshake will occur on connection open. The request is verified by the test + // fixture. + ScopedDbConnection conn(TARGET_HOST); + conn.done(); +} + +class DummyServiceEntryPointWithInternalClientMissingCheck final : public DummyServiceEntryPoint { +private: + void commandRequestHook(const rpc::RequestInterface* request) const final { + if (request->getCommandName() != "isMaster") { + // It's not an isMaster request. Nothing to do. + return; + } + + BSONObj commandArgs = request->getCommandArgs(); + ASSERT_FALSE(commandArgs["internalClient"]); + } +}; + +class DummyServerFixtureWithInternalClientMissingCheck : public DummyServerFixture { private: - virtual std::unique_ptr<DummyServiceEntryPoint> makeServiceEntryPoint() { - return stdx::make_unique<DummyServiceEntryPointWithIsMasterCheck>(); + std::unique_ptr<DummyServiceEntryPoint> makeServiceEntryPoint() const final { + return stdx::make_unique<DummyServiceEntryPointWithInternalClientMissingCheck>(); } }; -TEST_F(DummyServerFixtureWithIsMasterCheck, VerifyIsMasterRequestOnConnectionOpen) { +TEST_F(DummyServerFixtureWithInternalClientMissingCheck, VerifyIsMasterRequestOnConnectionOpen) { // The isMaster handshake will occur on connection open. The request is verified by the test // fixture. ScopedDbConnection conn(TARGET_HOST); |