9 #include <gmock/gmock.h> 10 #include <gtest/gtest.h> 17 using namespace folly;
28 auto readAead = std::make_unique<MockAead>();
29 readAead_ = readAead.get();
31 auto writeAead = std::make_unique<MockAead>();
32 writeAead_ = writeAead.get();
53 queue_.append(getBuf(hex));
57 auto str = buf->moveToFbString().toStdString();
67 addToQueue(
"17030100050123456789");
70 expectSame(buf,
"0123456789");
71 return getBuf(
"abcdef16");
73 auto msg = read_.read(queue_);
74 EXPECT_EQ(msg->type, ContentType::handshake);
75 expectSame(msg->fragment,
"abcdef");
80 addToQueue(
"17030100050123456789");
83 expectSame(buf,
"0123456789");
84 return getBuf(
"020215");
86 auto msg = read_.read(queue_);
88 expectSame(msg->fragment,
"0202");
93 addToQueue(
"17030100050123456789");
96 expectSame(buf,
"0123456789");
97 return getBuf(
"1234abcd17");
99 auto msg = read_.read(queue_);
100 EXPECT_EQ(msg->type, ContentType::application_data);
101 expectSame(msg->fragment,
"1234abcd");
106 addToQueue(
"17030100050123456789");
109 expectSame(buf,
"0123456789");
110 return getBuf(
"1234abcd20");
116 addToQueue(
"1703010010012345");
122 addToQueue(
"16030102");
128 addToQueue(
"1603014100");
134 addToQueue(
"1603015000");
139 addToQueue(
"17030100050123456789aa");
142 expectSame(buf,
"0123456789");
143 return getBuf(
"abcdef16");
150 addToQueue(
"17030100050123456789");
153 expectSame(buf,
"0123456789");
154 return getBuf(
"1234abcd17000000");
156 auto msg = read_.read(queue_);
157 EXPECT_EQ(msg->type, ContentType::application_data);
158 expectSame(msg->fragment,
"1234abcd");
163 addToQueue(
"17030100050123456789");
166 expectSame(buf,
"0123456789");
167 return getBuf(
"17000000");
169 auto msg = read_.read(queue_);
170 EXPECT_EQ(msg->type, ContentType::application_data);
176 addToQueue(
"17030100050123456789");
179 expectSame(buf,
"0123456789");
180 return getBuf(
"16000000");
186 addToQueue(
"17030100050123456789");
189 expectSame(buf,
"0123456789");
190 return getBuf(
"00000000");
196 for (
int i = 0;
i < 10;
i++) {
197 addToQueue(
"17030100050123456789");
201 expectSame(buf,
"0123456789");
202 return getBuf(
"1234abcd17");
209 read_.setSkipFailedDecryption(
true);
210 addToQueue(
"17030100050123456789");
222 read_.setSkipFailedDecryption(
true);
223 addToQueue(
"1703010005012345678917030100050123456789170301000501234567aa");
233 expectSame(buf,
"0123456789");
234 return getBuf(
"1234abcd17");
236 auto msg = read_.read(queue_);
237 EXPECT_EQ(msg->type, ContentType::application_data);
238 expectSame(msg->fragment,
"1234abcd");
243 expectSame(buf,
"01234567aa");
244 return getBuf(
"1234abaa17");
246 msg = read_.read(queue_);
247 EXPECT_EQ(msg->type, ContentType::application_data);
248 expectSame(msg->fragment,
"1234abaa");
253 TLSMessage msg{ContentType::handshake, getBuf(
"1234567890")};
256 expectSame(buf,
"123456789016");
257 return getBuf(
"abcd1234abcd");
260 expectSame(buf.data,
"1703030006abcd1234abcd");
264 TLSMessage msg{ContentType::application_data, getBuf(
"1234567890")};
267 expectSame(buf,
"123456789017");
268 return getBuf(
"abcd1234abcd");
271 expectSame(buf.data,
"1703030006abcd1234abcd");
275 TLSMessage msg{ContentType::application_data, getBuf(
"1234567890", 5, 17)};
280 expectSame(buf,
"123456789017");
282 return getBuf(
"abcd1234abcd", 5, 0);
286 expectSame(buf.data,
"1703030006abcd1234abcd");
291 msg.fragment->append(0x4a00);
292 memset(msg.fragment->writableData(), 0x1, msg.fragment->length());
299 return getBuf(
"aaaa");
305 return getBuf(
"bbbb");
307 auto outBuf = write_.write(
std::move(msg));
308 expectSame(outBuf.data,
"1703034001aaaa1703030a01bbbb");
313 msg.fragment->append(2000);
314 memset(msg.fragment->writableData(), 0x1, msg.fragment->length());
322 return getBuf(
"aaaa");
329 msg.fragment->append(500);
330 memset(msg.fragment->writableData(), 0x1, msg.fragment->length());
338 return getBuf(
"aaaa");
344 for (
int i = 0;
i < 10;
i++) {
345 TLSMessage msg{ContentType::application_data, getBuf(
"1234567890")};
349 expectSame(buf,
"123456789017");
350 return getBuf(
"abcd1234abcd");
358 auto outBuf = write_.write(
std::move(msg));
363 write_.setMaxRecord(1900);
366 msg.fragment->append(2000);
367 memset(msg.fragment->writableData(), 0x1, msg.fragment->length());
374 return getBuf(
"aaaa");
380 write_.setMinDesiredRecord(1700);
382 msg.fragment->append(1000);
383 memset(msg.fragment->writableData(), 0x1, msg.fragment->length());
386 memset(next->writableData(), 0x2, next->length());
387 msg.fragment->prependChain(
std::move(next));
394 return getBuf(
"aaaa");
399 return getBuf(
"bbbb");
#define EXPECT_ANY_THROW(statement)
bool unhexlify(const InputString &input, OutputString &output)
static void expectSame(const Buf &buf, const std::string &hex)
static std::unique_ptr< IOBuf > create(std::size_t capacity)
#define EXPECT_EQ(val1, val2)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
static Options cacheChainLength()
static Buf getBuf(const std::string &hex, size_t headroom=0, size_t tailroom=0)
PolymorphicAction< internal::InvokeAction< FunctionImpl > > Invoke(FunctionImpl function_impl)
constexpr auto data(C &c) -> decltype(c.data())
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
std::size_t computeChainDataLength() const
#define EXPECT_TRUE(condition)
std::unique_ptr< folly::IOBuf > Buf
void addToQueue(const std::string &hex)
#define EXPECT_CALL(obj, call)
const internal::AnythingMatcher _
#define EXPECT_FALSE(condition)
bool hexlify(const InputString &input, OutputString &output, bool append_output)
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)