proxygen
QPACKContextTests.cpp File Reference

Go to the source code of this file.

Functions

 TEST (QPACKContextTests, StaticOnly)
 
 TEST (QPACKContextTests, Indexed)
 
 TEST (QPACKContextTests, NameIndexed)
 
 TEST (QPACKContextTests, NameIndexedInsert)
 
 TEST (QPACKContextTests, PostBaseNameIndexedLiteral)
 
 TEST (QPACKContextTests, Unacknowledged)
 
 TEST (QPACKContextTests, TestDraining)
 
 TEST (QPACKContextTests, TestDuplicate)
 
 TEST (QPACKContextTests, TestTableSizeUpdate)
 
 TEST (QPACKContextTests, TestAcks)
 
 TEST (QPACKContextTests, TestImplicitAcks)
 
 TEST (QPACKContextTests, TestDecodeQueue)
 
 TEST (QPACKContextTests, TestDecodeQueueDelete)
 
 TEST (QPACKContextTests, TestDecodeMaxUncompressed)
 
 TEST (QPACKContextTests, TestDecoderStreamChunked)
 
 TEST (QPACKContextTests, TestDecodePartialControl)
 
void checkQError (QPACKDecoder &decoder, std::unique_ptr< IOBuf > buf, const HPACK::DecodeError err)
 
 TEST (QPACKContextTests, DecodeErrors)
 
 TEST (QPACKContextTests, TestEvictedNameReference)
 

Function Documentation

void checkQError ( QPACKDecoder decoder,
std::unique_ptr< IOBuf buf,
const HPACK::DecodeError  err 
)

Definition at line 417 of file QPACKContextTests.cpp.

References folly::IOBuf::computeChainDataLength(), proxygen::QPACKDecoder::decodeStreaming(), EXPECT_EQ, and folly::gen::move.

Referenced by TEST().

418  {
419  auto cb = std::make_unique<TestStreamingCallback>();
420  auto len = buf->computeChainDataLength();
421  // streamID only matters for cancellation
422  decoder.decodeStreaming(0, std::move(buf), len, cb.get());
423  EXPECT_EQ(cb->error, err);
424 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
void decodeStreaming(uint64_t streamId, std::unique_ptr< folly::IOBuf > block, uint32_t totalBytes, HPACK::StreamingCallback *streamingCb)
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
TEST ( QPACKContextTests  ,
StaticOnly   
)

Definition at line 68 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), proxygen::QPACKDecoder::encodeTableStateSync(), EXPECT_EQ, folly::gen::move, and proxygen::QPACKEncoder::EncodeResult::stream.

68  {
69  QPACKEncoder encoder(true, 128);
70  QPACKDecoder decoder(128);
71  vector<HPACKHeader> req;
72  req.push_back(HPACKHeader("accept-encoding", "gzip, deflate"));
73  auto result = encoder.encode(req, 10, 1);
74  EXPECT_EQ(result.stream->computeChainDataLength(), 3);
75  EXPECT_EQ(result.stream->data()[0], 0);
76  EXPECT_EQ(result.stream->data()[1], 0);
77  verifyDecode(decoder, std::move(result), req);
78  // nothing to ack
79  EXPECT_EQ(decoder.encodeTableStateSync(), nullptr);
80 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
Indexed   
)

Definition at line 82 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), and folly::gen::move.

82  {
83  QPACKEncoder encoder(true, 128);
84  QPACKDecoder decoder(128);
85  vector<HPACKHeader> req;
86  // Encodes "Post Base"
87  req.push_back(HPACKHeader("Blarf", "Blah"));
88  auto result = encoder.encode(req, 10, 1);
89  verifyDecode(decoder, std::move(result), req);
90  // Encodes "Normal"
91  result = encoder.encode(req, 10, 2);
92  verifyDecode(decoder, std::move(result), req);
93 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
NameIndexed   
)

