forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Greg Greenway <ggreenway@apple.com>
- Loading branch information
Showing
10 changed files
with
326 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "envoy/thread_local/thread_local.h" | ||
#include "source/common/common/matchers.h" | ||
#include "source/extensions/filters/common/lua/lua.h" | ||
|
||
namespace Envoy::Extensions::Matching::String::Lua { | ||
|
||
class LuaStringMatcher : public Matchers::StringMatcher, public ThreadLocal::ThreadLocalObject { | ||
public: | ||
LuaStringMatcher(const std::string& code); | ||
|
||
// ThreadLocal::ThreadLocalObject | ||
~LuaStringMatcher() override = default; | ||
|
||
// Matchers::StringMatcher | ||
bool match(const absl::string_view value) const override; | ||
|
||
private: | ||
CSmartPtr<lua_State, lua_close> state_; | ||
}; | ||
|
||
} // namespace Envoy::Extensions::Matching::String::Lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
load( | ||
"//bazel:envoy_build_system.bzl", | ||
"envoy_package", | ||
) | ||
load( | ||
"//test/extensions:extensions_build_system.bzl", | ||
"envoy_extension_cc_test", | ||
) | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
envoy_package() | ||
|
||
envoy_extension_cc_test( | ||
name = "lua_test", | ||
srcs = ["lua_test.cc"], | ||
extension_names = ["envoy.matching.string.lua"], | ||
deps = [ | ||
"//source/extensions/matching/string/lua:config", | ||
"//test/test_common:logging_lib", | ||
"//test/test_common:utility_lib", | ||
], | ||
) | ||
|
||
envoy_extension_cc_test( | ||
name = "lua_integration_test", | ||
srcs = ["lua_integration_test.cc"], | ||
extension_names = ["envoy.matching.string.lua"], | ||
deps = [ | ||
"//source/extensions/matching/string/lua:config", | ||
"//test/integration:http_integration_lib", | ||
], | ||
) |
83 changes: 83 additions & 0 deletions
83
test/extensions/matching/string/lua/lua_integration_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
#include "source/common/http/utility.h" | ||
#include "source/common/protobuf/protobuf.h" | ||
#include "envoy/extensions/matching/string/lua/v3/lua.pb.h" | ||
|
||
#include "test/integration/http_integration.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace Matching { | ||
namespace String { | ||
namespace Lua { | ||
|
||
class LuaIntegrationTest : public testing::TestWithParam<Network::Address::IpVersion>, | ||
public HttpIntegrationTest { | ||
public: | ||
LuaIntegrationTest() : HttpIntegrationTest(Http::CodecType::HTTP1, GetParam()) { | ||
autonomous_upstream_ = true; | ||
config_helper_.addConfigModifier( | ||
[](envoy::extensions::filters::network::http_connection_manager::v3::HttpConnectionManager& | ||
hcm) { | ||
::envoy::extensions::matching::string::lua::v3::Lua config; | ||
config.set_inline_code( | ||
R"( | ||
function match(str) | ||
return str == "good" or str == "acceptable" | ||
end | ||
)"); | ||
auto* header_match = hcm.mutable_route_config() | ||
->mutable_virtual_hosts(0) | ||
->mutable_routes(0) | ||
->mutable_match() | ||
->add_headers(); | ||
|
||
header_match->set_name("lua-header"); | ||
|
||
auto* string_match_extension = header_match->mutable_string_match()->mutable_extension(); | ||
string_match_extension->set_name("unused but must be set"); | ||
string_match_extension->mutable_typed_config()->PackFrom(config); | ||
}); | ||
HttpIntegrationTest::initialize(); | ||
} | ||
}; | ||
|
||
INSTANTIATE_TEST_SUITE_P(IpVersions, LuaIntegrationTest, | ||
testing::ValuesIn(TestEnvironment::getIpVersionsForTest()), | ||
TestUtility::ipTestParamsToString); | ||
|
||
TEST_P(LuaIntegrationTest, HeaderMatcher) { | ||
Http::TestRequestHeaderMapImpl matching_request_headers{ | ||
{":method", "GET"}, {":path", "/"}, | ||
{":scheme", "http"}, {":authority", "example.com"}, | ||
{"lua-header", "acceptable"}, | ||
}; | ||
codec_client_ = makeHttpConnection(lookupPort("http")); | ||
{ | ||
auto response = codec_client_->makeHeaderOnlyRequest(matching_request_headers); | ||
ASSERT_TRUE(response->waitForEndStream()); | ||
ASSERT_TRUE(response->complete()); | ||
EXPECT_EQ("200", response->headers().Status()->value().getStringView()); | ||
} | ||
|
||
Http::TestRequestHeaderMapImpl non_matching_request_headers{ | ||
{":method", "GET"}, | ||
{":path", "/"}, | ||
{":scheme", "http"}, | ||
{":authority", "example.com"}, | ||
{"lua-header", "unacceptable"}, | ||
}; | ||
{ | ||
auto response = codec_client_->makeHeaderOnlyRequest(non_matching_request_headers); | ||
ASSERT_TRUE(response->waitForEndStream()); | ||
ASSERT_TRUE(response->complete()); | ||
EXPECT_EQ("404", response->headers().Status()->value().getStringView()); | ||
} | ||
} | ||
|
||
} // namespace Lua | ||
} // namespace String | ||
} // namespace Matching | ||
} // namespace Extensions | ||
} // namespace Envoy |
Oops, something went wrong.