mirror of
https://github.com/esphome/esphome.git
synced 2026-09-22 04:28:43 +00:00
Add explicit binascii.Error catch and bad-padding test
binascii.Error is already a subclass of ValueError, but listing it explicitly makes the intent clear. Added test for incorrect base64 padding (e.g. "Basic abc").
This commit is contained in:
@@ -123,7 +123,7 @@ def is_authenticated(handler: BaseHandler) -> bool:
|
||||
try:
|
||||
auth_decoded = base64.b64decode(auth_header[6:]).decode()
|
||||
username, password = auth_decoded.split(":", 1)
|
||||
except (ValueError, UnicodeDecodeError):
|
||||
except (binascii.Error, ValueError, UnicodeDecodeError):
|
||||
return False
|
||||
return settings.check_password(username, password)
|
||||
return handler.get_secure_cookie(AUTH_COOKIE_NAME) == COOKIE_AUTHENTICATED_YES
|
||||
|
||||
@@ -1707,6 +1707,14 @@ def test_is_authenticated_malformed_base64(
|
||||
assert web_server.is_authenticated(handler) is False
|
||||
|
||||
|
||||
def test_is_authenticated_bad_base64_padding(
|
||||
mock_auth_settings: MagicMock,
|
||||
) -> None:
|
||||
"""Test that incorrect base64 padding (binascii.Error) returns False."""
|
||||
handler = _make_auth_handler("Basic abc")
|
||||
assert web_server.is_authenticated(handler) is False
|
||||
|
||||
|
||||
def test_is_authenticated_invalid_utf8(
|
||||
mock_auth_settings: MagicMock,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user