Skip to content

Commit

Permalink
Upgrade to build against the latest Envoy (#10)
Browse files Browse the repository at this point in the history
* Upgrade to build against the latest Envoy

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>

* Upgrade to the latest Envoy with fixes from v1.12.2

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>

* get rid of old-style casts in assertions

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>

* tests: fix unused-private-field and old-style-cast errors

Signed-off-by: Dmitry Rozhkov <dmitry.rozhkov@linux.intel.com>
  • Loading branch information
rojkov authored and venilnoronha committed Dec 18, 2019
1 parent daf0a77 commit 4ce9b71
Show file tree
Hide file tree
Showing 27 changed files with 253 additions and 150 deletions.
2 changes: 1 addition & 1 deletion envoy
Submodule envoy updated 1509 files
2 changes: 1 addition & 1 deletion envoy_build_config/extensions_build_config.bzl
Expand Up @@ -105,7 +105,7 @@ EXTENSIONS = {
# SSL
#

"envoy.extensions.common.crypto.utility_lib": "@envoy_openssl//source/extensions/common/crypto:utility_lib",
"envoy.common.crypto.utility_lib": "@envoy_openssl//source/extensions/common/crypto:utility_lib",

#
# Stat sinks
Expand Down
6 changes: 4 additions & 2 deletions source/extensions/filters/http/lua/BUILD
Expand Up @@ -5,6 +5,7 @@ licenses(["notice"]) # Apache 2

load(
"@envoy//bazel:envoy_build_system.bzl",
"envoy_cc_extension",
"envoy_cc_library",
"envoy_package",
)
Expand Down Expand Up @@ -47,16 +48,17 @@ envoy_cc_library(
],
)

envoy_cc_library(
envoy_cc_extension(
name = "config",
repository = "@envoy",
srcs = ["config.cc"],
hdrs = ["config.h"],
security_posture = "robust_to_untrusted_downstream",
deps = [
":lua_filter_lib",
"@envoy//include/envoy/registry",
"@envoy//source/common/config:filter_json_lib",
"@envoy//source/extensions/filters/http:well_known_names",
"@envoy//source/extensions/filters/http/common:factory_base_lib",
"@envoy_api//envoy/config/filter/http/lua/v2:pkg_cc_proto",
],
)
11 changes: 0 additions & 11 deletions source/extensions/filters/http/lua/config.cc
Expand Up @@ -3,8 +3,6 @@
#include "envoy/config/filter/http/lua/v2/lua.pb.validate.h"
#include "envoy/registry/registry.h"

#include "common/config/filter_json.h"

#include "extensions/filters/http/lua/lua_filter.h"

namespace Envoy {
Expand All @@ -22,15 +20,6 @@ Http::FilterFactoryCb LuaFilterConfig::createFilterFactoryFromProtoTyped(
};
}

Http::FilterFactoryCb
LuaFilterConfig::createFilterFactory(const Json::Object& json_config,
const std::string& stat_prefix,
Server::Configuration::FactoryContext& context) {
envoy::config::filter::http::lua::v2::Lua proto_config;
Config::FilterJson::translateLuaFilter(json_config, proto_config);
return createFilterFactoryFromProtoTyped(proto_config, stat_prefix, context);
}

/**
* Static registration for the Lua filter. @see RegisterFactory.
*/
Expand Down
4 changes: 0 additions & 4 deletions source/extensions/filters/http/lua/config.h
Expand Up @@ -18,10 +18,6 @@ class LuaFilterConfig : public Common::FactoryBase<envoy::config::filter::http::
public:
LuaFilterConfig() : FactoryBase(HttpFilterNames::get().Lua) {}

Http::FilterFactoryCb
createFilterFactory(const Json::Object& json_config, const std::string& stats_prefix,
Server::Configuration::FactoryContext& context) override;

private:
Http::FilterFactoryCb
createFilterFactoryFromProtoTyped(const envoy::config::filter::http::lua::v2::Lua& proto_config,
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/filters/http/lua/lua_filter.cc
Expand Up @@ -127,7 +127,7 @@ int StreamHandleWrapper::luaRespond(lua_State* state) {
Buffer::InstancePtr body;
if (raw_body != nullptr) {
body = std::make_unique<Buffer::OwnedImpl>(raw_body, body_size);
headers->insertContentLength().value(body_size);
headers->setContentLength(body_size);
}

// Once we respond we treat that as the end of the script even if there is more code. Thus we
Expand Down Expand Up @@ -193,7 +193,7 @@ int StreamHandleWrapper::luaHttpCall(lua_State* state) {

if (body != nullptr) {
message->body() = std::make_unique<Buffer::OwnedImpl>(body, body_size);
message->headers().insertContentLength().value(body_size);
message->headers().setContentLength(body_size);
}

absl::optional<std::chrono::milliseconds> timeout;
Expand Down
1 change: 0 additions & 1 deletion source/extensions/filters/http/lua/lua_filter.h
Expand Up @@ -5,7 +5,6 @@

#include "common/crypto/utility.h"

#include "extensions/common/crypto/crypto_impl.h"
#include "extensions/filters/common/lua/wrappers.h"
#include "extensions/filters/http/lua/wrappers.h"
#include "extensions/filters/http/well_known_names.h"
Expand Down
7 changes: 1 addition & 6 deletions source/extensions/filters/http/lua/wrappers.cc
Expand Up @@ -79,12 +79,7 @@ int HeaderMapWrapper::luaReplace(lua_State* state) {
const char* value = luaL_checkstring(state, 3);
const Http::LowerCaseString lower_key(key);

Http::HeaderEntry* entry = headers_.get(lower_key);
if (entry != nullptr) {
entry->value(value, strlen(value));
} else {
headers_.addCopy(lower_key, value);
}
headers_.setCopy(lower_key, value);

return 0;
}
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/grpc_credentials/aws_iam/config.cc
Expand Up @@ -119,9 +119,9 @@ AwsIamHeaderAuthenticator::buildMessageToSign(absl::string_view service_url,
Http::Utility::extractHostPathFromUri(uri, host, path);

Http::RequestMessageImpl message;
message.headers().insertMethod().value().setReference(Http::Headers::get().MethodValues.Post);
message.headers().insertHost().value(host);
message.headers().insertPath().value(path);
message.headers().setReferenceMethod(Http::Headers::get().MethodValues.Post);
message.headers().setHost(host);
message.headers().setPath(path);

return message;
}
Expand Down
4 changes: 3 additions & 1 deletion source/extensions/transport_sockets/tls/config.cc
Expand Up @@ -53,7 +53,9 @@ Ssl::ContextManagerPtr SslContextManagerFactory::createContextManager(TimeSource
return std::make_unique<ContextManagerImpl>(time_source);
}

REGISTER_FACTORY(SslContextManagerFactory, Ssl::ContextManagerFactory);
static Envoy::Registry::RegisterInternalFactory<SslContextManagerFactory,
Ssl::ContextManagerFactory>
ssl_manager_registered;

} // namespace Tls
} // namespace TransportSockets
Expand Down
6 changes: 3 additions & 3 deletions source/extensions/transport_sockets/tls/context_impl.cc
Expand Up @@ -98,7 +98,7 @@ ContextImpl::ContextImpl(Stats::Scope& scope, const Envoy::Ssl::ContextConfig& c
}
throw EnvoyException(fmt::format("Failed to initialize cipher suites {}. The following "
"ciphers were rejected when tried individually: {}",
config.cipherSuites(), StringUtil::join(bad_ciphers, ", ")));
config.cipherSuites(), absl::StrJoin(bad_ciphers, ", ")));
}

