Skip to content

Commit

Permalink
wasm: update proxy-wasm to apply canary always (envoyproxy#22469)
Browse files Browse the repository at this point in the history
Signed-off-by: Ingwon Song <[email protected]>
  • Loading branch information
ingwonsong authored Aug 2, 2022
1 parent 1647d36 commit 5c6c8c1
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 23 deletions.
6 changes: 3 additions & 3 deletions bazel/repository_locations.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -1119,8 +1119,8 @@ REPOSITORY_LOCATIONS_SPEC = dict(
project_name = "WebAssembly for Proxies (C++ host implementation)",
project_desc = "WebAssembly for Proxies (C++ host implementation)",
project_url = "https://github.com/proxy-wasm/proxy-wasm-cpp-host",
version = "2cf68d6c00b4141ecf2afb5e5d51ebd21a27ed43",
sha256 = "6314d3e36e8aa9c4e792772b66f773fcfd58affcd4fd437c6d3dc540165e7fc6",
version = "4ddbed3c8c8c1aa76db8157e22ae3be676e76ac1",
sha256 = "e9c05ed5e827e256f4725735c2ed3d5420fc95f5bce052b42f93aa37248a1f42",
strip_prefix = "proxy-wasm-cpp-host-{version}",
urls = ["https://github.com/proxy-wasm/proxy-wasm-cpp-host/archive/{version}.tar.gz"],
use_category = ["dataplane_ext"],
Expand All @@ -1136,7 +1136,7 @@ REPOSITORY_LOCATIONS_SPEC = dict(
"envoy.wasm.runtime.wavm",
"envoy.wasm.runtime.wasmtime",
],
release_date = "2022-07-13",
release_date = "2022-07-30",
cpe = "N/A",
),
proxy_wasm_rust_sdk = dict(
Expand Down
7 changes: 3 additions & 4 deletions source/extensions/filters/http/wasm/wasm_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class FilterConfig : Logger::Loggable<Logger::Id::wasm> {
}
if (!wasm || wasm->isFailed()) {
if (handle->plugin()->fail_open_) {
// Fail open skips adding this filter to callbacks.
return nullptr;
return nullptr; // Fail open skips adding this filter to callbacks.
} else {
// Fail closed is handled by an empty Context.
return std::make_shared<Context>(nullptr, 0, handle);
return std::make_shared<Context>(nullptr, 0,
handle); // Fail closed is handled by an empty Context.
}
}
return std::make_shared<Context>(wasm, handle->rootContextId(), handle);
Expand Down
7 changes: 3 additions & 4 deletions source/extensions/filters/network/wasm/wasm_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,10 @@ class FilterConfig : Logger::Loggable<Logger::Id::wasm> {
}
if (!wasm || wasm->isFailed()) {
if (handle->plugin()->fail_open_) {
// Fail open skips adding this filter to callbacks.
return nullptr;
return nullptr; // Fail open skips adding this filter to callbacks.
} else {
// Fail closed is handled by an empty Context.
return std::make_shared<Context>(nullptr, 0, handle);
return std::make_shared<Context>(nullptr, 0,
handle); // Fail closed is handled by an empty Context.
}
}
return std::make_shared<Context>(wasm, handle->rootContextId(), handle);
Expand Down
50 changes: 46 additions & 4 deletions test/extensions/access_loggers/wasm/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ TEST_P(WasmAccessLogConfigTest, YamlLoadFromFileWasmInvalidConfig) {
StreamInfo::MockStreamInfo log_stream_info;
filter_instance = factory->createAccessLogInstance(proto_config, nullptr, context_);
filter_instance->log(nullptr, nullptr, nullptr, log_stream_info);

TestUtility::loadFromYaml(invalid_yaml, proto_config);
filter_instance = factory->createAccessLogInstance(proto_config, nullptr, context_);
filter_instance->log(nullptr, nullptr, nullptr, log_stream_info);
}

TEST_P(WasmAccessLogConfigTest, YamlLoadFromRemoteWasmCreateFilter) {
Expand Down Expand Up @@ -238,6 +234,52 @@ TEST_P(WasmAccessLogConfigTest, YamlLoadFromRemoteWasmCreateFilter) {
filter_instance->log(nullptr, nullptr, nullptr, log_stream_info);
}

TEST_P(WasmAccessLogConfigTest, FailedToGetThreadLocalPlugin) {
if (std::get<0>(GetParam()) == "null") {
return;
}
auto factory =
Registry::FactoryRegistry<Server::Configuration::AccessLogInstanceFactory>::getFactory(
"envoy.access_loggers.wasm");
ASSERT_NE(factory, nullptr);

NiceMock<Envoy::ThreadLocal::MockInstance> threadlocal;
const std::string yaml = TestEnvironment::substitute(absl::StrCat(R"EOF(
config:
vm_config:
runtime: "envoy.wasm.runtime.)EOF",
std::get<0>(GetParam()), R"EOF("
configuration:
"@type": "type.googleapis.com/google.protobuf.StringValue"
value: "some configuration"
code:
local:
filename: "{{ test_rundir }}/test/extensions/access_loggers/wasm/test_data/test_cpp.wasm"
configuration:
"@type": "type.googleapis.com/google.protobuf.StringValue"
value: "valid"
)EOF"));

envoy::extensions::access_loggers::wasm::v3::WasmAccessLog proto_config;
TestUtility::loadFromYaml(yaml, proto_config);
EXPECT_CALL(context_, threadLocal()).WillOnce(ReturnRef(threadlocal));
threadlocal.registered_ = true;
AccessLog::InstanceSharedPtr filter_instance =
factory->createAccessLogInstance(proto_config, nullptr, context_);
ASSERT_EQ(threadlocal.current_slot_, 1);

Http::TestRequestHeaderMapImpl request_header;
Http::TestResponseHeaderMapImpl response_header;
Http::TestResponseTrailerMapImpl response_trailer;
StreamInfo::MockStreamInfo log_stream_info;

filter_instance->log(&request_header, &response_header, &response_trailer, log_stream_info);
// Even if the thread local plugin handle returns nullptr, `log` should not raise error or
// exception.
threadlocal.data_[0] = std::make_shared<PluginHandleSharedPtrThreadLocal>(nullptr);
filter_instance->log(&request_header, &response_header, &response_trailer, log_stream_info);
}

} // namespace Wasm
} // namespace AccessLoggers
} // namespace Extensions
Expand Down
33 changes: 29 additions & 4 deletions test/extensions/filters/http/wasm/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromFileWasmInvalidConfig) {
EXPECT_CALL(filter_callback, addStreamFilter(_));
EXPECT_CALL(filter_callback, addAccessLogHandler(_));
cb(filter_callback);

TestUtility::loadFromYaml(invalid_yaml, proto_config);
auto filter_config = std::make_unique<FilterConfig>(proto_config, context_);
EXPECT_EQ(filter_config->createFilter(), nullptr);
}

