Reduce AuthenticationExceptions raising from transports (#740)

* Reduce AuthenticationExceptions raising from transports

* Make auth failed test ids easier to read

* Test invalid klap response length
This commit is contained in:
Steven B
2024-02-05 20:49:26 +00:00
committed by GitHub
parent 215b8d4e4f
commit 6ab17d823c
3 changed files with 70 additions and 16 deletions

View File

@@ -159,7 +159,7 @@ class KlapTransport(BaseTransport):
)
if response_status != 200:
raise AuthenticationException(
raise SmartDeviceException(
f"Device {self._host} responded with {response_status} to handshake1"
)
@@ -167,6 +167,12 @@ class KlapTransport(BaseTransport):
remote_seed: bytes = response_data[0:16]
server_hash = response_data[16:]
if len(server_hash) != 32:
raise SmartDeviceException(
f"Device {self._host} responded with unexpected klap response "
+ f"{response_data!r} to handshake1"
)
if _LOGGER.isEnabledFor(logging.DEBUG):
_LOGGER.debug(
"Handshake1 success at %s. Host is %s, "
@@ -260,7 +266,9 @@ class KlapTransport(BaseTransport):
)
if response_status != 200:
raise AuthenticationException(
# This shouldn't be caused by incorrect
# credentials so don't raise AuthenticationException
raise SmartDeviceException(
f"Device {self._host} responded with {response_status} to handshake2"
)