| 137 | |
| 138 | |
| 139 | TEST_F(SSLClientTest, client) |
| 140 | { |
| 141 | // Create the socket based on the 'use_ssl' flag. We use this to |
| 142 | // test whether a regular socket could connect to an SSL server |
| 143 | // socket. |
| 144 | const Try<Socket> create = Socket::create( |
| 145 | flags.use_ssl ? SocketImpl::Kind::SSL : SocketImpl::Kind::POLL); |
| 146 | ASSERT_SOME(create); |
| 147 | |
| 148 | Socket socket = create.get(); |
| 149 | |
| 150 | Try<net::IP> ip = net::IP::parse(flags.server, AF_INET); |
| 151 | EXPECT_SOME(ip); |
| 152 | |
| 153 | // Connect to the server. |
| 154 | Address address(ip.get(), flags.port); |
| 155 | Future<Nothing> connect = [&]() { |
| 156 | switch(socket.kind()) { |
| 157 | case SocketImpl::Kind::POLL: |
| 158 | return socket.connect(address); |
| 159 | case SocketImpl::Kind::SSL: |
| 160 | return socket.connect( |
| 161 | address, |
| 162 | openssl::create_tls_client_config(flags.server_hostname)); |
| 163 | } |
| 164 | UNREACHABLE(); |
| 165 | }(); |
| 166 | |
| 167 | // Verify that the client views the connection as established. |
| 168 | AWAIT_EXPECT_READY(connect); |
| 169 | |
| 170 | // Send 'data' from the client to the server. |
| 171 | AWAIT_EXPECT_READY(socket.send(flags.data)); |
| 172 | |
| 173 | // Verify the client received the message back from the server. |
| 174 | AWAIT_EXPECT_EQ(flags.data, socket.recv()); |
| 175 | } |
| 176 | |
| 177 | #endif // USE_SSL_SOCKET |