From 86b3f5ecbcbd1c0dc1d7f25db6ef1cfb313c12b4 Mon Sep 17 00:00:00 2001 From: Garrett Beatty Date: Mon, 9 Dec 2024 15:44:30 -0500 Subject: [PATCH] add cookie value encoding --- .../src/Amazon.Lambda.TestTool/HttpContextExtensions.cs | 2 +- .../HttpContextExtensionsTests.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/HttpContextExtensions.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/HttpContextExtensions.cs index 93b86fc05..07a7629af 100644 --- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/HttpContextExtensions.cs +++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/HttpContextExtensions.cs @@ -44,7 +44,7 @@ public static APIGatewayHttpApiV2ProxyRequest ToApiGatewayHttpV2Request( RouteKey = $"{request.Method} {matchedConfig.Path}", RawPath = request.Path, RawQueryString = request.QueryString.Value, - Cookies = request.Cookies.Select(c => $"{c.Key}={c.Value}").ToArray(), + Cookies = request.Cookies.Select(c => $"{c.Key}={HttpUtility.UrlEncode(c.Value)}").ToArray(), Headers = headers, QueryStringParameters = queryStringParameters, PathParameters = pathParameters ?? new Dictionary(), diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/HttpContextExtensionsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/HttpContextExtensionsTests.cs index 83302cdeb..20fcdb0d6 100644 --- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/HttpContextExtensionsTests.cs +++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/HttpContextExtensionsTests.cs @@ -52,7 +52,7 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR request.QueryString = new QueryString("?status=pending"); request.Headers["User-Agent"] = "TestAgent"; request.Headers["Accept"] = "application/json"; - request.Headers["Cookie"] = "session=abc123; theme=dark"; + request.Headers["Cookie"] = "session=abc123; theme=dark; complex=this+has+spaces;"; var result = context.ToApiGatewayHttpV2Request(); @@ -61,9 +61,10 @@ public void ToApiGatewayHttpV2Request_ShouldReturnValidApiGatewayHttpApiV2ProxyR Assert.Equal("GET /api/users/{userId}/orders", result.RouteKey); Assert.Equal("/api/users/123/orders", result.RawPath); Assert.Equal("?status=pending", result.RawQueryString); - Assert.Equal(2, result.Cookies.Length); + Assert.Equal(3, result.Cookies.Length); Assert.Contains("session=abc123", result.Cookies); Assert.Contains("theme=dark", result.Cookies); + Assert.Contains("complex=this%2bhas%2bspaces", result.Cookies); Assert.Equal("123", result.PathParameters["userId"]); Assert.Equal("GET", result.RequestContext.Http.Method); Assert.Equal("/api/users/123/orders", result.RequestContext.Http.Path);