~mna/kick

ffc2e85fd5b48e0f2027b3d820c50260b9dc9d73 — Martin Angers 1 year, 4 months ago 164e80f
start testing cors, fails
1 files changed, 33 insertions(+), 0 deletions(-)

M builder/builder_test.go
M builder/builder_test.go => builder/builder_test.go +33 -0
@@ 331,6 331,12 @@ func TestHandler_Valid(t *testing.T) {
				Method:  "PUT",
				Path:    "/noslash",
				Handler: statusHandler(204),
				Config: &kick.HandlerConfig{
					CORS: &kick.CORSConfig{
						AllowedMethods: []string{"PUT"},
						AllowedOrigins: []string{"example.com"},
					},
				},
			},
			{
				Method:  "GET",


@@ 423,6 429,17 @@ func TestHandler_Valid(t *testing.T) {
					MaxRequestBodyBytes:  maxRequestBody,
				},
			},
			{
				Method:  "GET",
				Path:    "/limited",
				Handler: statusHandler(200),
				Config: &kick.HandlerConfig{
					RequestLimit: &kick.RequestLimitConfig{
						FillInterval: time.Second,
						Capacity:     1,
					},
				},
			},
		},
	}



@@ 589,6 606,22 @@ func TestHandler_Valid(t *testing.T) {
			reqh: "Content-Type:application/json",
			code: 413,
		},
		{
			// first call works
			req:  "GET /limited",
			code: 200,
		},
		{
			// next call is rate-limited
			req:  "GET /limited",
			code: 503,
		},
		{
			req:  "OPTIONS /noslash",
			reqh: "Origin:http://notexample.com Access-Control-Request-Method:PUT",
			code: 204,
			resh: "Access-Control-Allow-Origin:x",
		},
	}
	for _, c := range cases {
		t.Run(fmt.Sprintf("%s %s", c.req, c.reqh), func(t *testing.T) {