Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
seshubaws authored Jan 29, 2024
2 parents af6932a + a7c2a75 commit fbdcfd1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
## Maintenance

* **deps:** bump squidfunk/mkdocs-material from `58eef6c` to `9aad7af` in /docs ([#3670](https://github.com/aws-powertools/powertools-lambda-python/issues/3670))
* **deps:** bump codecov/codecov-action from 3.1.4 to 3.1.5 ([#3674](https://github.com/aws-powertools/powertools-lambda-python/issues/3674))
* **deps:** bump pydantic from 1.10.13 to 1.10.14 ([#3655](https://github.com/aws-powertools/powertools-lambda-python/issues/3655))
* **deps:** bump codecov/codecov-action from 3.1.4 to 3.1.5 ([#3674](https://github.com/aws-powertools/powertools-lambda-python/issues/3674))
* **deps:** bump the layer-balancer group in /layer/scripts/layer-balancer with 1 update ([#3665](https://github.com/aws-powertools/powertools-lambda-python/issues/3665))
* **deps-dev:** bump aws-cdk from 2.122.0 to 2.123.0 ([#3673](https://github.com/aws-powertools/powertools-lambda-python/issues/3673))
* **deps-dev:** bump ruff from 0.1.13 to 0.1.14 ([#3656](https://github.com/aws-powertools/powertools-lambda-python/issues/3656))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def _get_body(self, app: EventHandlerInstance) -> Dict[str, Any]:
"""

content_type_value = app.current_event.get_header_value("content-type")
if not content_type_value or content_type_value.startswith("application/json"):
if not content_type_value or content_type_value.strip().startswith("application/json"):
try:
return app.current_event.json_body
except json.JSONDecodeError as e:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,32 @@ def handler(user: Model) -> Model:
assert json.loads(result["body"]) == {"name": "John", "age": 30}


def test_validate_body_param_with_stripped_headers():
# GIVEN an APIGatewayRestResolver with validation enabled
app = APIGatewayRestResolver(enable_validation=True)

class Model(BaseModel):
name: str
age: int

# WHEN a handler is defined with a body parameter
# WHEN headers has spaces
@app.post("/")
def handler(user: Model) -> Model:
return user

LOAD_GW_EVENT["httpMethod"] = "POST"
LOAD_GW_EVENT["headers"] = {"Content-type": " application/json "}
LOAD_GW_EVENT["path"] = "/"
LOAD_GW_EVENT["body"] = json.dumps({"name": "John", "age": 30})

# THEN the handler should be invoked and return 200
# THEN the body must be a JSON object
result = app(LOAD_GW_EVENT, {})
assert result["statusCode"] == 200
assert json.loads(result["body"]) == {"name": "John", "age": 30}


def test_validate_body_param_with_invalid_date():
# GIVEN an APIGatewayRestResolver with validation enabled
app = APIGatewayRestResolver(enable_validation=True)
Expand Down

0 comments on commit fbdcfd1

Please sign in to comment.