forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uds_integration_test.cc
139 lines (114 loc) · 5.15 KB
/
uds_integration_test.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#include "uds_integration_test.h"
#include "envoy/config/bootstrap/v3/bootstrap.pb.h"
#include "common/event/dispatcher_impl.h"
#include "common/network/utility.h"
#include "test/test_common/network_utility.h"
#include "gtest/gtest.h"
namespace Envoy {
#if defined(__linux__)
INSTANTIATE_TEST_SUITE_P(
TestParameters, UdsUpstreamIntegrationTest,
testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
testing::Values(false, true)));
#else
INSTANTIATE_TEST_SUITE_P(
TestParameters, UdsUpstreamIntegrationTest,
testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
testing::Values(false)));
#endif
TEST_P(UdsUpstreamIntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) {
testRouterRequestAndResponseWithBody(1024, 512, false);
}
TEST_P(UdsUpstreamIntegrationTest, RouterHeaderOnlyRequestAndResponse) {
testRouterHeaderOnlyRequestAndResponse();
}
TEST_P(UdsUpstreamIntegrationTest, RouterUpstreamDisconnectBeforeResponseComplete) {
testRouterUpstreamDisconnectBeforeResponseComplete();
}
TEST_P(UdsUpstreamIntegrationTest, RouterDownstreamDisconnectBeforeRequestComplete) {
testRouterDownstreamDisconnectBeforeRequestComplete();
}
TEST_P(UdsUpstreamIntegrationTest, RouterDownstreamDisconnectBeforeResponseComplete) {
testRouterDownstreamDisconnectBeforeResponseComplete();
}
#if defined(__linux__)
INSTANTIATE_TEST_SUITE_P(
TestParameters, UdsListenerIntegrationTest,
testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
testing::Values(false, true)));
#else
INSTANTIATE_TEST_SUITE_P(
TestParameters, UdsListenerIntegrationTest,
testing::Combine(testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
testing::Values(false)));
#endif
void UdsListenerIntegrationTest::initialize() {
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) -> void {
auto* admin_addr = bootstrap.mutable_admin()->mutable_address();
admin_addr->clear_socket_address();
admin_addr->mutable_pipe()->set_path(getAdminSocketName());
auto* listeners = bootstrap.mutable_static_resources()->mutable_listeners();
RELEASE_ASSERT(!listeners->empty(), "");
auto filter_chains = listeners->Get(0).filter_chains();
listeners->Clear();
auto* listener = listeners->Add();
listener->set_name("listener_0");
listener->mutable_address()->mutable_pipe()->set_path(getListenerSocketName());
*(listener->mutable_filter_chains()) = filter_chains;
});
HttpIntegrationTest::initialize();
}
HttpIntegrationTest::ConnectionCreationFunction UdsListenerIntegrationTest::createConnectionFn() {
return [&]() -> Network::ClientConnectionPtr {
Network::ClientConnectionPtr conn(dispatcher_->createClientConnection(
Network::Utility::resolveUrl(fmt::format("unix://{}", getListenerSocketName())),
Network::Address::InstanceConstSharedPtr(), Network::Test::createRawBufferSocket(),
nullptr));
conn->enableHalfClose(enable_half_close_);
return conn;
};
}
TEST_P(UdsListenerIntegrationTest, TestPeerCredentials) {
fake_upstreams_count_ = 1;
initialize();
auto client_connection = createConnectionFn()();
codec_client_ = makeHttpConnection(std::move(client_connection));
Http::TestRequestHeaderMapImpl request_headers{
{":method", "POST"}, {":path", "/test/long/url"}, {":scheme", "http"},
{":authority", "host"}, {"x-lyft-user-id", "123"}, {"x-forwarded-for", "10.0.0.1"}};
auto response = codec_client_->makeHeaderOnlyRequest(request_headers);
waitForNextUpstreamRequest(0);
auto credentials = codec_client_->connection()->unixSocketPeerCredentials();
#ifndef SO_PEERCRED
EXPECT_EQ(credentials, absl::nullopt);
#else
EXPECT_EQ(credentials->pid, getpid());
EXPECT_EQ(credentials->uid, getuid());
EXPECT_EQ(credentials->gid, getgid());
#endif
upstream_request_->encodeHeaders(Http::TestResponseHeaderMapImpl{{":status", "200"}}, true);
response->waitForEndStream();
}
TEST_P(UdsListenerIntegrationTest, RouterRequestAndResponseWithBodyNoBuffer) {
ConnectionCreationFunction creator = createConnectionFn();
testRouterRequestAndResponseWithBody(1024, 512, false, &creator);
}
TEST_P(UdsListenerIntegrationTest, RouterHeaderOnlyRequestAndResponse) {
ConnectionCreationFunction creator = createConnectionFn();
testRouterHeaderOnlyRequestAndResponse(&creator);
}
TEST_P(UdsListenerIntegrationTest, RouterListenerDisconnectBeforeResponseComplete) {
ConnectionCreationFunction creator = createConnectionFn();
testRouterUpstreamDisconnectBeforeResponseComplete(&creator);
}
TEST_P(UdsListenerIntegrationTest, RouterDownstreamDisconnectBeforeRequestComplete) {
ConnectionCreationFunction creator = createConnectionFn();
testRouterDownstreamDisconnectBeforeRequestComplete(&creator);
}
// TODO(htuch): This is disabled due to
// https://github.com/envoyproxy/envoy/issues/2829.
TEST_P(UdsListenerIntegrationTest, DISABLED_RouterDownstreamDisconnectBeforeResponseComplete) {
ConnectionCreationFunction creator = createConnectionFn();
testRouterDownstreamDisconnectBeforeResponseComplete(&creator);
}
} // namespace Envoy