Skip to content

Commit 65e1d15

Browse files
committed
chore: Add protocol snapshot tests for the mqtt and local e2e tests.
Update the local tests to send the exact same binary format for the initial hello requests. This also adds L01 coverage.
1 parent a8f5d06 commit 65e1d15

File tree

7 files changed

+277
-37
lines changed

7 files changed

+277
-37
lines changed

roborock/protocol.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ def _l01_iv(timestamp: int, nonce: int, sequence: int) -> bytes:
163163
return digest[:12]
164164

165165
@staticmethod
166-
def _l01_aad(timestamp: int, nonce: int, sequence: int, connect_nonce: int, ack_nonce: int) -> bytes:
166+
def _l01_aad(timestamp: int, nonce: int, sequence: int, connect_nonce: int, ack_nonce: int | None = None) -> bytes:
167167
"""Derive AAD for L01 protocol."""
168168
return (
169169
sequence.to_bytes(4, "big")
170170
+ connect_nonce.to_bytes(4, "big")
171-
+ ack_nonce.to_bytes(4, "big")
171+
+ (ack_nonce.to_bytes(4, "big") if ack_nonce is not None else b"")
172172
+ nonce.to_bytes(4, "big")
173173
+ timestamp.to_bytes(4, "big")
174174
)
@@ -181,7 +181,7 @@ def encrypt_gcm_l01(
181181
sequence: int,
182182
nonce: int,
183183
connect_nonce: int,
184-
ack_nonce: int,
184+
ack_nonce: int | None = None,
185185
) -> bytes:
186186
"""Encrypt plaintext for L01 protocol using AES-256-GCM."""
187187
if not isinstance(plaintext, bytes):

tests/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __repr__(self):
6363
for label, data in self.entries:
6464
lines.append(label)
6565
lines.extend(self._hexdump(data))
66-
return "\n".join(lines)
66+
return "\n".join(lines) or "[empty]"
6767

