Skip to content

Commit

Permalink
Add authentication requires args length check (#1335)
Browse files Browse the repository at this point in the history
* Add authentication requires args length check

* Update authentication.py

Fix linting

* Remove unneeded check

* Fix lifting

* Fix linting

Co-authored-by: Lars Stegman <LSm@allseas.com>
  • Loading branch information
LarsStegman and LarsStegman committed Nov 15, 2021
1 parent 6af5c51 commit 649161c
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions starlette/authentication.py
Expand Up @@ -40,7 +40,9 @@ def decorator(func: typing.Callable) -> typing.Callable:
async def websocket_wrapper(
*args: typing.Any, **kwargs: typing.Any
) -> None:
websocket = kwargs.get("websocket", args[idx] if args else None)
websocket = kwargs.get(
"websocket", args[idx] if idx < len(args) else None
)
assert isinstance(websocket, WebSocket)

if not has_required_scope(websocket, scopes_list):
Expand All @@ -56,7 +58,7 @@ async def websocket_wrapper(
async def async_wrapper(
*args: typing.Any, **kwargs: typing.Any
) -> Response:
request = kwargs.get("request", args[idx] if args else None)
request = kwargs.get("request", args[idx] if idx < len(args) else None)
assert isinstance(request, Request)

if not has_required_scope(request, scopes_list):
Expand All @@ -73,7 +75,7 @@ async def async_wrapper(
# Handle sync request/response functions.
@functools.wraps(func)
def sync_wrapper(*args: typing.Any, **kwargs: typing.Any) -> Response:
request = kwargs.get("request", args[idx] if args else None)
request = kwargs.get("request", args[idx] if idx < len(args) else None)
assert isinstance(request, Request)

if not has_required_scope(request, scopes_list):
Expand Down

0 comments on commit 649161c

Please sign in to comment.