Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 3 additions & 1 deletion bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,8 @@ def envoy_cc_test(
args = [],
shard_count = None,
coverage = True,
local = False):
local = False,
size = "medium"):
test_lib_tags = []
if coverage:
test_lib_tags.append("coverage_test_lib")
Expand Down Expand Up @@ -472,6 +473,7 @@ def envoy_cc_test(
tags = tags + ["coverage_test"],
local = local,
shard_count = shard_count,
size = size,
)

# Envoy C++ related test infrastructure (that want gtest, gmock, but may be
Expand Down
11 changes: 11 additions & 0 deletions test/config/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ const std::string ConfigHelper::BASE_CONFIG = R"EOF(
port_value: 0
)EOF";

const std::string ConfigHelper::REDIS_PROXY_CONFIG = BASE_CONFIG + R"EOF(
Comment thread
msukalski marked this conversation as resolved.
Outdated
filter_chains:
filters:
name: envoy.redis_proxy
config:
stat_prefix: redis_stats
cluster: cluster_0
settings:
op_timeout: 5s
)EOF";

const std::string ConfigHelper::TCP_PROXY_CONFIG = BASE_CONFIG + R"EOF(
filter_chains:
filters:
Expand Down
2 changes: 2 additions & 0 deletions test/config/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class ConfigHelper {
// A basic configuration (admin port, cluster_0, one listener) with no network filters.
static const std::string BASE_CONFIG;

// A basic configuration for redis server proxying.
static const std::string REDIS_PROXY_CONFIG;
// A basic configuration for L4 proxying.
static const std::string TCP_PROXY_CONFIG;
// A basic configuration for L7 proxying.
Expand Down
13 changes: 13 additions & 0 deletions test/integration/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,19 @@ envoy_cc_test(
],
)

envoy_cc_test(
name = "redis_proxy_integration_test",
size = "small",
srcs = [
"redis_proxy_integration_test.cc",
"redis_proxy_integration_test.h",
],
deps = [
":integration_lib",
"//source/extensions/filters/network/redis_proxy:config",
],
)

envoy_cc_test(
name = "tcp_proxy_integration_test",
srcs = [
Expand Down
83 changes: 83 additions & 0 deletions test/integration/redis_proxy_integration_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#include "test/integration/redis_proxy_integration_test.h"

#include <sstream>
Comment thread
msukalski marked this conversation as resolved.
#include <vector>

#include "extensions/filters/network/redis_proxy/command_splitter_impl.h"

namespace RedisCommon = Envoy::Extensions::NetworkFilters::Common::Redis;
namespace RedisCmdSplitter = Envoy::Extensions::NetworkFilters::RedisProxy::CommandSplitter;

namespace Envoy {
namespace {

std::string makeBulkStringArray(std::vector<std::string>&& command_strings) {
std::stringstream result;

result << "*" << command_strings.size() << "\r\n";
for (uint64_t i = 0; i < command_strings.size(); i++) {
result << "$" << command_strings[i].size() << "\r\n";
result << command_strings[i] << "\r\n";
}

return result.str();
}

INSTANTIATE_TEST_SUITE_P(IpVersions, RedisProxyIntegrationTest,
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()),
TestUtility::ipTestParamsToString);

void RedisProxyIntegrationTest::initialize() {
config_helper_.renameListener("redis_proxy");
BaseIntegrationTest::initialize();
}

TEST_P(RedisProxyIntegrationTest, SimpleRequestAndResponse) {
Comment thread
msukalski marked this conversation as resolved.
Outdated
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("redis_proxy"));

std::string client_to_proxy = makeBulkStringArray({"get", "foo"});
std::string proxy_to_server;

ASSERT_TRUE(client_to_proxy.size() > 0);
Comment thread
msukalski marked this conversation as resolved.
Outdated
ASSERT_TRUE(client_to_proxy.find("get") != std::string::npos);
ASSERT_TRUE(client_to_proxy.find("foo") != std::string::npos);
tcp_client->write(client_to_proxy);

FakeRawConnectionPtr fake_upstream_connection;
ASSERT_TRUE(fake_upstreams_[0]->waitForRawConnection(fake_upstream_connection));
ASSERT_TRUE(fake_upstream_connection->waitForData(client_to_proxy.size(), &proxy_to_server));
ASSERT_EQ(client_to_proxy, proxy_to_server);

std::string server_to_proxy = "$3\r\nbar\r\n"; // bulkstring reply of "bar"

ASSERT_TRUE(fake_upstream_connection->write(server_to_proxy));
tcp_client->waitForData(server_to_proxy);
ASSERT_EQ(server_to_proxy, tcp_client->data());

tcp_client->close();
ASSERT_TRUE(fake_upstream_connection->close());
}

TEST_P(RedisProxyIntegrationTest, InvalidRequest) {
initialize();
IntegrationTcpClientPtr tcp_client = makeTcpConnection(lookupPort("redis_proxy"));

std::string client_to_proxy = makeBulkStringArray({"foo"});

ASSERT_TRUE(client_to_proxy.size() > 0);
ASSERT_TRUE(client_to_proxy.find("foo") != std::string::npos);
tcp_client->write(client_to_proxy);

std::stringstream error_response;
error_response << "-" << RedisCmdSplitter::Response::get().InvalidRequest << "\r\n";
std::string proxy_to_client = error_response.str();

tcp_client->waitForData(proxy_to_client);
ASSERT_EQ(proxy_to_client, tcp_client->data());

tcp_client->close();
}

} // namespace
} // namespace Envoy
23 changes: 23 additions & 0 deletions test/integration/redis_proxy_integration_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include "test/integration/integration.h"

#include "gtest/gtest.h"

namespace Envoy {
namespace {
class RedisProxyIntegrationTest : public testing::TestWithParam<Network::Address::IpVersion>,
Comment thread
msukalski marked this conversation as resolved.
Outdated
public BaseIntegrationTest {
public:
RedisProxyIntegrationTest() : BaseIntegrationTest(GetParam(), ConfigHelper::REDIS_PROXY_CONFIG) {}

~RedisProxyIntegrationTest() override {
test_server_.reset();
fake_upstreams_.clear();
}

void initialize() override;
};

} // namespace
} // namespace Envoy