6868
def _hexdump(self, data: bytes, bytes_per_line: int = 16) -> list[str]:
6969
"""Print a hexdump of the given bytes object in a tcpdump/hexdump -C style.
@@ -205,6 +205,7 @@ def push_response(self) -> None:
205205
# Enqueue a response to be sent back to the client in the buffer.
206206
# The buffer will be emptied when the client calls recv() on the socket
207207
_LOGGER.debug("Queued: 0x%s", response.hex())
208+
self.log.add_log_entry("[mqtt <]", response)
208209
self.response_buf.write(response)
209210

210211

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# serializer version: 1
2+
# name: test_connect
3+
[local >]
4+
00000000 00 00 00 15 31 2e 30 00 00 00 01 00 00 23 82 68 |....1.0......#.h|
5+
00000010 a6 a2 24 00 00 e6 b9 24 63 |..$....$c|
6+
[local <]
7+
00000000 00 00 00 27 31 2e 30 00 00 00 01 00 00 00 17 68 |...'1.0........h|
8+
00000010 a6 a2 23 00 01 00 10 cb 93 c7 39 b9 21 53 43 48 |..#.......9.!SCH|
9+
00000020 83 b3 c2 af 0f 51 2c da 9e ea 3b |.....Q,...;|
10+
# ---
11+
# name: test_l01_session
12+
[local >]
13+
00000000 00 00 00 15 31 2e 30 00 00 00 01 00 00 23 82 68 |....1.0......#.h|
14+
00000010 a6 a2 24 00 00 e6 b9 24 63 |..$....$c|
15+
[local <]
16+
00000000 00 |.|
17+
[local >]
18+
00000000 00 00 00 15 4c 30 31 00 00 00 01 00 00 23 82 68 |....L01......#.h|
19+
00000010 a6 a2 25 00 00 ee 2f 30 e8 |..%.../0.|
20+
[local <]
21+
00000000 00 00 00 29 4c 30 31 00 00 00 01 00 00 00 17 68 |...)L01........h|
22+
00000010 a6 a2 23 00 01 00 12 a0 4a ec 75 88 03 75 0f d2 |..#.....J.u..u..|
23+
00000020 40 33 69 02 f4 71 50 72 f3 81 56 80 f4 |@3i..qPr..V..|
24+
[local >]
25+
00000000 00 00 00 3e 4c 30 31 00 00 00 7b 00 00 23 83 68 |...>L01...{..#.h|
26+
00000010 a6 a2 26 00 65 00 27 9e fd c2 42 b7 01 b4 eb 9c |..&.e.'...B.....|
27+
00000020 00 84 4f fd 51 1f bc a5 65 12 c2 dc 45 0e 21 cb |..O.Q...e...E.!.|
28+
00000030 45 dc bb 0a ba 16 84 28 a7 33 e5 e2 fa a8 f1 f2 |E......(.3......|
29+
00000040 ec f4 |..|
30+
[local <]
31+
00000000 00 00 00 37 4c 30 31 00 00 00 7b 00 00 00 17 68 |...7L01...{....h|
32+
00000010 a6 a2 27 00 66 00 20 b7 72 49 8a 64 eb 16 a5 71 |..'.f. .rI.d...q|
33+
00000020 73 eb 9e 7e 37 64 3e 75 c0 70 ea 39 4e de 82 1f |s..~7d>u.p.9N...|
34+
00000030 e2 29 86 de 4a 7b 38 20 55 12 8a |.)..J{8 U..|
35+
# ---
36+
# name: test_send_command
37+
[local >]
38+
00000000 00 00 00 15 31 2e 30 00 00 00 01 00 00 23 82 68 |....1.0......#.h|
39+
00000010 a6 a2 24 00 00 e6 b9 24 63 |..$....$c|
40+
[local <]
41+
00000000 00 00 00 27 31 2e 30 00 00 00 01 00 00 00 17 68 |...'1.0........h|
42+
00000010 a6 a2 23 00 01 00 10 cb 93 c7 39 b9 21 53 43 48 |..#.......9.!SCH|
43+
00000020 83 b3 c2 af 0f 51 2c da 9e ea 3b |.....Q,...;|
44+
[local >]
45+
00000000 00 00 00 37 31 2e 30 00 00 00 7b 00 00 23 83 68 |...71.0...{..#.h|
46+
00000010 a6 a2 25 00 65 00 20 91 5b 1f 43 34 d5 22 47 9f |..%.e. .[.C4."G.|
47+
00000020 59 4e 45 53 85 f9 c6 6e f2 eb 27 eb 6d 03 d8 92 |YNES...n..'.m...|
48+
00000030 5b 30 83 b4 a4 ea f5 85 be 38 57 |[0.......8W|
49+
[local <]
50+
00000000 00 00 00 37 31 2e 30 00 00 00 7b 00 00 00 17 68 |...71.0...{....h|
51+
00000010 a6 a2 26 00 66 00 20 07 8b 28 60 a8 08 18 12 47 |..&.f. ..(`....G|
52+
00000020 05 20 3e f5 53 e3 fd 4a cc 03 72 7b b4 2c d9 84 |. >.S..J..r{.,..|
53+
00000030 7f 4b 18 d8 76 7d 5c 65 87 7c 2d |.K..v}\e.|-|
54+
# ---
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# serializer version: 1
2+
# name: test_session_e2e_publish_message
3+
[mqtt <]
4+
00000000 20 09 02 00 06 22 00 0a 21 00 14 | ...."..!..|
5+
[mqtt >]
6+
00000000 10 21 00 04 4d 51 54 54 05 c2 00 3c 00 00 00 00 |.!..MQTT...<....|
7+
00000010 08 75 73 65 72 6e 61 6d 65 00 08 70 61 73 73 77 |.username..passw|
8+
00000020 6f 72 64 |ord|
9+
[mqtt >]
10+
00000000 30 41 00 07 74 6f 70 69 63 2d 31 00 31 2e 30 00 |0A..topic-1.1.0.|
11+
00000010 00 01 c8 00 00 23 82 68 a6 a2 23 00 65 00 20 91 |.....#.h..#.e. .|
12+
00000020 22 f1 91 1a 6e 89 71 ca ec 2d 44 2a 16 57 e7 5b |"...n.q..-D*.W.[|
13+
00000030 4a 9a c8 97 4b 13 37 3b f5 81 13 45 7c e7 48 03 |J...K.7;...E|.H.|
14+
00000040 99 71 bf |.q.|
15+
# ---
16+
# name: test_session_e2e_receive_message
17+
[mqtt <]
18+
00000000 20 09 02 00 06 22 00 0a 21 00 14 | ...."..!..|
19+
[mqtt >]
20+
00000000 10 21 00 04 4d 51 54 54 05 c2 00 3c 00 00 00 00 |.!..MQTT...<....|
21+
00000010 08 75 73 65 72 6e 61 6d 65 00 08 70 61 73 73 77 |.username..passw|
22+
00000020 6f 72 64 |ord|
23+
[mqtt <]
24+
00000000 90 04 00 01 00 00 |......|
25+
[mqtt >]
26+
00000000 82 0d 00 01 00 00 07 74 6f 70 69 63 2d 31 00 |.......topic-1.|
27+
[mqtt <]
28+
00000000 30 31 00 07 74 6f 70 69 63 2d 31 00 31 2e 30 00 |01..topic-1.1.0.|
29+
00000010 00 00 7b 00 00 23 82 68 a6 a2 23 00 66 00 10 45 |..{..#.h..#.f..E|
30+
00000020 3b c3 2b 12 a6 77 d9 55 f6 e0 89 f5 93 a5 30 5d |;.+..w.U......0]|
31+
00000030 a0 72 fa |.r.|
32+
# ---

0 commit comments

Comments
 (0)