3
3
4
4
from test .ClientServerTest import ClientServerTest
5
5
6
+
6
7
class TestRequestSeed (ClientServerTest ):
7
8
def __init__ (self , * args , ** kwargs ):
8
9
ClientServerTest .__init__ (self , * args , ** kwargs )
9
10
10
11
def test_request_seed_success (self ):
11
12
request = self .conn .touserqueue .get (timeout = 0.2 )
12
13
self .assertEqual (request , b"\x27 \x05 " )
13
- self .conn .fromuserqueue .put (b"\x67 \x05 \x99 \x88 \x77 \x66 " ) # Positive response
14
+ self .conn .fromuserqueue .put (b"\x67 \x05 \x99 \x88 \x77 \x66 " ) # Positive response
14
15
15
16
def _test_request_seed_success (self ):
16
17
response = self .udsclient .request_seed (0x05 )
@@ -19,16 +20,16 @@ def _test_request_seed_success(self):
19
20
def test_request_seed_success_spr (self ):
20
21
request = self .conn .touserqueue .get (timeout = 0.2 )
21
22
self .assertEqual (request , b"\x27 \x85 " )
22
- self .conn .fromuserqueue .put ('wait' ) # Synchronize
23
+ self .conn .fromuserqueue .put ('wait' ) # Synchronize
23
24
24
25
def _test_request_seed_success_spr (self ):
25
26
with self .udsclient .suppress_positive_response :
26
27
response = self .udsclient .request_seed (0x05 )
27
28
self .assertEqual (response , None )
28
- self .conn .fromuserqueue .get (timeout = 0.2 ) # Avoid closing connection prematurely
29
+ self .conn .fromuserqueue .get (timeout = 0.2 ) # Avoid closing connection prematurely
29
30
30
31
def test_request_seed_denied_exception (self ):
31
- self .wait_request_and_respond (b"\x7F \x27 \x22 " ) # Conditions Not Correct
32
+ self .wait_request_and_respond (b"\x7F \x27 \x22 " ) # Conditions Not Correct
32
33
33
34
def _test_request_seed_denied_exception (self ):
34
35
with self .assertRaises (NegativeResponseException ) as handle :
@@ -41,7 +42,7 @@ def _test_request_seed_denied_exception(self):
41
42
self .assertEqual (response .code , 0x22 )
42
43
43
44
def test_request_seed_denied_no_exception (self ):
44
- self .wait_request_and_respond (b"\x7F \x27 \x22 " ) # Conditions Not Correct
45
+ self .wait_request_and_respond (b"\x7F \x27 \x22 " ) # Conditions Not Correct
45
46
46
47
def _test_request_seed_denied_no_exception (self ):
47
48
self .udsclient .config ['exception_on_negative_response' ] = False
@@ -53,14 +54,14 @@ def _test_request_seed_denied_no_exception(self):
53
54
self .assertEqual (response .code , 0x22 )
54
55
55
56
def test_request_seed_bad_subfn_exception (self ):
56
- self .wait_request_and_respond (b"\x67 \x06 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
57
+ self .wait_request_and_respond (b"\x67 \x06 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
57
58
58
59
def _test_request_seed_bad_subfn_exception (self ):
59
60
with self .assertRaises (UnexpectedResponseException ) as handle :
60
61
self .udsclient .request_seed (0x05 )
61
62
62
63
def test_request_seed_bad_subfn_no_exception (self ):
63
- self .wait_request_and_respond (b"\x67 \x06 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
64
+ self .wait_request_and_respond (b"\x67 \x06 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
64
65
65
66
def _test_request_seed_bad_subfn_no_exception (self ):
66
67
self .udsclient .config ['exception_on_unexpected_response' ] = False
@@ -69,44 +70,44 @@ def _test_request_seed_bad_subfn_no_exception(self):
69
70
self .assertTrue (response .unexpected )
70
71
71
72
def test_request_seed_incomplete_response_exception (self ):
72
- self .wait_request_and_respond (b"\x67 \x05 " ) # Positive response with no seed
73
+ self .wait_request_and_respond (b"\x67 \x05 " ) # Positive response with no seed
73
74
74
75
def _test_request_seed_incomplete_response_exception (self ):
75
76
with self .assertRaises (InvalidResponseException ) as handle :
76
77
self .udsclient .request_seed (0x05 )
77
78
78
79
def test_request_seed_incomplete_response_no_exception (self ):
79
- self .wait_request_and_respond (b"\x67 \x05 " ) # Positive response with no seed
80
+ self .wait_request_and_respond (b"\x67 \x05 " ) # Positive response with no seed
80
81
81
82
def _test_request_seed_incomplete_response_no_exception (self ):
82
83
self .udsclient .config ['exception_on_invalid_response' ] = False
83
84
response = self .udsclient .request_seed (0x05 )
84
85
self .assertFalse (response .valid )
85
86
86
87
def test_request_seed_invalidservice_exception (self ):
87
- self .wait_request_and_respond (b"\x00 \x05 " ) # Inexistent Service
88
+ self .wait_request_and_respond (b"\x00 \x05 " ) # Inexistent Service
88
89
89
90
def _test_request_seed_invalidservice_exception (self ):
90
91
with self .assertRaises (InvalidResponseException ) as handle :
91
92
self .udsclient .request_seed (0x05 )
92
93
93
94
def test_request_seed_invalidservice_no_exception (self ):
94
- self .wait_request_and_respond (b"\x00 \x05 " ) # Inexistent Service
95
+ self .wait_request_and_respond (b"\x00 \x05 " ) # Inexistent Service
95
96
96
97
def _test_request_seed_invalidservice_no_exception (self ):
97
98
self .udsclient .config ['exception_on_invalid_response' ] = False
98
99
response = self .udsclient .request_seed (0x05 )
99
100
self .assertFalse (response .valid )
100
101
101
102
def test_request_seed_wrongservice_exception (self ):
102
- self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
103
+ self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
103
104
104
105
def _test_request_seed_wrongservice_exception (self ):
105
106
with self .assertRaises (UnexpectedResponseException ) as handle :
106
107
self .udsclient .request_seed (0x05 )
107
108
108
109
def test_request_seed_wrongservice_no_exception (self ):
109
- self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
110
+ self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
110
111
111
112
def _test_request_seed_wrongservice_no_exception (self ):
112
113
self .udsclient .config ['exception_on_unexpected_response' ] = False
@@ -119,7 +120,10 @@ def test_request_seed_bad_param(self):
119
120
120
121
def _test_request_seed_bad_param (self ):
121
122
with self .assertRaises (ValueError ):
122
- self .udsclient .request_seed (0x80 )
123
+ self .udsclient .request_seed (0 ) # issue #220
124
+
125
+ with self .assertRaises (ValueError ):
126
+ self .udsclient .request_seed (0x7f ) # issue #220
123
127
124
128
with self .assertRaises (ValueError ):
125
129
self .udsclient .request_seed (- 1 )
@@ -132,14 +136,14 @@ def __init__(self, *args, **kwargs):
132
136
def test_send_key_success (self ):
133
137
request = self .conn .touserqueue .get (timeout = 0.2 )
134
138
self .assertEqual (request , b"\x27 \x06 \x11 \x22 \x33 \x44 " )
135
- self .conn .fromuserqueue .put (b"\x67 \x06 " ) # Positive response
139
+ self .conn .fromuserqueue .put (b"\x67 \x06 " ) # Positive response
136
140
137
141
def _test_send_key_success (self ):
138
- response = self .udsclient .send_key (0x06 ,b"\x11 \x22 \x33 \x44 " )
142
+ response = self .udsclient .send_key (0x06 , b"\x11 \x22 \x33 \x44 " )
139
143
self .assertTrue (response .positive )
140
144
141
145
def test_send_key_denied_exception (self ):
142
- self .wait_request_and_respond (b"\x7F \x27 \x35 " ) # InvalidKey
146
+ self .wait_request_and_respond (b"\x7F \x27 \x35 " ) # InvalidKey
143
147
144
148
def _test_send_key_denied_exception (self ):
145
149
with self .assertRaises (NegativeResponseException ) as handle :
@@ -152,7 +156,7 @@ def _test_send_key_denied_exception(self):
152
156
self .assertEqual (response .code , 0x35 )
153
157
154
158
def test_send_key_denied_no_exception (self ):
155
- self .wait_request_and_respond (b"\x7F \x27 \x35 " ) # InvalidKey
159
+ self .wait_request_and_respond (b"\x7F \x27 \x35 " ) # InvalidKey
156
160
157
161
def _test_send_key_denied_no_exception (self ):
158
162
self .udsclient .config ['exception_on_negative_response' ] = False
@@ -164,14 +168,14 @@ def _test_send_key_denied_no_exception(self):
164
168
self .assertEqual (response .code , 0x35 )
165
169
166
170
def test_send_key_bad_subfn_exception (self ):
167
- self .wait_request_and_respond (b"\x67 \x08 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
171
+ self .wait_request_and_respond (b"\x67 \x08 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
168
172
169
173
def _test_send_key_bad_subfn_exception (self ):
170
174
with self .assertRaises (UnexpectedResponseException ) as handle :
171
175
self .udsclient .send_key (0x06 , b"\x11 \x22 \x33 \x44 " )
172
176
173
177
def test_send_key_bad_subfn_no_exception (self ):
174
- self .wait_request_and_respond (b"\x67 \x08 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
178
+ self .wait_request_and_respond (b"\x67 \x08 \x99 \x88 \x77 \x66 " ) # Positive response with wrong subfunction
175
179
176
180
def _test_send_key_bad_subfn_no_exception (self ):
177
181
self .udsclient .config ['exception_on_unexpected_response' ] = False
@@ -180,29 +184,29 @@ def _test_send_key_bad_subfn_no_exception(self):
180
184
self .assertTrue (response .unexpected )
181
185
182
186
def test_send_key_invalidservice_exception (self ):
183
- self .wait_request_and_respond (b"\x00 \x06 " ) # Inexistent Service
187
+ self .wait_request_and_respond (b"\x00 \x06 " ) # Inexistent Service
184
188
185
189
def _test_send_key_invalidservice_exception (self ):
186
190
with self .assertRaises (InvalidResponseException ) as handle :
187
191
self .udsclient .send_key (0x06 , b"\x11 \x22 \x33 \x44 " )
188
192
189
193
def test_send_key_invalidservice_no_exception (self ):
190
- self .wait_request_and_respond (b"\x00 \x06 " ) # Inexistent Service
194
+ self .wait_request_and_respond (b"\x00 \x06 " ) # Inexistent Service
191
195
192
196
def _test_send_key_invalidservice_no_exception (self ):
193
197
self .udsclient .config ['exception_on_invalid_response' ] = False
194
198
response = self .udsclient .send_key (0x06 , b"\x11 \x22 \x33 \x44 " )
195
199
self .assertFalse (response .valid )
196
200
197
201
def test_send_key_wrongservice_exception (self ):
198
- self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
202
+ self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
199
203
200
204
def _test_send_key_wrongservice_exception (self ):
201
205
with self .assertRaises (UnexpectedResponseException ) as handle :
202
206
self .udsclient .send_key (0x06 , b"\x11 \x22 \x33 \x44 " )
203
207
204
208
def test_send_key_wrongservice_no_exception (self ):
205
- self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
209
+ self .wait_request_and_respond (b"\x7E \x00 " ) # Valid but wrong service (Tester Present)
206
210
207
211
def _test_send_key_wrongservice_no_exception (self ):
208
212
self .udsclient .config ['exception_on_unexpected_response' ] = False
@@ -217,6 +221,12 @@ def _test_send_key_bad_param(self):
217
221
with self .assertRaises (ValueError ):
218
222
self .udsclient .send_key (0x80 , b"\x11 \x22 \x33 \x44 " )
219
223
224
+ with self .assertRaises (ValueError ):
225
+ self .udsclient .send_key (0x7F , b"\x11 \x22 \x33 \x44 " ) # issue #220
226
+
227
+ with self .assertRaises (ValueError ):
228
+ self .udsclient .send_key (0 , b"\x11 \x22 \x33 \x44 " ) # issue #220
229
+
220
230
with self .assertRaises (ValueError ):
221
231
self .udsclient .send_key (- 1 , b"\x11 \x22 \x33 \x44 " )
222
232
@@ -249,15 +259,15 @@ def test_unlock_success(self):
249
259
self .assertEqual (request , b"\x27 \x07 " ) # Request seed
250
260
self .conn .fromuserqueue .put (b"\x67 \x07 \x11 \x22 \x33 \x44 " ) # Positive response
251
261
request = self .conn .touserqueue .get (timeout = 0.2 )
252
- key = bytearray ([(0x10 + 0x07 + i + 0 + 0x11 ), (0x10 + 0x07 + i + 1 + 0x22 ), (0x10 + 0x07 + i + 2 + 0x33 ), (0x10 + 0x07 + i + 3 + 0x44 )])
262
+ key = bytearray ([(0x10 + 0x07 + i + 0 + 0x11 ), (0x10 + 0x07 + i + 1 + 0x22 ), (0x10 + 0x07 + i + 2 + 0x33 ), (0x10 + 0x07 + i + 3 + 0x44 )])
253
263
self .assertEqual (request , b"\x27 \x08 " + bytes (key ))
254
264
self .conn .fromuserqueue .put (b"\x67 \x08 " ) # Positive response
255
265
256
266
def _test_unlock_success (self ):
257
267
self .udsclient .config ['security_algo' ] = self .dummy_algo
258
268
self .udsclient .config ['security_algo_params' ] = 0x10
259
- response = self .udsclient .unlock_security_access (0x07 )
260
- response = self .udsclient .unlock_security_access (0x08 )
269
+ response = self .udsclient .unlock_security_access (0x07 )
270
+ response = self .udsclient .unlock_security_access (0x08 )
261
271
self .assertTrue (response .positive )
262
272
263
273
def test_unlock_already_unlocked (self ):
@@ -267,7 +277,7 @@ def test_unlock_already_unlocked(self):
267
277
def _test_unlock_already_unlocked (self ):
268
278
self .udsclient .config ['security_algo' ] = self .dummy_algo
269
279
self .udsclient .config ['security_algo_params' ] = 0x10
270
- response = self .udsclient .unlock_security_access (0x07 )
280
+ response = self .udsclient .unlock_security_access (0x07 )
271
281
self .assertTrue (response .positive )
272
282
273
283
def test_unlock_success_backward_compatibility (self ):
@@ -282,22 +292,21 @@ def test_unlock_success_backward_compatibility(self):
282
292
def _test_unlock_success_backward_compatibility (self ):
283
293
self .udsclient .config ['security_algo' ] = self .dummy_algo_backward_compatible
284
294
self .udsclient .config ['security_algo_params' ] = 0xFF
285
- response = self .udsclient .unlock_security_access (0x07 )
286
- response = self .udsclient .unlock_security_access (0x08 )
295
+ response = self .udsclient .unlock_security_access (0x07 )
296
+ response = self .udsclient .unlock_security_access (0x08 )
287
297
self .assertTrue (response .positive )
288
298
289
-
290
299
def test_unlock_seed_fail_exception (self ):
291
- self .wait_request_and_respond (b"\x7F \x27 \x11 " )
300
+ self .wait_request_and_respond (b"\x7F \x27 \x11 " )
292
301
293
302
def _test_unlock_seed_fail_exception (self ):
294
303
self .udsclient .config ['security_algo' ] = self .dummy_algo
295
304
self .udsclient .config ['security_algo_params' ] = 0xFF
296
305
with self .assertRaises (NegativeResponseException ):
297
- response = self .udsclient .unlock_security_access (0x07 )
306
+ response = self .udsclient .unlock_security_access (0x07 )
298
307
299
308
def test_unlock_seed_fail_no_exception (self ):
300
- self .wait_request_and_respond (b"\x7F \x27 \x11 " )
309
+ self .wait_request_and_respond (b"\x7F \x27 \x11 " )
301
310
302
311
def _test_unlock_seed_fail_no_exception (self ):
303
312
self .udsclient .config ['security_algo' ] = self .dummy_algo
0 commit comments