|
5 | 5 |
|
6 | 6 |
|
7 | 7 | def get_mock_aws_alb_event( |
8 | | - method, path, multi_value_query_parameters, body, body_base64_encoded |
| 8 | + method, |
| 9 | + path, |
| 10 | + multi_value_query_parameters, |
| 11 | + body, |
| 12 | + body_base64_encoded, |
| 13 | + multi_value_headers=True, |
9 | 14 | ): |
10 | | - return { |
| 15 | + event = { |
11 | 16 | "requestContext": { |
12 | 17 | "elb": { |
13 | 18 | "targetGroupArn": "arn:aws:elasticloadbalancing:us-east-2:123456789012:targetgroup/lambda-279XGJDqGZ5rsrHC2Fjr/49e9d65c45c6791a" # noqa: E501 |
@@ -38,6 +43,10 @@ def get_mock_aws_alb_event( |
38 | 43 | "body": body, |
39 | 44 | "isBase64Encoded": body_base64_encoded, |
40 | 45 | } |
| 46 | + if multi_value_headers: |
| 47 | + event["multiValueHeaders"] = {} |
| 48 | + |
| 49 | + return event |
41 | 50 |
|
42 | 51 |
|
43 | 52 | def test_aws_alb_basic(): |
@@ -226,7 +235,7 @@ def test_aws_alb_scope_real( |
226 | 235 | assert handler.body == b"" |
227 | 236 |
|
228 | 237 |
|
229 | | -def test_aws_alb_set_cookies() -> None: |
| 238 | +def test_aws_alb_set_cookies_multiValueHeaders() -> None: |
230 | 239 | async def app(scope, receive, send): |
231 | 240 | await send( |
232 | 241 | { |
@@ -255,6 +264,39 @@ async def app(scope, receive, send): |
255 | 264 | } |
256 | 265 |
|
257 | 266 |
|
| 267 | +def test_aws_alb_set_cookies_headers() -> None: |
| 268 | + async def app(scope, receive, send): |
| 269 | + await send( |
| 270 | + { |
| 271 | + "type": "http.response.start", |
| 272 | + "status": 200, |
| 273 | + "headers": [ |
| 274 | + [b"content-type", b"text/plain; charset=utf-8"], |
| 275 | + [b"set-cookie", b"cookie1=cookie1; Secure"], |
| 276 | + [b"set-cookie", b"cookie2=cookie2; Secure"], |
| 277 | + ], |
| 278 | + } |
| 279 | + ) |
| 280 | + await send({"type": "http.response.body", "body": b"Hello, world!"}) |
| 281 | + |
| 282 | + handler = Mangum(app, lifespan="off") |
| 283 | + event = get_mock_aws_alb_event( |
| 284 | + "GET", "/test", {}, None, False, multi_value_headers=False |
| 285 | + ) |
| 286 | + response = handler(event, {}) |
| 287 | + assert response == { |
| 288 | + "statusCode": 200, |
| 289 | + "isBase64Encoded": False, |
| 290 | + "headers": { |
| 291 | + "content-type": "text/plain; charset=utf-8", |
| 292 | + "set-cookie": "cookie1=cookie1; Secure", |
| 293 | + "Set-cookie": "cookie2=cookie2; Secure", |
| 294 | + }, |
| 295 | + "multiValueHeaders": {}, |
| 296 | + "body": "Hello, world!", |
| 297 | + } |
| 298 | + |
| 299 | + |
258 | 300 | @pytest.mark.parametrize( |
259 | 301 | "method,content_type,raw_res_body,res_body,res_base64_encoded", |
260 | 302 | [ |
|
0 commit comments