TEST_P(WasmFilterConfigTest, YamlLoadInlineWasm) {
Expand Down Expand Up @@ -954,6 +950,35 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromRemoteWasmCreateFilter) {
EXPECT_NE(filter_config->createFilter(), nullptr);
}

TEST_P(WasmFilterConfigTest, FailedToGetThreadLocalPlugin) {
NiceMock<Envoy::ThreadLocal::MockInstance> threadlocal;
const std::string yaml = TestEnvironment::substitute(absl::StrCat(R"EOF(
config:
fail_open: true
vm_config:
runtime: "envoy.wasm.runtime.)EOF",
std::get<0>(GetParam()), R"EOF("
configuration:
"@type": "type.googleapis.com/google.protobuf.StringValue"
value: "some configuration"
code:
local:
filename: "{{ test_rundir }}/test/extensions/filters/http/wasm/test_data/test_cpp.wasm"
)EOF"));

envoy::extensions::filters::http::wasm::v3::Wasm proto_config;
TestUtility::loadFromYaml(yaml, proto_config);
EXPECT_CALL(context_, threadLocal()).WillOnce(ReturnRef(threadlocal));
threadlocal.registered_ = true;
auto filter_config = std::make_unique<FilterConfig>(proto_config, context_);
ASSERT_EQ(threadlocal.current_slot_, 1);
ASSERT_NE(filter_config->createFilter(), nullptr);

// If the thread local plugin handle returns nullptr, `createFilter` should return nullptr
threadlocal.data_[0] = std::make_shared<PluginHandleSharedPtrThreadLocal>(nullptr);
EXPECT_EQ(filter_config->createFilter(), nullptr);
}

} // namespace Wasm
} // namespace HttpFilters
} // namespace Extensions
Expand Down
39 changes: 35 additions & 4 deletions test/extensions/filters/network/wasm/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ TEST_P(WasmNetworkFilterConfigTest, YamlLoadFromFileWasmInvalidConfig) {
Network::MockConnection connection;
EXPECT_CALL(connection, addFilter(_));
cb(connection);

TestUtility::loadFromYaml(invalid_yaml, proto_config);
auto filter_config = std::make_unique<FilterConfig>(proto_config, context_);
EXPECT_EQ(filter_config->createFilter(), nullptr);
}

TEST_P(WasmNetworkFilterConfigTest, YamlLoadFromRemoteWasmCreateFilter) {
Expand Down Expand Up @@ -415,6 +411,41 @@ TEST_P(WasmNetworkFilterConfigTest, YamlLoadFromRemoteWasmCreateFilter) {
EXPECT_NE(filter_config->createFilter(), nullptr);
}

TEST_P(WasmNetworkFilterConfigTest, FailedToGetThreadLocalPlugin) {
if (std::get<0>(GetParam()) == "null") {
return;
}

NiceMock<Envoy::ThreadLocal::MockInstance> threadlocal;
const std::string yaml = TestEnvironment::substitute(absl::StrCat(R"EOF(
config:
vm_config:
runtime: "envoy.wasm.runtime.)EOF",
std::get<0>(GetParam()), R"EOF("
configuration:
"@type": "type.googleapis.com/google.protobuf.StringValue"
value: "some configuration"
code:
local:
filename: "{{ test_rundir }}/test/extensions/filters/network/wasm/test_data/test_cpp.wasm"
configuration:
"@type": "type.googleapis.com/google.protobuf.StringValue"
value: "valid"
)EOF"));

envoy::extensions::filters::network::wasm::v3::Wasm proto_config;
TestUtility::loadFromYaml(yaml, proto_config);
EXPECT_CALL(context_, threadLocal()).WillOnce(ReturnRef(threadlocal));
threadlocal.registered_ = true;
auto filter_config = std::make_unique<FilterConfig>(proto_config, context_);
ASSERT_EQ(threadlocal.current_slot_, 1);
ASSERT_NE(filter_config->createFilter(), nullptr);

// If the thread local plugin handle returns nullptr, `createFilter` should return nullptr
threadlocal.data_[0] = std::make_shared<PluginHandleSharedPtrThreadLocal>(nullptr);
EXPECT_EQ(filter_config->createFilter(), nullptr);
}

} // namespace Wasm
} // namespace NetworkFilters
} // namespace Extensions
Expand Down

0 comments on commit 5c6c8c1

Please sign in to comment.