/proc/self/cwd/test/integration/h1_fuzz.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "test/integration/h1_fuzz.h" |
2 | | |
3 | | #include <functional> |
4 | | |
5 | | #include "source/common/common/assert.h" |
6 | | #include "source/common/common/logger.h" |
7 | | |
8 | | #include "test/integration/http_integration.h" |
9 | | #include "test/test_common/environment.h" |
10 | | |
11 | | namespace Envoy { |
12 | | |
13 | | void H1FuzzIntegrationTest::replay(const test::integration::CaptureFuzzTestCase& input, |
14 | 1.30k | bool ignore_response) { |
15 | 1.30k | struct Init { |
16 | 1.30k | Init(H1FuzzIntegrationTest* test) { test->initialize(); } |
17 | 1.30k | }; |
18 | 1.30k | PERSISTENT_FUZZ_VAR(Init, initialized, (this)); |
19 | 1.30k | UNREFERENCED_PARAMETER(initialized); |
20 | 1.30k | IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("http")); |
21 | 1.30k | FakeRawConnectionPtr fake_upstream_connection; |
22 | 8.08k | for (int i = 0; i < input.events().size(); ++i) { |
23 | 6.86k | const auto& event = input.events(i); |
24 | 6.86k | ENVOY_LOG_MISC(debug, "Processing event: {}", event.DebugString()); |
25 | | // If we're disconnected, we fail out. |
26 | 6.86k | if (!tcp_client->connected()) { |
27 | 0 | ENVOY_LOG_MISC(debug, "Disconnected, no further event processing."); |
28 | 0 | break; |
29 | 0 | } |
30 | 6.86k | switch (event.event_selector_case()) { |
31 | 1.03k | case test::integration::Event::kDownstreamSendBytes: |
32 | 1.03k | ASSERT_TRUE(tcp_client->write(event.downstream_send_bytes(), false, false)); |
33 | 1.03k | break; |
34 | 1.03k | case test::integration::Event::kDownstreamRecvBytes: |
35 | | // TODO(htuch): Should we wait for some data? |
36 | 454 | break; |
37 | 607 | case test::integration::Event::kUpstreamSendBytes: |
38 | 607 | if (ignore_response) { |
39 | 363 | break; |
40 | 363 | } |
41 | 244 | if (fake_upstream_connection == nullptr) { |
42 | 111 | if (!fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection, max_wait_ms_)) { |
43 | | // If we timed out, we fail out. |
44 | 66 | tcp_client->close(); |
45 | 66 | return; |
46 | 66 | } |
47 | 111 | } |
48 | | // If we're no longer connected, we're done. |
49 | 178 | if (!fake_upstream_connection->connected()) { |
50 | 11 | tcp_client->close(); |
51 | 11 | return; |
52 | 11 | } |
53 | 167 | { |
54 | 167 | AssertionResult result = fake_upstream_connection->write(event.upstream_send_bytes()); |
55 | 167 | RELEASE_ASSERT(result, result.message()); |
56 | 167 | } |
57 | 167 | break; |
58 | 505 | case test::integration::Event::kUpstreamRecvBytes: |
59 | | // TODO(htuch): Should we wait for some data? |
60 | 505 | break; |
61 | 4.26k | default: |
62 | | // Maybe nothing is set? |
63 | 4.26k | break; |
64 | 6.86k | } |
65 | 6.86k | } |
66 | 1.22k | if (fake_upstream_connection != nullptr) { |
67 | 34 | if (fake_upstream_connection->connected()) { |
68 | 27 | AssertionResult result = fake_upstream_connection->close(); |
69 | 27 | RELEASE_ASSERT(result, result.message()); |
70 | 27 | } |
71 | 34 | AssertionResult result = fake_upstream_connection->waitForDisconnect(); |
72 | 34 | RELEASE_ASSERT(result, result.message()); |
73 | 34 | } |
74 | 1.22k | tcp_client->close(); |
75 | 1.22k | } |
76 | | |
77 | | } // namespace Envoy |