forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h1_fuzz.cc
78 lines (72 loc) · 2.58 KB
/
h1_fuzz.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "test/integration/h1_fuzz.h"
#include <functional>
#include "common/common/assert.h"
#include "common/common/logger.h"
#include "test/integration/http_integration.h"
#include "test/test_common/environment.h"
namespace Envoy {
void H1FuzzIntegrationTest::replay(const test::integration::CaptureFuzzTestCase& input,
bool ignore_response) {
PERSISTENT_FUZZ_VAR bool initialized = [this]() -> bool {
initialize();
fake_upstreams_[0]->set_allow_unexpected_disconnects(true);
return true;
}();
UNREFERENCED_PARAMETER(initialized);
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("http"));
FakeRawConnectionPtr fake_upstream_connection;
for (int i = 0; i < input.events().size(); ++i) {
const auto& event = input.events(i);
ENVOY_LOG_MISC(debug, "Processing event: {}", event.DebugString());
// If we're disconnected, we fail out.
if (!tcp_client->connected()) {
ENVOY_LOG_MISC(debug, "Disconnected, no further event processing.");
break;
}
switch (event.event_selector_case()) {
case test::integration::Event::kDownstreamSendBytes:
ASSERT_TRUE(tcp_client->write(event.downstream_send_bytes(), false, false));
break;
case test::integration::Event::kDownstreamRecvBytes:
// TODO(htuch): Should we wait for some data?
break;
case test::integration::Event::kUpstreamSendBytes:
if (ignore_response) {
break;
}
if (fake_upstream_connection == nullptr) {
if (!fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection, max_wait_ms_)) {
// If we timed out, we fail out.
tcp_client->close();
return;
}
}
// If we're no longer connected, we're done.
if (!fake_upstream_connection->connected()) {
tcp_client->close();
return;
}
{
AssertionResult result = fake_upstream_connection->write(event.upstream_send_bytes());
RELEASE_ASSERT(result, result.message());
}
break;
case test::integration::Event::kUpstreamRecvBytes:
// TODO(htuch): Should we wait for some data?
break;
default:
// Maybe nothing is set?
break;
}
}
if (fake_upstream_connection != nullptr) {
if (fake_upstream_connection->connected()) {
AssertionResult result = fake_upstream_connection->close();
RELEASE_ASSERT(result, result.message());
}
AssertionResult result = fake_upstream_connection->waitForDisconnect(true);
RELEASE_ASSERT(result, result.message());
}
tcp_client->close();
}
} // namespace Envoy