if (!SSL_CTX_set1_curves_list(ctx.ssl_ctx_.get(), config.ecdhCurves().c_str())) {
Expand Down Expand Up @@ -1046,7 +1046,7 @@ int ServerContextImpl::sessionTicketProcess(SSL*, uint8_t* key_name, uint8_t* iv

// This RELEASE_ASSERT is logically a static_assert, but we can't actually get
// EVP_CIPHER_key_length(cipher) at compile-time
RELEASE_ASSERT(key.aes_key_.size() == (unsigned) EVP_CIPHER_key_length(cipher), "");
RELEASE_ASSERT(key.aes_key_.size() == static_cast<unsigned>(EVP_CIPHER_key_length(cipher)), "");
if (!EVP_EncryptInit_ex(ctx, cipher, nullptr, key.aes_key_.data(), iv)) {
return -1;
}
Expand All @@ -1067,7 +1067,7 @@ int ServerContextImpl::sessionTicketProcess(SSL*, uint8_t* key_name, uint8_t* iv
return -1;
}

RELEASE_ASSERT(key.aes_key_.size() == (unsigned) EVP_CIPHER_key_length(cipher), "");
RELEASE_ASSERT(key.aes_key_.size() == static_cast<unsigned>(EVP_CIPHER_key_length(cipher)), "");
if (!EVP_DecryptInit_ex(ctx, cipher, nullptr, key.aes_key_.data(), iv)) {
return -1;
}
Expand Down
7 changes: 4 additions & 3 deletions test/common/grpc/grpc_client_integration_test_harness.h
Expand Up @@ -148,10 +148,11 @@ class HelloworldStream : public MockAsyncStreamCallbacks<helloworld::HelloReply>
}

void expectGrpcStatus(Status::GrpcStatus grpc_status) {
if (grpc_status == Status::GrpcStatus::InvalidCode) {
if (grpc_status == Status::WellKnownGrpcStatus::InvalidCode) {
EXPECT_CALL(*this, onRemoteClose(_, _)).WillExitIfNeeded();
} else if (grpc_status > Status::GrpcStatus::MaximumValid) {
EXPECT_CALL(*this, onRemoteClose(Status::GrpcStatus::InvalidCode, _)).WillExitIfNeeded();
} else if (grpc_status > Status::WellKnownGrpcStatus::MaximumKnown) {
EXPECT_CALL(*this, onRemoteClose(Status::WellKnownGrpcStatus::InvalidCode, _))
.WillExitIfNeeded();
} else {
EXPECT_CALL(*this, onRemoteClose(grpc_status, _)).WillExitIfNeeded();
}
Expand Down
4 changes: 2 additions & 2 deletions test/extensions/filters/http/common/aws/signer_impl_test.cc
Expand Up @@ -30,9 +30,9 @@ class SignerImplTest : public testing::Test {
time_system_.setSystemTime(std::chrono::milliseconds(1514862245000));
}

void addMethod(const std::string& method) { message_->headers().insertMethod().value(method); }
void addMethod(const std::string& method) { message_->headers().setMethod(method); }

void addPath(const std::string& path) { message_->headers().insertPath().value(path); }
void addPath(const std::string& path) { message_->headers().setPath(path); }

void addHeader(const std::string& key, const std::string& value) {
message_->headers().addCopy(Http::LowerCaseString(key), value);
Expand Down
14 changes: 8 additions & 6 deletions test/extensions/filters/http/lua/config_test.cc
@@ -1,8 +1,11 @@
#include <string>

#include "envoy/config/filter/http/lua/v2/lua.pb.validate.h"

#include "extensions/filters/http/lua/config.h"

#include "test/mocks/server/mocks.h"
#include "test/test_common/utility.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"
Expand All @@ -23,16 +26,15 @@ TEST(LuaFilterConfigTest, ValidateFail) {
}

TEST(LuaFilterConfigTest, LuaFilterInJson) {
std::string json_string = R"EOF(
{
"inline_code" : "print(5)"
}
const std::string yaml_string = R"EOF(
inline_code : "print(5)"
)EOF";

Json::ObjectSharedPtr json_config = Json::Factory::loadFromString(json_string);
envoy::config::filter::http::lua::v2::Lua proto_config;
TestUtility::loadFromYaml(yaml_string, proto_config);
NiceMock<Server::Configuration::MockFactoryContext> context;
LuaFilterConfig factory;
Http::FilterFactoryCb cb = factory.createFilterFactory(*json_config, "stats", context);
Http::FilterFactoryCb cb = factory.createFilterFactoryFromProto(proto_config, "stats", context);
Http::MockFilterChainFactoryCallbacks filter_callback;
EXPECT_CALL(filter_callback, addStreamFilter(_));
cb(filter_callback);
Expand Down
Expand Up @@ -101,7 +101,7 @@ BENCHMARK(BM_TlsInspector)->Unit(benchmark::kMicrosecond);
int main(int argc, char** argv) {
Envoy::Thread::MutexBasicLockable lock;
Envoy::Logger::Context logging_context(spdlog::level::warn,
Envoy::Logger::Logger::DEFAULT_LOG_FORMAT, lock);
Envoy::Logger::Logger::DEFAULT_LOG_FORMAT, lock, false);

benchmark::Initialize(&argc, argv);
if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
Expand Down

0 comments on commit 4ce9b71

Please sign in to comment.