Skip to content

Commit 5e60096

Browse files
committed
code cleanup
1 parent 7efb55b commit 5e60096

File tree

4 files changed

+247
-30
lines changed

4 files changed

+247
-30
lines changed

net_proto/tests/unit/protocols/arp/test__arp__assembler__operation.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@
7575
"tha=MacAddress('0a:0b:0c:0d:0e:0f'), tpa=Ip4Address('101.102.103.104')))"
7676
),
7777
"__bytes__": (
78+
# ARP (Ethernet/IPv4)
79+
# Hardware type : 1 (Ethernet)
80+
# Protocol type : 0x0800 (IPv4)
81+
# HLEN / PLEN : 6 / 4
82+
# Operation : 1 (Request)
83+
# Sender MAC : 01:02:03:04:05:06
84+
# Sender IP : 11.22.33.44
85+
# Target MAC : 0a:0b:0c:0d:0e:0f
86+
# Target IP : 101.102.103.104
87+
#
88+
# Summary : Unicast ARP request — "Who has 101.102.103.104? Tell 11.22.33.44."
7889
b"\x00\x01\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
7990
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
8091
),
@@ -116,6 +127,17 @@
116127
"tha=MacAddress('7a:7b:7c:7d:7e:7f'), tpa=Ip4Address('7.7.7.7')))"
117128
),
118129
"__bytes__": (
130+
# ARP (Ethernet/IPv4)
131+
# Hardware type : 1 (Ethernet)
132+
# Protocol type : 0x0800 (IPv4)
133+
# HLEN / PLEN : 6 / 4
134+
# Operation : 2 (Reply)
135+
# Sender MAC : a1:b2:c3:d4:e5:f6
136+
# Sender IP : 5.5.5.5
137+
# Target MAC : 7a:7b:7c:7d:7e:7f
138+
# Target IP : 7.7.7.7
139+
#
140+
# Summary : Unicast ARP reply — "5.5.5.5 is at a1:b2:c3:d4:e5:f6."
119141
b"\x00\x01\x08\x00\x06\x04\x00\x02\xa1\xb2\xc3\xd4\xe5\xf6\x05\x05"
120142
b"\x05\x05\x7a\x7b\x7c\x7d\x7e\x7f\x07\x07\x07\x07"
121143
),

