/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.07k | bool ignore_response) { |
15 | 1.07k | struct Init { |
16 | 1.07k | Init(H1FuzzIntegrationTest* test) { test->initialize(); } |
17 | 1.07k | }; |
18 | 1.07k | PERSISTENT_FUZZ_VAR(Init, initialized, (this)); |
19 | 1.07k | UNREFERENCED_PARAMETER(initialized); |
20 | 1.07k | IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("http")); |
21 | 1.07k | FakeRawConnectionPtr fake_upstream_connection; |
22 | 8.49k | for (int i = 0; i < input.events().size(); ++i) { |
23 | 7.54k | const auto& event = input.events(i); |
24 | 7.54k | ENVOY_LOG_MISC(debug, "Processing event: {}", event.DebugString()); |
25 | | // If we're disconnected, we fail out. |
26 | 7.54k | if (!tcp_client->connected()) { |
27 | 0 | ENVOY_LOG_MISC(debug, "Disconnected, no further event processing."); |
28 | 0 | break; |
29 | 0 | } |
30 | 7.54k | switch (event.event_selector_case()) { |
31 | 1.21k | case test::integration::Event::kDownstreamSendBytes: |
32 | 1.21k | ASSERT_TRUE(tcp_client->write(event.downstream_send_bytes(), false, false)); |
33 | 1.21k | break; |
34 | 1.21k | case test::integration::Event::kDownstreamRecvBytes: |
35 | | // TODO(htuch): Should we wait for some data? |
36 | 245 | break; |
37 | 374 | case test::integration::Event::kUpstreamSendBytes: |
38 | 374 | if (ignore_response) { |
39 | 157 | break; |
40 | 157 | } |
41 | 217 | if (fake_upstream_connection == nullptr) { |
42 | 138 | if (!fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection, max_wait_ms_)) { |
43 | | // If we timed out, we fail out. |
44 | 110 | tcp_client->close(); |
45 | 110 | return; |
46 | 110 | } |
47 | 138 | } |
48 | | // If we're no longer connected, we're done. |
49 | 107 | if (!fake_upstream_connection->connected()) { |
50 | 8 | tcp_client->close(); |
51 | 8 | return; |
52 | 8 | } |
53 | 99 | { |
54 | 99 | AssertionResult result = fake_upstream_connection->write(event.upstream_send_bytes()); |
55 | 99 | RELEASE_ASSERT(result, result.message()); |
56 | 99 | } |
57 | 99 | break; |
58 | 248 | case test::integration::Event::kUpstreamRecvBytes: |
59 | | // TODO(htuch): Should we wait for some data? |
60 | 248 | break; |
61 | 5.46k | default: |
62 | | // Maybe nothing is set? |
63 | 5.46k | break; |
64 | 7.54k | } |
65 | 7.54k | } |
66 | 952 | if (fake_upstream_connection != nullptr) { |
67 | 20 | if (fake_upstream_connection->connected()) { |
68 | 17 | AssertionResult result = fake_upstream_connection->close(); |
69 | 17 | RELEASE_ASSERT(result, result.message()); |
70 | 17 | } |
71 | 20 | AssertionResult result = fake_upstream_connection->waitForDisconnect(); |
72 | 20 | RELEASE_ASSERT(result, result.message()); |
73 | 20 | } |
74 | 952 | tcp_client->close(); |
75 | 952 | } |
76 | | |
77 | | } // namespace Envoy |