From b57f3a32ccdd9ee32c074f0afa52af526bcc08c7 Mon Sep 17 00:00:00 2001 From: Patrick Taibel Date: Mon, 11 Apr 2022 15:07:34 +0200 Subject: [PATCH] Add test for global request body size limit --- gateway/proxy_muxer_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gateway/proxy_muxer_test.go b/gateway/proxy_muxer_test.go index c60cb4494dee..ab6a1407e078 100644 --- a/gateway/proxy_muxer_test.go +++ b/gateway/proxy_muxer_test.go @@ -9,6 +9,7 @@ import ( "net/http/httptest" "reflect" "strconv" + "strings" "sync/atomic" "testing" @@ -310,3 +311,19 @@ func TestHandle404(t *testing.T) { {Path: "/nonexisting", Code: http.StatusNotFound, BodyMatch: http.StatusText(http.StatusNotFound)}, }...) } + +func TestRequestBodyLimit(t *testing.T) { + ts := StartTest(func(globalConf *config.Config) { + globalConf.HttpServerOptions.MaxRequestBodySize = 1024 + }) + defer ts.Close() + + ts.Gw.BuildAndLoadAPI(func(spec *APISpec) { + spec.UseKeylessAccess = true + }) + + _, _ = ts.Run(t, []test.TestCase{ + {Path: "/sample/", Method: "POST", Data: strings.Repeat("a", 1024), Code: http.StatusOK}, + {Path: "/sample/", Method: "POST", Data: strings.Repeat("a", 1025), Code: http.StatusRequestEntityTooLarge}, + }...) +}