Definition at line 95 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), and folly::gen::move.

95  {
96  QPACKEncoder encoder(true, 64);
97  QPACKDecoder decoder(64);
98  vector<HPACKHeader> req;
99 
100  // Encodes a "Post Base" name index since the table is full
101  req.push_back(HPACKHeader("Blarf", "Blah"));
102  req.push_back(HPACKHeader("Blarf", "Blerg"));
103  auto result = encoder.encode(req, 10, 1);
104  verifyDecode(decoder, std::move(result), req);
105  // Encodes "Normal" name index
106  result = encoder.encode(req, 10, 2);
107  verifyDecode(decoder, std::move(result), req);
108 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
NameIndexedInsert   
)

Definition at line 110 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::EncodeResult::control, proxygen::QPACKEncoder::encode(), EXPECT_FALSE, and folly::gen::move.

110  {
111  QPACKEncoder encoder(false, 128);
112  QPACKDecoder decoder(128);
113  vector<HPACKHeader> req;
114 
115  req.push_back(HPACKHeader("Blarf", "Blah"));
116  auto result = encoder.encode(req, 10, 1);
117  verifyDecode(decoder, std::move(result), req);
118 
119  // Encodes an insert using a dynamic name reference
120  req.push_back(HPACKHeader("Blarf", "Blerg"));
121  result = encoder.encode(req, 10, 2);
122  EXPECT_FALSE(stringInOutput(result.control.get(), "blarf"));
123  verifyDecode(decoder, std::move(result), req);
124 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( QPACKContextTests  ,
PostBaseNameIndexedLiteral   
)

Definition at line 126 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), EXPECT_EQ, i, folly::gen::move, proxygen::QPACKEncoder::setMaxVulnerable(), and proxygen::QPACKEncoder::EncodeResult::stream.

126  {
127  QPACKEncoder encoder(false, 360);
128  QPACKDecoder decoder(360);
129  vector<HPACKHeader> req;
130 
131  encoder.setMaxVulnerable(1);
132  // Fills the table with exacty minFree (48) empty
133  for (auto i = 0; i < 8; i++) {
134  req.push_back(HPACKHeader(folly::to<std::string>("Blarf", i), "0"));
135  }
136  // Too big to put in the table without evicting, perfect
137  // for Post-Base Name-Indexed literal with idx=7
138  req.push_back(HPACKHeader("Blarf7", "blergblergblerg"));
139  auto result = encoder.encode(req, 10, 1);
140  EXPECT_EQ(result.stream->computeChainDataLength(),
141  2 /*prefix*/ + 8 /*pb indexed*/ + 2 /*name idx len*/ +
142  1 /*val len*/ + 15 /* value */);
143  verifyDecode(decoder, std::move(result), req);
144 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
Unacknowledged   
)

Definition at line 147 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), EXPECT_GT, folly::gen::move, proxygen::QPACKEncoder::setMaxVulnerable(), and proxygen::QPACKEncoder::EncodeResult::stream.

147  {
148  QPACKEncoder encoder(true, 128);
149  QPACKDecoder decoder(128);
150  // Disallow unack'd headers
151  encoder.setMaxVulnerable(0);
152  vector<HPACKHeader> req;
153  req.push_back(HPACKHeader("Blarf", "Blah"));
154  auto result = encoder.encode(req, 10, 1);
155 
156  // Stream will encode a literal: prefix(2) + <more than 1>
157  EXPECT_GT(result.stream->computeChainDataLength(), 3);
158  verifyDecode(decoder, std::move(result), req);
159 
160  req.push_back(HPACKHeader("Blarf", "Blerg"));
161  result = encoder.encode(req, 10, 2);
162  EXPECT_GT(result.stream->computeChainDataLength(), 4);
163  verifyDecode(decoder, std::move(result), req);
164 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934
TEST ( QPACKContextTests  ,
TestDraining   
)

Definition at line 166 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), EXPECT_GT, EXPECT_TRUE, and proxygen::QPACKEncoder::EncodeResult::stream.

