Commit c73706ee authored by Orvid King's avatar Orvid King Committed by Facebook Github Bot

Shift AsyncSSLSocketTest to use NetworkSocket

Summary: Do it.

Reviewed By: yfeldblum

Differential Revision: D12988464

fbshipit-source-id: b5dd907f24f9064ea7c7e417e0616120339eb452
parent 1d27782a
......@@ -22,10 +22,11 @@
#include <folly/io/async/AsyncSSLSocket.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/ScopedEventBaseThread.h>
#include <folly/net/NetOps.h>
#include <folly/net/NetworkSocket.h>
#include <folly/portability/GMock.h>
#include <folly/portability/GTest.h>
#include <folly/portability/OpenSSL.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/Unistd.h>
#include <folly/ssl/Init.h>
......@@ -111,17 +112,12 @@ uint32_t TestSSLAsyncCacheServer::lookupDelay_ = 0;
constexpr size_t SSLClient::kMaxReadBufferSz;
constexpr size_t SSLClient::kMaxReadsPerEvent;
void getfds(int fds[2]) {
if (socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
void getfds(NetworkSocket fds[2]) {
if (netops::socketpair(PF_LOCAL, SOCK_STREAM, 0, fds) != 0) {
FAIL() << "failed to create socketpair: " << errnoStr(errno);
}
for (int idx = 0; idx < 2; ++idx) {
int flags = fcntl(fds[idx], F_GETFL, 0);
if (flags == -1) {
FAIL() << "failed to get flags for socket " << idx << ": "
<< errnoStr(errno);
}
if (fcntl(fds[idx], F_SETFL, flags | O_NONBLOCK) != 0) {
if (netops::set_socket_non_blocking(fds[idx]) != 0) {
FAIL() << "failed to put socket " << idx
<< " in non-blocking mode: " << errnoStr(errno);
}
......@@ -144,7 +140,7 @@ void sslsocketpair(
AsyncSSLSocket::UniquePtr* serverSock) {
auto clientCtx = std::make_shared<folly::SSLContext>();
auto serverCtx = std::make_shared<folly::SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, serverCtx);
clientSock->reset(new AsyncSSLSocket(clientCtx, eventBase, fds[0], false));
......@@ -258,7 +254,7 @@ TEST(AsyncSSLSocketTest, Renegotiate) {
EventBase eventBase;
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
std::array<int, 2> fds;
std::array<NetworkSocket, 2> fds;
getfds(fds.data());
getctx(clientCtx, dfServerCtx);
......@@ -495,7 +491,7 @@ class NextProtocolTest : public Test {
EventBase eventBase;
std::shared_ptr<SSLContext> clientCtx{std::make_shared<SSLContext>()};
std::shared_ptr<SSLContext> serverCtx{std::make_shared<SSLContext>()};
int fds[2];
NetworkSocket fds[2];
std::unique_ptr<AlpnClient> client;
std::unique_ptr<AlpnServer> server;
};
......@@ -568,7 +564,7 @@ TEST(AsyncSSLSocketTest, SNITestMatch) {
// tlsext_hostname match.
std::shared_ptr<SSLContext> hskServerCtx(dfServerCtx);
const std::string serverName("xyz.newdev.facebook.com");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -602,7 +598,7 @@ TEST(AsyncSSLSocketTest, SNITestNotMatch) {
const std::string clientRequestingServerName("foo.com");
const std::string serverExpectedServerName("xyz.newdev.facebook.com");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -636,7 +632,7 @@ TEST(AsyncSSLSocketTest, SNITestChangeServerName) {
// tlsext_hostname match.
std::shared_ptr<SSLContext> hskServerCtx(dfServerCtx);
const std::string serverName("xyz.newdev.facebook.com");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -669,7 +665,7 @@ TEST(AsyncSSLSocketTest, SNITestClientHelloNoHostname) {
std::shared_ptr<SSLContext> hskServerCtx(dfServerCtx);
const std::string serverExpectedServerName("xyz.newdev.facebook.com");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -915,7 +911,7 @@ TEST(AsyncSSLSocketTest, SSLParseClientHelloSuccess) {
clientCtx->loadCertificate(kTestCert);
clientCtx->loadTrustedCertificates(kTestCA);
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -962,7 +958,7 @@ TEST(AsyncSSLSocketTest, GetClientCertificate) {
clientCtx->loadCertificate(kClientTestCert);
clientCtx->loadTrustedCertificates(kTestCA);
std::array<int, 2> fds;
std::array<NetworkSocket, 2> fds;
getfds(fds.data());
AsyncSSLSocket::UniquePtr clientSock(
......@@ -999,7 +995,7 @@ TEST(AsyncSSLSocketTest, SSLParseClientHelloOnePacket) {
EventBase eventBase;
auto ctx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
int bufLen = 42;
......@@ -1041,7 +1037,7 @@ TEST(AsyncSSLSocketTest, SSLParseClientHelloTwoPackets) {
EventBase eventBase;
auto ctx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
int bufLen = 42;
......@@ -1100,7 +1096,7 @@ TEST(AsyncSSLSocketTest, SSLParseClientHelloMultiplePackets) {
EventBase eventBase;
auto ctx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
int bufLen = 42;
......@@ -1156,7 +1152,7 @@ TEST(AsyncSSLSocketTest, SSLHandshakeValidationSuccess) {
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -1194,7 +1190,7 @@ TEST(AsyncSSLSocketTest, SSLHandshakeValidationFailure) {
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -1234,7 +1230,7 @@ TEST(AsyncSSLSocketTest, OverrideSSLCtxDisableVerify) {
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -1285,7 +1281,7 @@ TEST(AsyncSSLSocketTest, OverrideSSLCtxEnableVerify) {
clientCtx->loadCertificate(kTestCert);
clientCtx->loadTrustedCertificates(kTestCA);
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -1317,7 +1313,7 @@ TEST(AsyncSSLSocketTest, SSLHandshakeValidationOverride) {
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -1354,7 +1350,7 @@ TEST(AsyncSSLSocketTest, SSLHandshakeValidationSkip) {
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, dfServerCtx);
......@@ -1402,7 +1398,7 @@ TEST(AsyncSSLSocketTest, ClientCertHandshakeSuccess) {
clientCtx->loadCertificate(kTestCert);
clientCtx->loadTrustedCertificates(kTestCA);
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -1459,7 +1455,7 @@ TEST(AsyncSSLSocketTest, NoClientCertHandshakeError) {
clientCtx->setVerificationOption(SSLContext::SSLVerifyPeerEnum::NO_VERIFY);
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -1684,7 +1680,7 @@ TEST(AsyncSSLSocketTest, OpenSSL110AsyncTest) {
clientCtx->setVerificationOption(SSLContext::SSLVerifyPeerEnum::NO_VERIFY);
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -1722,7 +1718,7 @@ TEST(AsyncSSLSocketTest, OpenSSL110AsyncTestFailure) {
clientCtx->setVerificationOption(SSLContext::SSLVerifyPeerEnum::NO_VERIFY);
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -1761,7 +1757,7 @@ TEST(AsyncSSLSocketTest, OpenSSL110AsyncTestClosedWithCallbackPending) {
clientCtx->setVerificationOption(SSLContext::SSLVerifyPeerEnum::NO_VERIFY);
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -1875,7 +1871,7 @@ TEST(AsyncSSLSocketTest, UnencryptedTest) {
auto clientCtx = std::make_shared<folly::SSLContext>();
auto serverCtx = std::make_shared<folly::SSLContext>();
int fds[2];
NetworkSocket fds[2];
getfds(fds);
getctx(clientCtx, serverCtx);
auto client =
......@@ -1892,7 +1888,7 @@ TEST(AsyncSSLSocketTest, UnencryptedTest) {
// Check that bytes are unencrypted
char c;
EXPECT_EQ(1, recv(fds[1], &c, 1, MSG_PEEK));
EXPECT_EQ(1, netops::recv(fds[1], &c, 1, MSG_PEEK));
EXPECT_EQ('a', c);
EventBaseAborter eba(&base, 3000);
......@@ -1913,7 +1909,7 @@ TEST(AsyncSSLSocketTest, UnencryptedTest) {
// Check that bytes are *not* unencrypted
char c2;
EXPECT_EQ(1, recv(fds[1], &c2, 1, MSG_PEEK));
EXPECT_EQ(1, netops::recv(fds[1], &c2, 1, MSG_PEEK));
EXPECT_NE('a', c2);
base.loop();
......@@ -1968,7 +1964,7 @@ TEST(AsyncSSLSocketTest, SSLAcceptRunnerBasic) {
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
clientCtx->loadTrustedCertificates(kTestCA);
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -2003,7 +1999,7 @@ TEST(AsyncSSLSocketTest, SSLAcceptRunnerAcceptError) {
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
clientCtx->loadTrustedCertificates(kTestCA);
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -2037,7 +2033,7 @@ TEST(AsyncSSLSocketTest, SSLAcceptRunnerAcceptClose) {
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
clientCtx->loadTrustedCertificates(kTestCA);
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -2071,7 +2067,7 @@ TEST(AsyncSSLSocketTest, SSLAcceptRunnerAcceptDestroy) {
clientCtx->ciphers("ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
clientCtx->loadTrustedCertificates(kTestCA);
int fds[2];
NetworkSocket fds[2];
getfds(fds);
AsyncSSLSocket::UniquePtr clientSock(
......@@ -2492,7 +2488,7 @@ TEST(AsyncSSLSocketTest, TestPreReceivedData) {
EventBase eventBase;
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
std::array<int, 2> fds;
std::array<NetworkSocket, 2> fds;
getfds(fds.data());
getctx(clientCtx, dfServerCtx);
......@@ -2506,7 +2502,7 @@ TEST(AsyncSSLSocketTest, TestPreReceivedData) {
// Steal some data from the server.
std::array<uint8_t, 10> buf;
auto bytesReceived = recv(fds[1], buf.data(), buf.size(), 0);
auto bytesReceived = netops::recv(fds[1], buf.data(), buf.size(), 0);
checkUnixError(bytesReceived, "recv failed");
serverSock->setPreReceivedData(
......@@ -2526,7 +2522,7 @@ TEST(AsyncSSLSocketTest, TestMoveFromAsyncSocket) {
EventBase eventBase;
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
std::array<int, 2> fds;
std::array<NetworkSocket, 2> fds;
getfds(fds.data());
getctx(clientCtx, dfServerCtx);
......@@ -2539,7 +2535,7 @@ TEST(AsyncSSLSocketTest, TestMoveFromAsyncSocket) {
// Steal some data from the server.
std::array<uint8_t, 10> buf;
auto bytesReceived = recv(fds[1], buf.data(), buf.size(), 0);
auto bytesReceived = netops::recv(fds[1], buf.data(), buf.size(), 0);
checkUnixError(bytesReceived, "recv failed");
serverSock->setPreReceivedData(
......
......@@ -776,7 +776,7 @@ class TestSSLAsyncCacheServer : public TestSSLServer {
}
};
void getfds(int fds[2]);
void getfds(NetworkSocket fds[2]);
void getctx(
std::shared_ptr<folly::SSLContext> clientCtx,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment