-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Additional validation and filter config cleanup for Backend Routing (#…
…175) Config Manager changes: - For empty prefix in APPEND: Don't generate rules, they are no-op. - For empty prefix in CONST: Generate rules with path prefix '/'. - For URL parser: Don't parse query params. None of the control plane config should allow query params anyways. Filter changes: - More validation of proto config (as described above) and tests for this. - Tests to show duplicated query param behavior. Signed-off-by: Teju Nareddy <[email protected]>
- Loading branch information
Showing
13 changed files
with
312 additions
and
74 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v2 | ||
v3 |
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,105 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "src/envoy/http/backend_routing/filter_config.h" | ||
|
||
#include "api/envoy/http/backend_routing/config.pb.validate.h" | ||
#include "common/common/empty_string.h" | ||
#include "gmock/gmock.h" | ||
#include "google/protobuf/text_format.h" | ||
#include "gtest/gtest.h" | ||
#include "test/mocks/server/mocks.h" | ||
#include "test/test_common/utility.h" | ||
|
||
using ::testing::_; | ||
using ::testing::Invoke; | ||
using ::testing::Return; | ||
|
||
namespace espv2 { | ||
namespace envoy { | ||
namespace http_filters { | ||
namespace backend_routing { | ||
namespace { | ||
|
||
class BackendRoutingConfigTest : public ::testing::Test { | ||
protected: | ||
void validateConfig(absl::string_view filter_config) { | ||
google::api::envoy::http::backend_routing::FilterConfig proto_config; | ||
ASSERT_TRUE(google::protobuf::TextFormat::ParseFromString( | ||
std::string(filter_config), &proto_config)); | ||
ASSERT_GT(proto_config.rules_size(), 0); | ||
|
||
Envoy::TestUtility::validate(proto_config); | ||
} | ||
}; | ||
|
||
TEST_F(BackendRoutingConfigTest, AppendAddressNoPrefixThrows) { | ||
ASSERT_THROW(validateConfig(R"( | ||
rules { | ||
operation: "append-with-noop-prefix-operation" | ||
path_translation: APPEND_PATH_TO_ADDRESS | ||
path_prefix: "" | ||
} | ||
)"), | ||
Envoy::ProtoValidationException); | ||
} | ||
|
||
TEST_F(BackendRoutingConfigTest, ConstAddressNoPrefixThrows) { | ||
ASSERT_THROW(validateConfig(R"( | ||
rules { | ||
operation: "const-with-invalid-prefix-operation" | ||
path_translation: CONSTANT_ADDRESS | ||
path_prefix: "" | ||
} | ||
)"), | ||
Envoy::ProtoValidationException); | ||
} | ||
|
||
TEST_F(BackendRoutingConfigTest, ConstAddressRootPrefixWorks) { | ||
ASSERT_NO_THROW(validateConfig(R"( | ||
rules { | ||
operation: "const-with-root-prefix-operation" | ||
path_translation: CONSTANT_ADDRESS | ||
path_prefix: "/" | ||
} | ||
)")); | ||
} | ||
|
||
TEST_F(BackendRoutingConfigTest, PathTranslationUnspecifiedThrows) { | ||
ASSERT_THROW(validateConfig(R"( | ||
rules { | ||
operation: "invalid-path-translation-operation" | ||
path_prefix: "/test" | ||
} | ||
)"), | ||
Envoy::ProtoValidationException); | ||
} | ||
|
||
TEST_F(BackendRoutingConfigTest, InvalidPathCharactersThrows) { | ||
ASSERT_THROW(validateConfig(R"( | ||
rules { | ||
operation: "invalid-path-prefix-operation" | ||
path_translation: APPEND_PATH_TO_ADDRESS | ||
path_prefix: "/test\r\n/invalid" | ||
} | ||
)"), | ||
Envoy::ProtoValidationException); | ||
} | ||
|
||
} // namespace | ||
|
||
} // namespace backend_routing | ||
} // namespace http_filters | ||
} // namespace envoy | ||
} // namespace espv2 |
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
Oops, something went wrong.