MCPcopy Create free account
hub / github.com/apache/thrift / server

Method server

lib/cpp/test/SecurityFromBufferTest.cpp:104–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

102
103struct SecurityFromBufferFixture {
104 void server(apache::thrift::transport::SSLProtocol protocol) {
105 try {
106 boost::mutex::scoped_lock lock(mMutex);
107
108 shared_ptr<TSSLSocketFactory> pServerSocketFactory;
109 shared_ptr<TSSLServerSocket> pServerSocket;
110
111 pServerSocketFactory.reset(new TSSLSocketFactory(static_cast<apache::thrift::transport::SSLProtocol>(protocol)));
112 #if OPENSSL_VERSION_NUMBER >= 0x10100000L
113 // OpenSSL 1.1.0 introduced @SECLEVEL. Modern distributions limit TLS 1.0/1.1
114 // to @SECLEVEL=0 or 1, so specify it to test all combinations.
115 pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@SECLEVEL=0");
116 #else
117 pServerSocketFactory->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
118 #endif
119 pServerSocketFactory->loadCertificateFromBuffer(certString("server.crt").c_str());
120 pServerSocketFactory->loadPrivateKeyFromBuffer(certString("server.key").c_str());
121 pServerSocketFactory->server(true);
122 pServerSocket.reset(new TSSLServerSocket("localhost", 0, pServerSocketFactory));
123 shared_ptr<TTransport> connectedClient;
124
125 try {
126 pServerSocket->listen();
127 mPort = pServerSocket->getPort();
128 mCVar.notify_one();
129 lock.unlock();
130
131 connectedClient = pServerSocket->accept();
132 uint8_t buf[2];
133 buf[0] = 'O';
134 buf[1] = 'K';
135 connectedClient->write(&buf[0], 2);
136 connectedClient->flush();
137 }
138
139 catch (apache::thrift::transport::TTransportException& ex) {
140 boost::mutex::scoped_lock lock(gMutex);
141 BOOST_TEST_MESSAGE(boost::format("SRV %1% Exception: %2%") % boost::this_thread::get_id() % ex.what());
142 }
143
144 if (connectedClient) {
145 connectedClient->close();
146 connectedClient.reset();
147 }
148
149 pServerSocket->close();
150 pServerSocket.reset();
151 } catch (std::exception& ex) {
152 BOOST_FAIL(boost::format("%1%: %2%") % typeid(ex).name() % ex.what());
153 }
154 }
155
156 void client(apache::thrift::transport::SSLProtocol protocol) {
157 try {

Callers

nothing calls this directly

Calls 14

certStringFunction · 0.85
ciphersMethod · 0.80
acceptMethod · 0.65
writeMethod · 0.65
closeMethod · 0.65
resetMethod · 0.45
listenMethod · 0.45
getPortMethod · 0.45
unlockMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected