From ac6b5fbc5588af38894edb72a171ed0a5ee836dd Mon Sep 17 00:00:00 2001 From: guscarreon Date: Thu, 25 Apr 2024 16:28:18 -0400 Subject: [PATCH] Alex's review --- config/config_test.go | 12 ++++++++++++ server/server.go | 15 ++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/config/config_test.go b/config/config_test.go index 6ac4e579..c9f35632 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -867,6 +867,18 @@ func TestRequestLimitsValidateAndLog(t *testing.T) { }, expectFatal: true, }, + { + description: "Negative max_num_values, expect fatal level log and early exit", + inRequestLimitsCfg: &RequestLimits{MaxHeaderSize: -1}, + expectedLogInfo: []logComponents{ + {msg: `config.request_limits.allow_setting_keys: false`, lvl: logrus.InfoLevel}, + {msg: `config.request_limits.max_ttl_seconds: 0`, lvl: logrus.InfoLevel}, + {msg: `config.request_limits.max_size_bytes: 0`, lvl: logrus.InfoLevel}, + {msg: `config.request_limits.max_num_values: 0`, lvl: logrus.InfoLevel}, + {msg: `invalid config.request_limits.max_header_size_bytes: -1. Value cannot be negative.`, lvl: logrus.FatalLevel}, + }, + expectFatal: true, + }, } //substitute logger exit function so execution doesn't get interrupted diff --git a/server/server.go b/server/server.go index 9da84909..c847d510 100644 --- a/server/server.go +++ b/server/server.go @@ -74,10 +74,10 @@ func Listen(cfg config.Configuration, publicHandler http.Handler, adminHandler h return } -// newAdminServer returns an http.Server with the configured with the AdminPort and -// RequestLimits.MaxHeaderBytes values specified in Prebid Cache's config files or -// environment variables. If RequestLimits.MaxHeaderBytes is zero or non-specified, -// the http library sets server.MaxHeaderBytes to the value of http.DefaultMaxHeaderBytes +// newAdminServer returns an http.Server with the AdminPort and RequestLimits.MaxHeaderBytes +// from Prebid Cache's config files or environment variables. If RequestLimits.MaxHeaderBytes +// is zero or was not specified the the http library's DefaultMaxHeaderBytes value of 1 MB +// is set instead. func newAdminServer(cfg config.Configuration, handler http.Handler) *http.Server { server := &http.Server{ Addr: ":" + strconv.Itoa(cfg.AdminPort), @@ -89,10 +89,11 @@ func newAdminServer(cfg config.Configuration, handler http.Handler) *http.Server return server } -// newMainServer returns an http.Server with the configured with the Port and +// newMainServer returns an http.Server with the configured Port and // RequestLimits.MaxHeaderBytes values specified in Prebid Cache's config files -// or environment variables. If RequestLimits.MaxHeaderBytes is zero or non-specified, -// 1 MB, which is the value of the http library's DefaultMaxHeaderBytes, is set instead. +// or environment variables. If RequestLimits.MaxHeaderBytes is zero or was not +// specified, 1 MB, which is the value of the http library's DefaultMaxHeaderBytes, +// is set instead. func newMainServer(cfg config.Configuration, handler http.Handler) *http.Server { server := &http.Server{ Addr: ":" + strconv.Itoa(cfg.Port),