forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalpn_integration_test.cc
103 lines (86 loc) · 4.09 KB
/
alpn_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
#include "test/integration/autonomous_upstream.h"
#include "test/integration/http_integration.h"
#include "gtest/gtest.h"
namespace Envoy {
namespace {
class AlpnIntegrationTest : public testing::TestWithParam<Network::Address::IpVersion>,
public HttpIntegrationTest {
public:
AlpnIntegrationTest() : HttpIntegrationTest(Http::CodecClient::Type::HTTP2, GetParam()) {}
void SetUp() override {
autonomous_upstream_ = true;
setUpstreamCount(2);
setDownstreamProtocol(Http::CodecClient::Type::HTTP2);
upstream_tls_ = true;
config_helper_.configureUpstreamTls(true);
config_helper_.addConfigModifier([&](envoy::config::bootstrap::v3::Bootstrap& bootstrap) {
auto* static_resources = bootstrap.mutable_static_resources();
auto* cluster = static_resources->mutable_clusters(0);
auto* load_assignment = cluster->mutable_load_assignment();
load_assignment->set_cluster_name(cluster->name());
auto* locality = load_assignment->add_endpoints();
locality->set_priority(0);
locality->mutable_locality()->set_region("region");
locality->add_lb_endpoints()->mutable_endpoint()->MergeFrom(
ConfigHelper::buildEndpoint(Network::Test::getLoopbackAddressString(version_)));
});
}
void createUpstreams() override {
for (uint32_t i = 0; i < fake_upstreams_count_; ++i) {
setUpstreamProtocol(protocols_[i]);
Network::TransportSocketFactoryPtr factory = createUpstreamTlsContext();
auto endpoint = upstream_address_fn_(i);
auto config = upstreamConfig();
config.upstream_protocol_ = protocols_[i];
fake_upstreams_.emplace_back(new AutonomousUpstream(std::move(factory), endpoint, config,
autonomous_allow_incomplete_streams_));
}
}
std::vector<FakeHttpConnection::Type> protocols_;
};
INSTANTIATE_TEST_SUITE_P(IpVersions, AlpnIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);
TEST_P(AlpnIntegrationTest, Http2) {
setUpstreamProtocol(FakeHttpConnection::Type::HTTP2);
protocols_ = {FakeHttpConnection::Type::HTTP2, FakeHttpConnection::Type::HTTP2};
initialize();
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
response->waitForEndStream();
ASSERT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().Status()->value().getStringView());
}
TEST_P(AlpnIntegrationTest, Http1) {
setUpstreamProtocol(FakeHttpConnection::Type::HTTP1);
protocols_ = {FakeHttpConnection::Type::HTTP1, FakeHttpConnection::Type::HTTP1};
initialize();
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
auto response = codec_client_->makeHeaderOnlyRequest(default_request_headers_);
response->waitForEndStream();
ASSERT_TRUE(response->complete());
EXPECT_EQ("200", response->headers().Status()->value().getStringView());
}
TEST_P(AlpnIntegrationTest, Mixed) {
protocols_ = {FakeHttpConnection::Type::HTTP1, FakeHttpConnection::Type::HTTP2};
initialize();
codec_client_ = makeHttpConnection(makeClientConnection((lookupPort("http"))));
// Kick off two simultaneous requests, to ensure two upstream connections are
// created.
auto encoder_decoder1 = codec_client_->startRequest(default_request_headers_);
auto& encoder1 = encoder_decoder1.first;
auto& response1 = encoder_decoder1.second;
auto encoder_decoder2 = codec_client_->startRequest(default_request_headers_);
auto& encoder2 = encoder_decoder2.first;
auto& response2 = encoder_decoder2.second;
// Finish both streams to ensure both responses come through.
Buffer::OwnedImpl data("");
encoder1.encodeData(data, true);
encoder2.encodeData(data, true);
response1->waitForEndStream();
response2->waitForEndStream();
EXPECT_EQ("200", response1->headers().Status()->value().getStringView());
EXPECT_EQ("200", response2->headers().Status()->value().getStringView());
}
} // namespace
} // namespace Envoy