166  {
167  QPACKEncoder encoder(false, 128);
168  vector<HPACKHeader> req;
169  req.push_back(HPACKHeader("accept-encoding", "gzip,deflate"));
170  auto result = encoder.encode(req, 0, 1);
171 
172  // This will result in the first header being drained in the middle
173  // of encoding the new control channel, and force a literal.
174  req.clear();
175  req.push_back(HPACKHeader("accept-encoding", "sdch,gzip"));
176  req.push_back(HPACKHeader("accept-encoding", "gzip,deflate"));
177  result = encoder.encode(req, 0, 2);
178  EXPECT_GT(result.stream->computeChainDataLength(), 4);
179  EXPECT_TRUE(stringInOutput(result.stream.get(), "gzip,deflate"));
180 }
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934
TEST ( QPACKContextTests  ,
TestDuplicate   
)

Definition at line 182 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::EncodeResult::control, proxygen::QPACKEncoder::encode(), EXPECT_EQ, i, folly::gen::move, proxygen::QPACKEncoder::onTableStateSync(), and proxygen::QPACKEncoder::EncodeResult::stream.

182  {
183  QPACKEncoder encoder(false, 200);
184  QPACKDecoder decoder(200);
185  vector<HPACKHeader> req;
186  // 5 inserts and one literal
187  for (auto i = 0; i < 6; i++) {
188  req.emplace_back(folly::to<string>('a' + i), folly::to<string>(i));
189  }
190  // a=0 should now be draining
191  auto result = encoder.encode(req, 0, 1);
192  verifyDecode(decoder, std::move(result), req);
193  EXPECT_EQ(encoder.onTableStateSync(5), HPACK::DecodeError::NONE);
194  EXPECT_EQ(headerAck(decoder, encoder, 1), HPACK::DecodeError::NONE);
195  req.erase(req.begin() + 1, req.end());
196  result = encoder.encode(req, 0, 2);
197  // Control contains one-byte duplicate instruction, stream prefix + 1
198  EXPECT_EQ(result.control->computeChainDataLength(), 1);
199  EXPECT_EQ(result.stream->computeChainDataLength(), 3);
200  verifyDecode(decoder, std::move(result), req);
201 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
TestTableSizeUpdate   
)

Definition at line 203 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), EXPECT_EQ, proxygen::QPACKContext::getHeadersStored(), folly::gen::move, proxygen::QPACKEncoder::onTableStateSync(), and proxygen::QPACKEncoder::setHeaderTableSize().

203  {
204  QPACKEncoder encoder(false, 100);
205  QPACKDecoder decoder(100);
206  vector<HPACKHeader> req;
207  req.emplace_back("Blarf", "Blah");
208  req.emplace_back("Blarf", "Blerg");
209  auto result = encoder.encode(req, 0, 1);
210  verifyDecode(decoder, std::move(result), req);
211  EXPECT_EQ(encoder.onTableStateSync(2), HPACK::DecodeError::NONE);
212  EXPECT_EQ(headerAck(decoder, encoder, 1), HPACK::DecodeError::NONE);
213  encoder.setHeaderTableSize(64); // This will evict the oldest header
214  EXPECT_EQ(encoder.getHeadersStored(), 1);
215  result = encoder.encode(req, 0, 2);
216  verifyDecode(decoder, std::move(result), req);
217  EXPECT_EQ(decoder.getHeadersStored(), 1);
218  EXPECT_EQ(headerAck(decoder, encoder, 2), HPACK::DecodeError::NONE);
219 
220  encoder.setHeaderTableSize(100);
221  result = encoder.encode(req, 0, 3);
222  EXPECT_EQ(encoder.getHeadersStored(), 2);
223  verifyDecode(decoder, std::move(result), req);
224  EXPECT_EQ(decoder.getHeadersStored(), 2);
225 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
TestAcks   
)