net_proto/tests/unit/protocols/arp/test__arp__parser__integrity_checks.py

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,21 @@
4646
{
4747
"_description": ("The frame length is less than the value of the 'ARP__HEADER__LEN' constant."),
4848
"_args": [
49-
b"\x00\x01\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
50-
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67",
49+
(
50+
# ARP (Ethernet/IPv4)
51+
# Hardware type : 1 (Ethernet)
52+
# Protocol type : 0x0800 (IPv4)
53+
# HLEN / PLEN : 6 / 4
54+
# Operation : 1 (Request)
55+
# Sender MAC : 01:02:03:04:05:06
56+
# Sender IP : 11.22.33.44
57+
# Target MAC : 0a:0b:0c:0d:0e:0f
58+
# Target IP : 101.102.103 (truncated; missing one octet)
59+
#
60+
# Summary : Header cut short at 27 bytes (< 28-byte minimum).
61+
b"\x00\x01\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
62+
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67"
63+
),
5164
],
5265
"_kwargs": {},
5366
"_results": {
@@ -59,8 +72,21 @@
5972
{
6073
"_description": "The value of the 'hrtype' field is incorrect.",
6174
"_args": [
62-
b"\x00\x00\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
63-
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68",
75+
(
76+
# ARP (Ethernet/IPv4)
77+
# Hardware type : 0 (unknown)
78+
# Protocol type : 0x0800 (IPv4)
79+
# HLEN / PLEN : 6 / 4
80+
# Operation : 1 (Request)
81+
# Sender MAC : 01:02:03:04:05:06
82+
# Sender IP : 11.22.33.44
83+
# Target MAC : 0a:0b:0c:0d:0e:0f
84+
# Target IP : 101.102.103.104
85+
#
86+
# Summary : Invalid hardware type triggers integrity error.
87+
b"\x00\x00\x08\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
88+
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
89+
),
6490
],
6591
"_kwargs": {},
6692
"_results": {
@@ -73,8 +99,21 @@
7399
{
74100
"_description": "The value of the 'prtype' field is incorrect.",
75101
"_args": [
76-
b"\x00\x01\x00\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
77-
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68",
102+
(
103+
# ARP (Ethernet/IPv4)
104+
# Hardware type : 1 (Ethernet)
105+
# Protocol type : 0x0000 (unknown)
106+
# HLEN / PLEN : 6 / 4
107+
# Operation : 1 (Request)
108+
# Sender MAC : 01:02:03:04:05:06
109+
# Sender IP : 11.22.33.44
110+
# Target MAC : 0a:0b:0c:0d:0e:0f
111+
# Target IP : 101.102.103.104
112+
#
113+
# Summary : Invalid protocol type triggers integrity error.
114+
b"\x00\x01\x00\x00\x06\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
115+
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
116+
),
78117
],
79118
"_kwargs": {},
80119
"_results": {
@@ -86,8 +125,21 @@
86125
{
87126
"_description": "The value of the 'hrlen' field is incorrect.",
88127
"_args": [
89-
b"\x00\x01\x08\x00\x00\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
90-
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68",
128+
(
129+
# ARP (Ethernet/IPv4)
130+
# Hardware type : 1 (Ethernet)
131+
# Protocol type : 0x0800 (IPv4)
132+
# HLEN / PLEN : 0 / 4
133+
# Operation : 1 (Request)
134+
# Sender MAC : 01:02:03:04:05:06
135+
# Sender IP : 11.22.33.44
136+
# Target MAC : 0a:0b:0c:0d:0e:0f
137+
# Target IP : 101.102.103.104
138+
#
139+
# Summary : Hardware length field cleared (0) instead of 6.
140+
b"\x00\x01\x08\x00\x00\x04\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
141+
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
142+
),
91143
],
92144
"_kwargs": {},
93145
"_results": {
@@ -97,8 +149,21 @@
97149
{
98150
"_description": "The value of the 'prlen' field is incorrect.",
99151
"_args": [
100-
b"\x00\x01\x08\x00\x06\x00\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
101-
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68",
152+
(
153+
# ARP (Ethernet/IPv4)
154+
# Hardware type : 1 (Ethernet)
155+
# Protocol type : 0x0800 (IPv4)
156+
# HLEN / PLEN : 6 / 0
157+
# Operation : 1 (Request)
158+
# Sender MAC : 01:02:03:04:05:06
159+
# Sender IP : 11.22.33.44
160+
# Target MAC : 0a:0b:0c:0d:0e:0f
161+
# Target IP : 101.102.103.104
162+
#
163+
# Summary : Protocol length field cleared (0) instead of 4.
164+
b"\x00\x01\x08\x00\x06\x00\x00\x01\x01\x02\x03\x04\x05\x06\x0b\x16"
165+
b"\x21\x2c\x0a\x0b\x0c\x0d\x0e\x0f\x65\x66\x67\x68"
166+
),
102167
],
103168
"_kwargs": {},
104169
"_results": {

net_proto/tests/unit/protocols/arp/test__arp__parser__operation.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,21 @@
4747
{
4848
"_description": "ARP Request.",
4949
"_args": [
50-
b"\x00\x01\x08\x00\x06\x04\x00\x01\x02\x00\x00\x00\x00\x91\x0a\x00"
51-
b"\x01\x5b\x00\x00\x00\x00\x00\x07\x0a\x00\x01\x07",
50+
(
51+
# ARP (Ethernet/IPv4)
52+
# Hardware type : 1 (Ethernet)
53+
# Protocol type : 0x0800 (IPv4)
54+
# HLEN / PLEN : 6 / 4
55+
# Operation : 1 (Request)
56+
# Sender MAC : 02:00:00:00:00:91
57+
# Sender IP : 10.0.1.91
58+
# Target MAC : 00:00:00:00:00:07
59+
# Target IP : 10.0.1.7
60+
#
61+
# Summary : Unicast ARP request — "Who has 10.0.1.7? Tell 10.0.1.91."
62+
b"\x00\x01\x08\x00\x06\x04\x00\x01\x02\x00\x00\x00\x00\x91\x0a\x00"
63+
b"\x01\x5b\x00\x00\x00\x00\x00\x07\x0a\x00\x01\x07"
64+
),
5265
],
5366
"_kwargs": {},
5467
"_results": {
@@ -64,8 +77,21 @@
6477
{
6578
"_description": "ARP Reply.",
6679
"_args": [
67-
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x07\x0a\x00"
68-
b"\x01\x07\x02\x00\x00\x00\x00\x91\x0a\x00\x01\x5b",
80+
(
81+
# ARP (Ethernet/IPv4)
82+
# Hardware type : 1 (Ethernet)
83+
# Protocol type : 0x0800 (IPv4)
84+
# HLEN / PLEN : 6 / 4
85+
# Operation : 2 (Reply)
86+
# Sender MAC : 02:00:00:00:00:07
87+
# Sender IP : 10.0.1.7
88+
# Target MAC : 02:00:00:00:00:91
89+
# Target IP : 10.0.1.91
90+
#
91+
# Summary : Unicast ARP reply — "10.0.1.7 is at 02:00:00:00:00:07."
92+
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x07\x0a\x00"
93+
b"\x01\x07\x02\x00\x00\x00\x00\x91\x0a\x00\x01\x5b"
94+
),
6995
],
7096
"_kwargs": {},
7197
"_results": {

net_proto/tests/unit/protocols/arp/test__arp__parser__sanity_checks.py

Lines changed: 120 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,21 @@
4949
{
5050
"_description": "The value of the 'prlen' field is incorrect.",
5151
"_args": [
52-
b"\x00\x01\x08\x00\x06\x04\x00\x00\x02\x00\x00\x00\x00\x91\x0a\x00"
53-
b"\x01\x5b\x00\x00\x00\x00\x00\x07\x0a\x00\x01\x07",
52+
(
53+
# ARP (Ethernet/IPv4)
54+
# Hardware type : 1 (Ethernet)
55+
# Protocol type : 0x0800 (IPv4)
56+
# HLEN / PLEN : 6 / 4
57+
# Operation : 0 (invalid)
58+
# Sender MAC : 02:00:00:00:00:91
59+
# Sender IP : 10.0.1.91
60+
# Target MAC : 00:00:00:00:00:07
61+
# Target IP : 10.0.1.7
62+
#
63+
# Summary : Malformed ARP header with undefined operation code 0.
64+
b"\x00\x01\x08\x00\x06\x04\x00\x00\x02\x00\x00\x00\x00\x91\x0a\x00"
65+
b"\x01\x5b\x00\x00\x00\x00\x00\x07\x0a\x00\x01\x07"
66+
),
5467
],
5568
"_kwargs": {},
5669
"_results": {
@@ -60,8 +73,21 @@
6073
{
6174
"_description": "The SHA address is unspecified.",
6275
"_args": [
63-
b"\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
64-
b"\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x01\x07",
76+
(
77+
# ARP (Ethernet/IPv4)
78+
# Hardware type : 1 (Ethernet)
79+
# Protocol type : 0x0800 (IPv4)
80+
# HLEN / PLEN : 6 / 4
81+
# Operation : 1 (Request)
82+
# Sender MAC : 00:00:00:00:00:00
83+
# Sender IP : 0.0.0.0
84+
# Target MAC : 00:00:00:00:00:00
85+
# Target IP : 10.0.1.7
86+
#
87+
# Summary : ARP Request with unspecified sender MAC address.
88+
b"\x00\x01\x08\x00\x06\x04\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
89+
b"\x00\x00\x00\x00\x00\x00\x00\x00\x0a\x00\x01\x07"
90+
),
6591
],
6692
"_kwargs": {},
6793
"_results": {
@@ -71,8 +97,21 @@
7197
{
7298
"_description": "The SHA address is multicast.",
7399
"_args": [
74-
b"\x00\x01\x08\x00\x06\x04\x00\x01\x01\x00\x5e\x00\x00\x01\x0a\x00"
75-
b"\x01\x5b\x00\x00\x00\x00\x00\x07\x0a\x00\x01\x07",
100+
(
101+
# ARP (Ethernet/IPv4)
102+
# Hardware type : 1 (Ethernet)
103+
# Protocol type : 0x0800 (IPv4)
104+
# HLEN / PLEN : 6 / 4
105+
# Operation : 1 (Request)
106+
# Sender MAC : 01:00:5e:00:00:01
107+
# Sender IP : 10.0.1.91
108+
# Target MAC : 00:00:00:00:00:07
109+
# Target IP : 10.0.1.7
110+
#
111+
# Summary : ARP Request sent from multicast MAC address.
112+
b"\x00\x01\x08\x00\x06\x04\x00\x01\x01\x00\x5e\x00\x00\x01\x0a\x00"
113+
b"\x01\x5b\x00\x00\x00\x00\x00\x07\x0a\x00\x01\x07"
114+
),
76115
],
77116
"_kwargs": {},
78117
"_results": {
@@ -82,8 +121,21 @@
82121
{
83122
"_description": "The SHA address is broadcast.",
84123
"_args": [
85-
b"\x00\x01\x08\x00\x06\x04\x00\x01\xff\xff\xff\xff\xff\xff\x0a\x00"
86-
b"\x01\x5b\x00\x00\x00\x00\x00\x00\x0a\x00\x01\x07",
124+
(
125+
# ARP (Ethernet/IPv4)
126+
# Hardware type : 1 (Ethernet)
127+
# Protocol type : 0x0800 (IPv4)
128+
# HLEN / PLEN : 6 / 4
129+
# Operation : 1 (Request)
130+
# Sender MAC : ff:ff:ff:ff:ff:ff
131+
# Sender IP : 10.0.1.91
132+
# Target MAC : 00:00:00:00:00:00
133+
# Target IP : 10.0.1.7
134+
#
135+
# Summary : ARP Request claiming broadcast MAC as sender.
136+
b"\x00\x01\x08\x00\x06\x04\x00\x01\xff\xff\xff\xff\xff\xff\x0a\x00"
137+
b"\x01\x5b\x00\x00\x00\x00\x00\x00\x0a\x00\x01\x07"
138+
),
87139
],
88140
"_kwargs": {},
89141
"_results": {
@@ -93,8 +145,21 @@
93145
{
94146
"_description": "The SPA field is unspecified in ARP Reply.",
95147
"_args": [
96-
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\x00\x00"
97-
b"\x00\x00\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07",
148+
(
149+
# ARP (Ethernet/IPv4)
150+
# Hardware type : 1 (Ethernet)
151+
# Protocol type : 0x0800 (IPv4)
152+
# HLEN / PLEN : 6 / 4
153+
# Operation : 2 (Reply)
154+
# Sender MAC : 02:00:00:00:00:91
155+
# Sender IP : 0.0.0.0
156+
# Target MAC : 02:00:00:00:00:07
157+
# Target IP : 10.0.1.7
158+
#
159+
# Summary : ARP Reply advertising unspecified sender IPv4 address.
160+
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\x00\x00"
161+
b"\x00\x00\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07"
162+
),
98163
],
99164
"_kwargs": {},
100165
"_results": {
@@ -105,17 +170,43 @@
105170
{
106171
"_description": "The SPA address is multicast.",
107172
"_args": [
108-
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\xe0\x00"
109-
b"\x00\x01\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07",
173+
(
174+
# ARP (Ethernet/IPv4)
175+
# Hardware type : 1 (Ethernet)
176+
# Protocol type : 0x0800 (IPv4)
177+
# HLEN / PLEN : 6 / 4
178+
# Operation : 2 (Reply)
179+
# Sender MAC : 02:00:00:00:00:91
180+
# Sender IP : 224.0.0.1
181+
# Target MAC : 02:00:00:00:00:07
182+
# Target IP : 10.0.1.7
183+
#
184+
# Summary : ARP Reply advertising multicast sender IPv4 address.
185+
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\xe0\x00"
186+
b"\x00\x01\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07"
187+
),
110188
],
111189
"_kwargs": {},
112190
"_results": {"error_message": "The 'spa' field value 224.0.0.1 must not be a " "multicast IPv4 address."},
113191
},
114192
{
115193
"_description": "The SPA address is broadcast.",
116194
"_args": [
117-
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\xff\xff"
118-
b"\xff\xff\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07",
195+
(
196+
# ARP (Ethernet/IPv4)
197+
# Hardware type : 1 (Ethernet)
198+
# Protocol type : 0x0800 (IPv4)
199+
# HLEN / PLEN : 6 / 4
200+
# Operation : 2 (Reply)
201+
# Sender MAC : 02:00:00:00:00:91
202+
# Sender IP : 255.255.255.255
203+
# Target MAC : 02:00:00:00:00:07
204+
# Target IP : 10.0.1.7
205+
#
206+
# Summary : ARP Reply claiming limited broadcast sender IP address.
207+
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\xff\xff"
208+
b"\xff\xff\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07"
209+
),
119210
],
120211
"_kwargs": {},
121212
"_results": {
@@ -126,8 +217,21 @@
126217
{
127218
"_description": "The SHA address doesn't match the Ethernet source address.",
128219
"_args": [
129-
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\x0a\x00"
130-
b"\x01\x5b\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07",
220+
(
221+
# ARP (Ethernet/IPv4)
222+
# Hardware type : 1 (Ethernet)
223+
# Protocol type : 0x0800 (IPv4)
224+
# HLEN / PLEN : 6 / 4
225+
# Operation : 2 (Reply)
226+
# Sender MAC : 02:00:00:00:00:91
227+
# Sender IP : 10.0.1.91
228+
# Target MAC : 02:00:00:00:00:07
229+
# Target IP : 10.0.1.7
230+
#
231+
# Summary : ARP Reply with sender MAC differing from Ethernet frame source.
232+
b"\x00\x01\x08\x00\x06\x04\x00\x02\x02\x00\x00\x00\x00\x91\x0a\x00"
233+
b"\x01\x5b\x02\x00\x00\x00\x00\x07\x0a\x00\x01\x07"
234+
),
131235
],
132236
"_kwargs": {},
133237
"_results": {

0 commit comments

Comments
 (0)