Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions ci/build_setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ fi
cp -f "${ENVOY_SRCDIR}"/ci/WORKSPACE.filter.example "${ENVOY_FILTER_EXAMPLE_SRCDIR}"/WORKSPACE

# This is the hash on https://github.com/lyft/envoy-filter-example.git we pin to.
# TODO(hennna): Point to updated hash.
(cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git checkout 9f006f6be519007e9be3b29ad531b8e8be5a18d6)
(cd "${ENVOY_FILTER_EXAMPLE_SRCDIR}" && git fetch origin && git checkout 03f5353c939b0d796925c67d94db52e8055ee732)

# Also setup some space for building Envoy standalone.
export ENVOY_BUILD_DIR="${BUILD_DIR}"/envoy
Expand Down
7 changes: 6 additions & 1 deletion source/common/network/address_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ int Ipv6Instance::connect(int fd) const {
}

int Ipv6Instance::socket(SocketType type) const {
return ::socket(AF_INET6, flagsFromSocketType(type), 0);
const int fd = ::socket(AF_INET6, flagsFromSocketType(type), 0);
RELEASE_ASSERT(fd != -1);
// Setting IPV6_V6ONLY resticts the IPv6 socket to IPv6 connections only.
const int v6only = 1;
RELEASE_ASSERT(::setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, sizeof(v6only)) != -1);
return fd;
}