Definition at line 228 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::EncodeResult::control, proxygen::QPACKEncoder::encode(), EXPECT_EQ, EXPECT_FALSE, EXPECT_GT, EXPECT_TRUE, folly::gen::move, proxygen::QPACKEncoder::onTableStateSync(), proxygen::QPACKEncoder::setMaxVulnerable(), and proxygen::QPACKEncoder::EncodeResult::stream.

228  {
229  QPACKEncoder encoder(false, 100);
230  QPACKDecoder decoder(100);
231  encoder.setMaxVulnerable(1);
232  EXPECT_EQ(encoder.onTableStateSync(1), HPACK::DecodeError::INVALID_ACK);
233  EXPECT_EQ(headerAck(decoder, encoder, 1), HPACK::DecodeError::INVALID_ACK);
234 
235  vector<HPACKHeader> req;
236  req.emplace_back("Blarf", "BlahBlahBlah");
237  auto result = encoder.encode(req, 0, 1);
238  verifyDecode(decoder, std::move(result), req);
239  req.clear();
240  req.emplace_back("accept-encoding", "gzip, deflate");
241  result = encoder.encode(req, 0, 1);
242  verifyDecode(decoder, std::move(result), req);
243  req.clear();
244  req.emplace_back("Blarf", "BlahBlahBlah");
245  result = encoder.encode(req, 0, 1);
246  verifyDecode(decoder, std::move(result), req);
247 
248  // Blarf: Blah is unacknowledged and maxVulnerable is 1 -> literal
249  result = encoder.encode(req, 0, 2);
250  EXPECT_EQ(result.control, nullptr);
251  EXPECT_TRUE(stringInOutput(result.stream.get(), "blarf"));
252  verifyDecode(decoder, std::move(result), req);
253 
254  // Table is full and Blarf: BlahBlahBlah cannot be evicted -> literal
255  req.clear();
256  req.emplace_back("Foo", "BlahBlahBlahBlah!");
257  result = encoder.encode(req, 0, 3);
258  EXPECT_EQ(result.control, nullptr);
259  EXPECT_TRUE(stringInOutput(result.stream.get(), "foo"));
260  verifyDecode(decoder, std::move(result), req);
261  EXPECT_EQ(headerAck(decoder, encoder, 3), HPACK::DecodeError::NONE);
262 
263  // Should remove all encoder state. Blarf: BlahBlahBlah can now be evicted
264  // and a new vulnerable reference can be made.
265  EXPECT_EQ(headerAck(decoder, encoder, 2), HPACK::DecodeError::NONE);
266  EXPECT_EQ(cancelStream(decoder, encoder, 1), HPACK::DecodeError::NONE);
267  EXPECT_EQ(encoder.onTableStateSync(1), HPACK::DecodeError::NONE);
268 
269  result = encoder.encode(req, 0, 2);
270  // Encodes an insert
271  EXPECT_GT(result.control->computeChainDataLength(), 1);
272  EXPECT_EQ(result.stream->computeChainDataLength(), 3);
273  EXPECT_FALSE(stringInOutput(result.stream.get(), "foo"));
274  verifyDecode(decoder, std::move(result), req);
275 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
#define EXPECT_GT(val1, val2)
Definition: gtest.h:1934
TEST ( QPACKContextTests  ,
TestImplicitAcks   
)

Definition at line 277 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), EXPECT_EQ, EXPECT_FALSE, folly::gen::move, proxygen::QPACKEncoder::onHeaderAck(), proxygen::QPACKEncoder::setMaxVulnerable(), and proxygen::QPACKEncoder::EncodeResult::stream.

