Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/extensions/filters/http/admission_control/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Http::FilterFactoryCb AdmissionControlFilterFactory::createFilterFactoryFromProt
const envoy::extensions::filters::http::admission_control::v3alpha::AdmissionControl& config,
const std::string& stats_prefix, Server::Configuration::FactoryContext& context) {

if (config.has_sr_threshold() && config.sr_threshold().default_value().value() == 0) {
throw EnvoyException("Success Rate Threshold cannot be zero percent");
if (config.has_sr_threshold() && config.sr_threshold().default_value().value() < 1.0) {
throw EnvoyException("Success rate threshold cannot be less than 1.0%.");
}

const std::string prefix = stats_prefix + "admission_control.";
Expand Down
31 changes: 29 additions & 2 deletions test/extensions/filters/http/admission_control/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AdmissionControlConfigTest : public testing::Test {

// Ensure the filter ingest throws an exception if it is passed a config with a default value of 0
// for sr_threshold If exception was not thrown, a default value of 0 for sr_threshold induces a
// divide by zero error
// divide by zero error.
TEST_F(AdmissionControlConfigTest, ZeroSuccessRateThreshold) {
AdmissionControlFilterFactory admission_control_filter_factory;
const std::string yaml = R"EOF(
Expand All @@ -75,7 +75,34 @@ sampling_window: 1337s
NiceMock<Server::Configuration::MockFactoryContext> factory_context;
EXPECT_THROW_WITH_MESSAGE(admission_control_filter_factory.createFilterFactoryFromProtoTyped(
proto, "whatever", factory_context),
EnvoyException, "Success Rate Threshold cannot be zero percent");
EnvoyException, "Success rate threshold cannot be less than 1.0%.");
}

TEST_F(AdmissionControlConfigTest, SmallSuccessRateThreshold) {
AdmissionControlFilterFactory admission_control_filter_factory;
const std::string yaml = R"EOF(
enabled:
default_value: false
runtime_key: "foo.enabled"
sampling_window: 1337s
sr_threshold:
default_value:
value: 1.22e-22
runtime_key: "foo.sr_threshold"
aggression:
default_value: 4.2
runtime_key: "foo.aggression"
success_criteria:
http_criteria:
grpc_criteria:
)EOF";

AdmissionControlProto proto;
TestUtility::loadFromYamlAndValidate(yaml, proto);
NiceMock<Server::Configuration::MockFactoryContext> factory_context;
EXPECT_THROW_WITH_MESSAGE(admission_control_filter_factory.createFilterFactoryFromProtoTyped(
proto, "whatever", factory_context),
EnvoyException, "Success rate threshold cannot be less than 1.0%.");
}

// Verify the configuration when all fields are set.
Expand Down
1 change: 1 addition & 0 deletions test/extensions/filters/http/common/fuzz/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ envoy_cc_test_library(
"//test/mocks/http:http_mocks",
"//test/mocks/server:factory_context_mocks",
"//test/proto:bookstore_proto_cc_proto",
"//test/test_common:test_runtime_lib",
"@envoy_api//envoy/extensions/filters/http/grpc_json_transcoder/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/filters/http/jwt_authn/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/filters/http/squash/v3:pkg_cc_proto",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ DEFINE_PROTO_FUZZER(const test::extensions::filters::http::FilterFuzzTestCase& i
try {
// Catch invalid header characters.
TestUtility::validate(input);
ENVOY_LOG_MISC(debug, "Filter configuration: {}", input.config().DebugString());
// Fuzz filter.
static UberFilterFuzzer fuzzer;
fuzzer.fuzz(input.config(), input.data(), input.upstream_data());
Expand Down
3 changes: 3 additions & 0 deletions test/extensions/filters/http/common/fuzz/uber_filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "test/mocks/http/mocks.h"
#include "test/mocks/server/factory_context.h"
#include "test/mocks/stream_info/mocks.h"
#include "test/test_common/test_runtime.h"

namespace Envoy {
namespace Extensions {
Expand Down Expand Up @@ -39,7 +40,9 @@ class UberFilterFuzzer : public HttpFilterFuzzer {
Network::Address::InstanceConstSharedPtr addr_;
NiceMock<Upstream::MockClusterManager> cluster_manager_;
NiceMock<Http::MockAsyncClientRequest> async_request_;
envoy::config::core::v3::Metadata listener_metadata_;
NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info_;
TestScopedRuntime scoped_runtime_;

// Filter constructed from the config.
Http::StreamDecoderFilterSharedPtr decoder_filter_;
Expand Down
4 changes: 4 additions & 0 deletions test/extensions/filters/http/common/fuzz/uber_per_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ void UberFilterFuzzer::perFilterSetup() {
ON_CALL(factory_context_, admin()).WillByDefault(testing::ReturnRef(factory_context_.admin_));
ON_CALL(factory_context_.admin_, addHandler(_, _, _, _, _)).WillByDefault(testing::Return(true));
ON_CALL(factory_context_.admin_, removeHandler(_)).WillByDefault(testing::Return(true));

// Prepare expectations for WASM filter.
ON_CALL(factory_context_, listenerMetadata())
.WillByDefault(testing::ReturnRef(listener_metadata_));
}

} // namespace HttpFilters
Expand Down