PipeInstance::PipeInstance(const sockaddr_un* address) : InstanceBase(Type::Pipe) {
Expand Down
6 changes: 1 addition & 5 deletions source/common/network/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,8 @@ const std::string Utility::TCP_SCHEME = "tcp://";
const std::string Utility::UNIX_SCHEME = "unix://";

Address::InstanceConstSharedPtr Utility::resolveUrl(const std::string& url) {
// TODO(mattklein123): IPv6 support.
// TODO(mattklein123): We still support the legacy tcp:// and unix:// names. We should
// support/parse ip:// and pipe:// as better names.
if (url.find(TCP_SCHEME) == 0) {
return Address::InstanceConstSharedPtr{
new Address::Ipv4Instance(hostFromTcpUrl(url), portFromTcpUrl(url))};
return Address::parseInternetAddressAndPort(url.substr(TCP_SCHEME.size()));
} else if (url.find(UNIX_SCHEME) == 0) {
return Address::InstanceConstSharedPtr{
new Address::PipeInstance(url.substr(UNIX_SCHEME.size()))};
Expand Down
8 changes: 8 additions & 0 deletions test/common/network/address_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ void testSocketBindAndConnect(const std::string& addr_port_str) {
ASSERT_GE(listen_fd, 0) << addr_port->asString();
ScopedFdCloser closer1(listen_fd);

// Check that IPv6 sockets accept IPv6 connections only.
if (addr_port->ip()->ipv6() != nullptr) {
int v6only = 0;
socklen_t size_int = sizeof(v6only);
ASSERT_GE(::getsockopt(listen_fd, IPPROTO_IPV6, IPV6_V6ONLY, &v6only, &size_int), 0);
EXPECT_EQ(v6only, 1);
}

// Bind the socket to the desired address and port.
int rc = addr_port->bind(listen_fd);
int err = errno;
Expand Down
20 changes: 20 additions & 0 deletions test/common/network/utility_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,27 @@ TEST(NetworkUtility, Url) {
EXPECT_THROW(Utility::portFromTcpUrl("tcp://foo"), EnvoyException);
EXPECT_THROW(Utility::portFromTcpUrl("tcp://foo:bar"), EnvoyException);
EXPECT_THROW(Utility::hostFromTcpUrl(""), EnvoyException);
}

TEST(NetworkUtility, resolveUrl) {
EXPECT_THROW(Utility::resolveUrl("foo"), EnvoyException);
EXPECT_THROW(Utility::resolveUrl("abc://foo"), EnvoyException);
EXPECT_EQ("", Utility::resolveUrl("unix://")->asString());
EXPECT_EQ("foo", Utility::resolveUrl("unix://foo")->asString());
EXPECT_EQ("tmp", Utility::resolveUrl("unix://tmp")->asString());
EXPECT_EQ("tmp/server", Utility::resolveUrl("unix://tmp/server")->asString());
EXPECT_EQ(nullptr, Utility::resolveUrl("tcp://192.168.3.3"));
EXPECT_EQ(nullptr, Utility::resolveUrl("tcp://192.168.3.3.3:0"));
EXPECT_EQ(nullptr, Utility::resolveUrl("tcp://192.168.3:0"));
EXPECT_EQ(nullptr, Utility::resolveUrl("tcp://[::1]"));
EXPECT_EQ(nullptr, Utility::resolveUrl("tcp://[:::1]:1"));
EXPECT_EQ(nullptr, Utility::resolveUrl("tcp://foo:0"));
EXPECT_EQ("1.2.3.4:1234", Utility::resolveUrl("tcp://1.2.3.4:1234")->asString());
EXPECT_EQ("0.0.0.0:0", Utility::resolveUrl("tcp://0.0.0.0:0")->asString());
EXPECT_EQ("[::1]:1", Utility::resolveUrl("tcp://[::1]:1")->asString());
EXPECT_EQ("[1::2:3]:4", Utility::resolveUrl("tcp://[1::2:3]:4")->asString());
EXPECT_EQ("[a::1]:0", Utility::resolveUrl("tcp://[a::1]:0")->asString());
EXPECT_EQ("[a:b:c:d::]:0", Utility::resolveUrl("tcp://[a:b:c:d::]:0")->asString());
}

TEST(NetworkUtility, getLocalAddress) { EXPECT_NE(nullptr, Utility::getLocalAddress()); }
Expand Down
2 changes: 1 addition & 1 deletion test/config/integration/server.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"listeners": [
{
"address": "tcp://127.0.0.1:0",
"address": "tcp://{{ ip_loopback_address }}:0",
"use_original_dst": true,
"filters": [
{ "type": "read", "name": "ratelimit",
Expand Down
1 change: 1 addition & 0 deletions test/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ envoy_cc_test_library(
"//source/server/http:health_check_lib",
"//test/mocks/upstream:upstream_mocks",
"//test/test_common:environment_lib",
"//test/test_common:network_utility_lib",
"//test/test_common:utility_lib",
],
)
Expand Down
8 changes: 5 additions & 3 deletions test/integration/hotrestart_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ set -e

[[ -z "${ENVOY_BIN}" ]] && ENVOY_BIN="${TEST_RUNDIR}"/source/exe/envoy-static

# TODO(htuch): Clean this up when Bazelifying the hot restart test below. At the same time, restore
# some test behavior lost in #650, when we switched to 0 port binding - the hot restart tests no
# longer check socket passing. See #654.
# TODO(htuch): In this test script, we are duplicating work done in test_environment.cc via sed.
# Instead, we can add a simple C++ binary that links against test_environment.cc and uses the
# substitution methods provided there.
# TODO(henna): Parameterize IPv4 and IPv6 testing.
HOT_RESTART_JSON="${TEST_TMPDIR}"/hot_restart.json
cat "${TEST_RUNDIR}"/test/config/integration/server.json |
sed -e "s#{{ upstream_. }}#0#g" | \
sed -e "s#{{ test_rundir }}#$TEST_RUNDIR#" | \
sed -e "s#{{ ip_loopback_address }}#127.0.0.1#" | \
cat > "${HOT_RESTART_JSON}"

# Now start the real server, hot restart it twice, and shut it all down as a basic hot restart
Expand Down
4 changes: 2 additions & 2 deletions test/integration/http2_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Http2IntegrationTest : public BaseIntegrationTest, public testing::Test {
/**
* Global initializer for all integration tests.
*/
static void SetUpTestCase() {
void SetUp() override {
fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1));
registerPort("upstream_0", fake_upstreams_.back()->localAddress()->ip()->port());
fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP1));
Expand All @@ -20,7 +20,7 @@ class Http2IntegrationTest : public BaseIntegrationTest, public testing::Test {
/**
* Global destructor for all integration tests.
*/
static void TearDownTestCase() {
void TearDown() override {
test_server_.reset();
fake_upstreams_.clear();
}
Expand Down
4 changes: 2 additions & 2 deletions test/integration/http2_upstream_integration_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Http2UpstreamIntegrationTest : public BaseIntegrationTest, public testing:
/**
* Global initializer for all integration tests.
*/
static void SetUpTestCase() {
void SetUp() override {
fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2));
registerPort("upstream_0", fake_upstreams_.back()->localAddress()->ip()->port());
fake_upstreams_.emplace_back(new FakeUpstream(0, FakeHttpConnection::Type::HTTP2));
Expand All @@ -21,7 +21,7 @@ class Http2UpstreamIntegrationTest : public BaseIntegrationTest, public testing:
/**
* Global destructor for all integration tests.
*/
static void TearDownTestCase() {
void TearDown() override {
test_server_.reset();
fake_upstreams_.clear();
}
Expand Down
18 changes: 11 additions & 7 deletions test/integration/integration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
#include "gtest/gtest.h"
#include "spdlog/spdlog.h"

IntegrationTestServerPtr BaseIntegrationTest::test_server_;
std::vector<std::unique_ptr<FakeUpstream>> BaseIntegrationTest::fake_upstreams_;

IntegrationStreamDecoder::IntegrationStreamDecoder(Event::Dispatcher& dispatcher)
: dispatcher_(dispatcher) {}

Expand Down Expand Up @@ -261,12 +258,12 @@ IntegrationTcpClientPtr BaseIntegrationTest::makeTcpConnection(uint32_t port) {
}

void BaseIntegrationTest::registerPort(const std::string& key, uint32_t port) {
port_map()[key] = port;
port_map_[key] = port;
}

uint32_t BaseIntegrationTest::lookupPort(const std::string& key) {
auto it = port_map().find(key);
if (it != port_map().end()) {
auto it = port_map_.find(key);
if (it != port_map_.end()) {
return it->second;
}
RELEASE_ASSERT(false);
Expand All @@ -283,12 +280,19 @@ void BaseIntegrationTest::registerTestServerPorts(const std::vector<std::string>
}

void BaseIntegrationTest::createTestServer(const std::string& json_path,
const Network::Address::IpVersion version,
const std::vector<std::string>& port_names) {
test_server_ = IntegrationTestServer::create(
TestEnvironment::temporaryFileSubstitute(json_path, port_map()));
TestEnvironment::temporaryFileSubstitute(json_path, version, port_map_));
registerTestServerPorts(port_names);
}

// TODO(hennna): Deprecate when IPv6 test support is finished.
void BaseIntegrationTest::createTestServer(const std::string& json_path,
const std::vector<std::string>& port_names) {
BaseIntegrationTest::createTestServer(json_path, Network::Address::IpVersion::v4, port_names);
}

void BaseIntegrationTest::testRouterRequestAndResponseWithBody(Network::ClientConnectionPtr&& conn,
Http::CodecClient::Type type,
uint64_t request_size,
Expand Down
24 changes: 10 additions & 14 deletions test/integration/integration.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,14 @@ class BaseIntegrationTest : Logger::Loggable<Logger::Id::testing> {
IntegrationTcpClientPtr makeTcpConnection(uint32_t port);

// Test-wide port map.
static void registerPort(const std::string& key, uint32_t port);
static uint32_t lookupPort(const std::string& key);
static std::string substitutePorts(const std::string& json_path);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function doesn't seem to be used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, please clean up any dead code.

void registerPort(const std::string& key, uint32_t port);
uint32_t lookupPort(const std::string& key);

static void registerTestServerPorts(const std::vector<std::string>& port_names);
static void createTestServer(const std::string& json_path,
const std::vector<std::string>& port_names);

static IntegrationTestServerPtr test_server_;
static std::vector<std::unique_ptr<FakeUpstream>> fake_upstreams_;
void registerTestServerPorts(const std::vector<std::string>& port_names);
// TODO(hennna): Deprecate when IPv6 test support is finished.
void createTestServer(const std::string& json_path, const std::vector<std::string>& port_names);
void createTestServer(const std::string& json_path, const Network::Address::IpVersion version,
const std::vector<std::string>& port_names);

Api::ApiPtr api_;
Event::DispatcherPtr dispatcher_;
Expand Down Expand Up @@ -212,10 +210,8 @@ class BaseIntegrationTest : Logger::Loggable<Logger::Id::testing> {
void testDownstreamResetBeforeResponseComplete();
void testTrailers(uint64_t request_size, uint64_t response_size);

static TestEnvironment::PortMap& port_map() {
static auto* port_map = new TestEnvironment::PortMap();
return *port_map;
}

std::vector<std::unique_ptr<FakeUpstream>> fake_upstreams_;
spdlog::level::level_enum default_log_level_;
IntegrationTestServerPtr test_server_;
TestEnvironment::PortMap port_map_;
};
12 changes: 8 additions & 4 deletions test/integration/integration_admin_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

#include "test/integration/integration_test.h"
#include "test/integration/utility.h"
#include "test/test_common/environment.h"

#include "gtest/gtest.h"
#include "spdlog/spdlog.h"

TEST_F(IntegrationTest, HealthCheck) {
INSTANTIATE_TEST_CASE_P(AdminIntegrationTestIpVersions, IntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()));

TEST_P(IntegrationTest, HealthCheck) {
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("http"), "GET", "/healthcheck", "", Http::CodecClient::Type::HTTP1);
EXPECT_TRUE(response->complete());
Expand Down Expand Up @@ -40,7 +44,7 @@ TEST_F(IntegrationTest, HealthCheck) {
EXPECT_STREQ("200", response->headers().Status()->value().c_str());
}

TEST_F(IntegrationTest, AdminLogging) {
TEST_P(IntegrationTest, AdminLogging) {
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("admin"), "GET", "/logging", "", Http::CodecClient::Type::HTTP1);
EXPECT_TRUE(response->complete());
Expand Down Expand Up @@ -84,7 +88,7 @@ TEST_F(IntegrationTest, AdminLogging) {
}
}

TEST_F(IntegrationTest, Admin) {
TEST_P(IntegrationTest, Admin) {
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("admin"), "GET", "/", "", Http::CodecClient::Type::HTTP1);
EXPECT_TRUE(response->complete());
Expand Down Expand Up @@ -141,7 +145,7 @@ TEST_F(IntegrationTest, Admin) {
// Successful call to startProfiler requires tcmalloc.
#ifdef TCMALLOC

TEST_F(IntegrationTest, AdminCpuProfilerStart) {
TEST_P(IntegrationTest, AdminCpuProfilerStart) {
BufferingStreamDecoderPtr response = IntegrationUtil::makeSingleRequest(
lookupPort("admin"), "GET", "/cpuprofiler?enable=y", "", Http::CodecClient::Type::HTTP1);
EXPECT_TRUE(response->complete());
Expand Down
Loading