277  {
278  QPACKEncoder encoder(false, 1024);
279  QPACKDecoder decoder(1024);
280  encoder.setMaxVulnerable(2);
281 
282  vector<HPACKHeader> req;
283  req.emplace_back("Blarf", "Blah");
284  auto result = encoder.encode(req, 0, 1);
285  verifyDecode(decoder, std::move(result), req);
286  req.emplace_back("Foo", "Blah");
287  result = encoder.encode(req, 0, 2);
288  verifyDecode(decoder, std::move(result), req);
289  EXPECT_EQ(encoder.onHeaderAck(2, false), HPACK::DecodeError::NONE);
290  // both headers are now acknowledged, 1 unacked header allowed
291  req.clear();
292  req.emplace_back("Bar", "Binky");
293  result = encoder.encode(req, 0, 3);
294 
295  // No unacked headers allowed
296  req.emplace_back("Blarf", "Blah");
297  req.emplace_back("Foo", "Blah");
298  result = encoder.encode(req, 0, 4);
299  EXPECT_FALSE(stringInOutput(result.stream.get(), "Blah"));
300  verifyDecode(decoder, std::move(result), req);
301 
302  // cancel
303  EXPECT_EQ(encoder.onHeaderAck(2, true), HPACK::DecodeError::NONE);
304  EXPECT_EQ(encoder.onHeaderAck(4, true), HPACK::DecodeError::NONE);
305 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( QPACKContextTests  ,
TestDecodeQueue   
)

Definition at line 307 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), and folly::gen::move.

307  {
308  QPACKEncoder encoder(false, 64);
309  QPACKDecoder decoder(64);
310 
311  vector<HPACKHeader> req1;
312  req1.emplace_back("Blarf", "Blah");
313  auto result1 = encoder.encode(req1, 0, 1);
314 
315  vector<HPACKHeader> req2;
316  req2.emplace_back("Blarf", "Blerg");
317  auto result2 = encoder.encode(req2, 0, 2);
318  verifyDecode(decoder, std::move(result2), req2);
319  verifyDecode(decoder, std::move(result1), req1);
320 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
TestDecodeQueueDelete   
)

Definition at line 322 of file QPACKContextTests.cpp.

References proxygen::QPACKDecoder::decodeStreaming(), proxygen::QPACKEncoder::encode(), EXPECT_EQ, and folly::gen::move.

322  {
323  // This test deletes the decoder from a callback while there are items in
324  // the queue
325  QPACKEncoder encoder(true, 100);
326  auto decoder = std::make_unique<QPACKDecoder>(100);
327 
328  vector<HPACKHeader> req1;
329  req1.emplace_back("Blarf", "Blah");
330  auto result1 = encoder.encode(req1, 0, 1);
331 
332  vector<HPACKHeader> req2;
333  req2.emplace_back("Blarf", "Blerg");
334  auto result2 = encoder.encode(req2, 0, 2);
335 
336 
337  // Decode #1, no control stream, queued
338  auto cb1 = std::make_unique<TestStreamingCallback>();
339  auto rawCb1 = cb1.get();
340  auto rawDecoder = decoder.get();
341  cb1->headersCompleteCb = [decoder=std::move(decoder)] () mutable {
342  // Delete decoder from callback
343  decoder.reset();
344  };
345  auto length = result1.stream->computeChainDataLength();
346  rawDecoder->decodeStreaming(1, std::move(result1.stream), length, rawCb1);
347 
348  // Decode #2, no control stream, queued
349  auto cb2 = std::make_unique<TestStreamingCallback>();
350  length = result2.stream->computeChainDataLength();
351  rawDecoder->decodeStreaming(2, std::move(result2.stream), length, cb2.get());
352 
353  // Decode control stream #1, will unblock 1 and delete decoder
354  EXPECT_EQ(rawDecoder->decodeEncoderStream(std::move(result1.control)),
355  HPACK::DecodeError::NONE);
356 
357  // cb2 doesn't execute because the decoder was destroyed from cb1
358  EXPECT_EQ(cb2->error, HPACK::DecodeError::NONE);
359  EXPECT_EQ(cb2->headers.size(), 0);
360 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
TestDecodeMaxUncompressed   
)

