|
16 | 16 | #include "test/mocks/network/mocks.h" |
17 | 17 | #include "test/mocks/server/mocks.h" |
18 | 18 | #include "test/test_common/environment.h" |
| 19 | +#include "test/test_common/test_runtime.h" |
19 | 20 |
|
20 | 21 | #include "gmock/gmock.h" |
21 | 22 | #include "gtest/gtest.h" |
@@ -120,6 +121,29 @@ class WasmFilterConfigTest |
120 | 121 | return std::make_unique<FilterConfig>(proto_config, upstream_factory_context_); |
121 | 122 | } |
122 | 123 |
|
| 124 | + envoy::extensions::filters::http::wasm::v3::Wasm localWasmConfig(const std::string& name) { |
| 125 | + const std::string yaml = |
| 126 | + TestEnvironment::substitute(absl::StrCat(R"EOF( |
| 127 | + config: |
| 128 | + name: ")EOF", |
| 129 | + name, R"EOF(" |
| 130 | + vm_config: |
| 131 | + vm_id: ")EOF", |
| 132 | + name, R"EOF(" |
| 133 | + runtime: "envoy.wasm.runtime.)EOF", |
| 134 | + std::get<0>(GetParam()), R"EOF(" |
| 135 | + configuration: |
| 136 | + "@type": "type.googleapis.com/google.protobuf.StringValue" |
| 137 | + value: "some configuration" |
| 138 | + code: |
| 139 | + local: |
| 140 | + filename: "{{ test_rundir }}/test/extensions/filters/http/wasm/test_data/test_cpp.wasm" |
| 141 | + )EOF")); |
| 142 | + envoy::extensions::filters::http::wasm::v3::Wasm proto_config; |
| 143 | + TestUtility::loadFromYaml(yaml, proto_config); |
| 144 | + return proto_config; |
| 145 | + } |
| 146 | + |
123 | 147 | NiceMock<Network::MockListenerInfo> listener_info_; |
124 | 148 | Stats::IsolatedStoreImpl stats_store_; |
125 | 149 | Stats::Scope& stats_scope_{*stats_store_.rootScope()}; |
@@ -254,6 +278,53 @@ TEST_P(WasmFilterConfigTest, YamlLoadFromFileWasm) { |
254 | 278 | EXPECT_TRUE(api_->customStatNamespaces().registered("wasmcustom")); |
255 | 279 | } |
256 | 280 |
|
| 281 | +TEST_P(WasmFilterConfigTest, UpstreamWasmUsesServerScopeWhenRuntimeGuardEnabled) { |
| 282 | + if (std::get<2>(GetParam())) { |
| 283 | + GTEST_SKIP() << "Only applies to upstream Wasm filters."; |
| 284 | + } |
| 285 | + |
| 286 | + TestScopedRuntime scoped_runtime; |
| 287 | + scoped_runtime.mergeValues( |
| 288 | + {{"envoy.reloadable_features.upstream_wasm_filter_uses_root_scope", "true"}}); |
| 289 | + auto cluster_scope = |
| 290 | + upstream_factory_context_.store_.rootScope()->createScope("cluster.test_cluster."); |
| 291 | + ON_CALL(upstream_factory_context_, scope()).WillByDefault(ReturnRef(*cluster_scope)); |
| 292 | + |
| 293 | + const auto proto_config = localWasmConfig("upstream_wasm_root_scope"); |
| 294 | + EXPECT_CALL(init_watcher_, ready()); |
| 295 | + auto filter_config = getFilterConfig(proto_config); |
| 296 | + initializeContextInitManager(init_watcher_); |
| 297 | + |
| 298 | + const std::string full_stat_name = |
| 299 | + absl::StrCat("wasm.envoy.wasm.runtime.", std::get<0>(GetParam()), ".created"); |
| 300 | + const auto counter = TestUtility::findCounter( |
| 301 | + upstream_factory_context_.server_factory_context_.store_, full_stat_name); |
| 302 | + ASSERT_NE(nullptr, counter); |
| 303 | +} |
| 304 | + |
| 305 | +TEST_P(WasmFilterConfigTest, UpstreamWasmUsesClusterScopeWhenRuntimeGuardDisabled) { |
| 306 | + if (std::get<2>(GetParam())) { |
| 307 | + GTEST_SKIP() << "Only applies to upstream Wasm filters."; |
| 308 | + } |
| 309 | + |
| 310 | + TestScopedRuntime scoped_runtime; |
| 311 | + scoped_runtime.mergeValues( |
| 312 | + {{"envoy.reloadable_features.upstream_wasm_filter_uses_root_scope", "false"}}); |
| 313 | + auto cluster_scope = |
| 314 | + upstream_factory_context_.store_.rootScope()->createScope("cluster.test_cluster."); |
| 315 | + ON_CALL(upstream_factory_context_, scope()).WillByDefault(ReturnRef(*cluster_scope)); |
| 316 | + |
| 317 | + const auto proto_config = localWasmConfig("upstream_wasm_cluster_scope"); |
| 318 | + EXPECT_CALL(init_watcher_, ready()); |
| 319 | + auto filter_config = getFilterConfig(proto_config); |
| 320 | + initializeContextInitManager(init_watcher_); |
| 321 | + |
| 322 | + const std::string full_stat_name = absl::StrCat("cluster.test_cluster.wasm.envoy.wasm.runtime.", |
| 323 | + std::get<0>(GetParam()), ".created"); |
| 324 | + const auto counter = TestUtility::findCounter(upstream_factory_context_.store_, full_stat_name); |
| 325 | + ASSERT_NE(nullptr, counter); |
| 326 | +} |
| 327 | + |
257 | 328 | TEST_P(WasmFilterConfigTest, DEPRECATED_FEATURE_TEST(YamlLoadFromFileWasmFailOpenOk)) { |
258 | 329 | const std::string yaml = TestEnvironment::substitute(absl::StrCat(R"EOF( |
259 | 330 | config: |
|
0 commit comments