Definition at line 362 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::encode(), folly::gen::move, and proxygen::HPACKDecoderBase::setMaxUncompressed().

362  {
363  QPACKEncoder encoder(false, 64);
364  QPACKDecoder decoder(64);
365  decoder.setMaxUncompressed(5);
366 
367  vector<HPACKHeader> req;
368  req.emplace_back("Blarf", "Blah");
369  auto result = encoder.encode(req, 0, 1);
370  verifyDecode(decoder, std::move(result), req,
371  HPACK::DecodeError::HEADERS_TOO_LARGE);
372 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
TEST ( QPACKContextTests  ,
TestDecoderStreamChunked   
)

Definition at line 374 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::EncodeResult::control, proxygen::QPACKEncoder::decodeDecoderStream(), proxygen::QPACKDecoder::decodeEncoderStream(), proxygen::QPACKEncoder::encode(), proxygen::QPACKDecoder::encodeTableStateSync(), EXPECT_EQ, EXPECT_FALSE, EXPECT_TRUE, proxygen::QPACKContext::getTable(), i, proxygen::QPACKHeaderTable::isVulnerable(), and folly::gen::move.

374  {
375  QPACKEncoder encoder(false, 5000);
376  QPACKDecoder decoder(5000);
377 
378  vector<HPACKHeader> req;
379  for (auto i = 0; i < 128; i++) {
380  req.emplace_back("a", folly::to<string>(i));
381  }
382  auto result = encoder.encode(req, 0, 1);
383  EXPECT_EQ(decoder.decodeEncoderStream(std::move(result.control)),
384  HPACK::DecodeError::NONE);
385  auto ack = decoder.encodeTableStateSync();
386  EXPECT_EQ(ack->computeChainDataLength(), 2);
387  auto ackPart = ack->clone();
388  ackPart->trimEnd(1);
389  ack->trimStart(1);
390  EXPECT_EQ(encoder.decodeDecoderStream(std::move(ackPart)),
391  HPACK::DecodeError::NONE);
392  EXPECT_EQ(encoder.decodeDecoderStream(std::move(ack)),
393  HPACK::DecodeError::NONE);
394  EXPECT_FALSE(encoder.getTable().isVulnerable(128));
395  EXPECT_TRUE(encoder.getTable().isVulnerable(129));
396 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862
TEST ( QPACKContextTests  ,
TestDecodePartialControl   
)

Definition at line 398 of file QPACKContextTests.cpp.

References c, proxygen::QPACKEncoder::EncodeResult::control, proxygen::QPACKDecoder::decodeEncoderStream(), proxygen::QPACKEncoder::encode(), EXPECT_EQ, proxygen::QPACKContext::getHeader(), proxygen::QPACKContext::getHeadersStored(), and folly::gen::move.

398  {
399  QPACKEncoder encoder(false, 1000);
400  QPACKDecoder decoder(1000);
401 
402  vector<HPACKHeader> req;
403  req.emplace_back("abcdeabcdeabcdeabcdeabcdeabcdeabcde",
404  "vwxyzvwxyzvwxyzvwxyzvwxyzvwxyzvwxyz");
405  auto result = encoder.encode(req, 0, 1);
406  folly::io::Cursor c(result.control.get());
407  while (!c.isAtEnd()) {
408  std::unique_ptr<folly::IOBuf> buf;
409  c.clone(buf, 1);
410  EXPECT_EQ(decoder.decodeEncoderStream(std::move(buf)),
411  HPACK::DecodeError::NONE);
412  }
413  EXPECT_EQ(decoder.getHeadersStored(), 1);
414  EXPECT_EQ(decoder.getHeader(false, 1, 1, false), req[0]);
415 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
char c
TEST ( QPACKContextTests  ,
DecodeErrors   
)

Definition at line 426 of file QPACKContextTests.cpp.

References folly::IOBuf::append(), checkQError(), folly::IOBuf::clone(), folly::IOBuf::create(), proxygen::QPACKEncoder::decodeDecoderStream(), proxygen::QPACKDecoder::decodeEncoderStream(), EXPECT_EQ, proxygen::QPACKDecoder::setMaxBlocking(), folly::IOBuf::trimEnd(), and folly::IOBuf::writableData().

426  {
427  QPACKDecoder decoder(128);
428  unique_ptr<IOBuf> buf = IOBuf::create(128);
429 
430  // Largest ref invalid
431  buf->writableData()[0] = 0xFF;
432  buf->append(1);
433  checkQError(decoder, buf->clone(), HPACK::DecodeError::BUFFER_UNDERFLOW);
434 
435  // Base delta missing
436  buf->writableData()[0] = 0x01;
437  checkQError(decoder, buf->clone(), HPACK::DecodeError::BUFFER_UNDERFLOW);
438 
439  // Base delta invalid
440  buf->writableData()[1] = 0xFF;
441  buf->append(1);
442  checkQError(decoder, buf->clone(), HPACK::DecodeError::BUFFER_UNDERFLOW);
443 
444  // Base delta too negative
445  buf->writableData()[0] = 0x01;
446  buf->writableData()[1] = 0x82;
447  checkQError(decoder, buf->clone(), HPACK::DecodeError::INVALID_INDEX);
448 
449  // Exceeds blocking max
450  decoder.setMaxBlocking(0);
451  buf->writableData()[0] = 0x01;
452  buf->writableData()[1] = 0x00;
453  checkQError(decoder, buf->clone(), HPACK::DecodeError::TOO_MANY_BLOCKING);
454 
455  // valid prefix
456  buf->writableData()[0] = 0x00;
457  buf->writableData()[1] = 0x00;
458 
459  // Literal bad name index
460  buf->writableData()[2] = 0x4F;
461  buf->append(1);
462  checkQError(decoder, buf->clone(), HPACK::DecodeError::BUFFER_UNDERFLOW);
463 
464  // Literal invalid name index
465  buf->writableData()[2] = 0x41;
466  checkQError(decoder, buf->clone(), HPACK::DecodeError::INVALID_INDEX);
467 
468  // Literal bad name length
469  buf->writableData()[2] = 0x27;
470  checkQError(decoder, buf->clone(), HPACK::DecodeError::BUFFER_UNDERFLOW);
471 
472  // Literal invalid value length
473  buf->writableData()[2] = 0x51;
474  buf->writableData()[3] = 0xFF;
475  buf->append(1);
476  checkQError(decoder, buf->clone(), HPACK::DecodeError::BUFFER_UNDERFLOW);
477 
478  buf->trimEnd(1);
479  // Bad Index
480  buf->writableData()[2] = 0xBF;
481  checkQError(decoder, buf->clone(), HPACK::DecodeError::BUFFER_UNDERFLOW);
482 
483  // Zero static index
484  buf->writableData()[2] = 0xC0;
485  checkQError(decoder, buf->clone(), HPACK::DecodeError::INVALID_INDEX);
486 
487  // Invalid static index
488  buf->writableData()[2] = 0xFE;
489  checkQError(decoder, buf->clone(), HPACK::DecodeError::INVALID_INDEX);
490 
491  // No error after previous error
492  buf->writableData()[0] = 0xC1;
493  buf->writableData()[1] = 0x01;
494  buf->writableData()[2] = 0x41;
495  EXPECT_EQ(decoder.decodeEncoderStream(buf->clone()),
496  HPACK::DecodeError::NONE);
497 
498  // Control decode error
499  QPACKDecoder decoder2(64);
500  buf->writableData()[0] = 0x01; // duplicate dynamic index 1
501  buf->trimEnd(2);
502  EXPECT_EQ(decoder2.decodeEncoderStream(buf->clone()),
503  HPACK::DecodeError::INVALID_INDEX);
504 
505  QPACKEncoder encoder(true, 128);
506  buf->writableData()[0] = 0xFF;
507  buf->writableData()[1] = 0x80;
508  buf->writableData()[2] = 0xFF;
509  buf->writableData()[3] = 0xFF;
510  buf->writableData()[4] = 0xFF;
511  buf->writableData()[5] = 0xFF;
512  buf->writableData()[6] = 0xFF;
513  buf->writableData()[7] = 0xFF;
514  buf->writableData()[8] = 0xFF;
515  buf->writableData()[9] = 0xFF;
516  buf->writableData()[10] = 0xFF;
517  buf->writableData()[11] = 0x01;
518  buf->append(11);
519  // Bad header ack
520  EXPECT_EQ(encoder.decodeDecoderStream(buf->clone()),
521  HPACK::DecodeError::INTEGER_OVERFLOW);
522 
523  // Bad cancel
524  buf->writableData()[0] = 0x7F;
525  EXPECT_EQ(encoder.decodeDecoderStream(buf->clone()),
526  HPACK::DecodeError::INTEGER_OVERFLOW);
527 
528  // Bad table state sync
529  buf->writableData()[0] = 0x3F;
530  EXPECT_EQ(encoder.decodeDecoderStream(buf->clone()),
531  HPACK::DecodeError::INTEGER_OVERFLOW);
532 }
#define EXPECT_EQ(val1, val2)
Definition: gtest.h:1922
std::unique_ptr< IOBuf > clone() const
Definition: IOBuf.cpp:527
uint8_t * writableData()
Definition: IOBuf.h:509
void trimEnd(std::size_t amount)
Definition: IOBuf.h:718
void checkQError(QPACKDecoder &decoder, std::unique_ptr< IOBuf > buf, const HPACK::DecodeError err)
void append(std::size_t amount)
Definition: IOBuf.h:689
TEST ( QPACKContextTests  ,
TestEvictedNameReference   
)

Definition at line 534 of file QPACKContextTests.cpp.

References proxygen::QPACKEncoder::EncodeResult::control, proxygen::QPACKDecoder::decodeEncoderStream(), proxygen::QPACKDecoder::decodeStreaming(), proxygen::QPACKEncoder::encode(), EXPECT_FALSE, EXPECT_TRUE, proxygen::TestStreamingCallback::hasError(), folly::gen::move, proxygen::QPACKEncoder::onTableStateSync(), proxygen::QPACKEncoder::setMaxVulnerable(), and proxygen::QPACKEncoder::EncodeResult::stream.

534  {
535  QPACKEncoder encoder(false, 109);
536  QPACKDecoder decoder(109);
537  encoder.setMaxVulnerable(0);
538  vector<HPACKHeader> req;
539  req.push_back(HPACKHeader("x-accept-encoding", "foobarfoobar"));
540  auto result = encoder.encode(req, 0, 1);
541  decoder.decodeEncoderStream(std::move(result.control));
542  decoder.decodeStreaming(1, result.stream->clone(),
543  result.stream->computeChainDataLength(), nullptr);
544  encoder.onTableStateSync(1);
545  req.clear();
546  req.push_back(HPACKHeader("x-accept-encoding", "barfoobarfoo"));
547  result = encoder.encode(req, 0, 2);
548  EXPECT_TRUE(stringInOutput(result.stream.get(), "x-accept-encoding"));
550  decoder.decodeEncoderStream(std::move(result.control));
551  decoder.decodeStreaming(2, result.stream->clone(),
552  result.stream->computeChainDataLength(), &cb);
553  EXPECT_FALSE(cb.hasError());
554 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
#define EXPECT_TRUE(condition)
Definition: gtest.h:1859
#define EXPECT_FALSE(condition)
Definition: gtest.h:1862