Skip to content

Commit d724fc2

Browse files
author
Tony Crisci
committed
fix variant validator
1 parent 4bcf72a commit d724fc2

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

dbus_next/signature.py

-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,6 @@ def _verify_struct(self, body):
225225
self.children[i].verify(member)
226226

227227
def _verify_variant(self, body):
228-
return
229228
# a variant signature and value is valid by construction
230229
if not isinstance(body, Variant):
231230
raise SignatureBodyMismatchError('DBus VARIANT type "v" must be Python type "Variant"')

test/test_signature.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
from dbus_next import SignatureTree
1+
from dbus_next import SignatureTree, SignatureBodyMismatchError
2+
3+
import pytest
24

35

46
def assert_simple_type(signature, type_):
@@ -145,3 +147,38 @@ def test_dict_of_structs():
145147
assert len(struct_child.children) == 2
146148
for i in range(0, 2):
147149
assert_simple_type('s', struct_child.children[i])
150+
151+
152+
def test_invalid_variants():
153+
tree = SignatureTree('a{sa{sv}}')
154+
s_con = {
155+
'type': '802-11-wireless',
156+
'uuid': '1234',
157+
'id': 'SSID',
158+
}
159+
160+
s_wifi = {
161+
'ssid': 'SSID',
162+
'mode': 'infrastructure',
163+
'hidden': True,
164+
}
165+
166+
s_wsec = {
167+
'key-mgmt': 'wpa-psk',
168+
'auth-alg': 'open',
169+
'psk': 'PASSWORD',
170+
}
171+
172+
s_ip4 = {'method': 'auto'}
173+
s_ip6 = {'method': 'auto'}
174+
175+
con = {
176+
'connection': s_con,
177+
'802-11-wireless': s_wifi,
178+
'802-11-wireless-security': s_wsec,
179+
'ipv4': s_ip4,
180+
'ipv6': s_ip6
181+
}
182+
183+
with pytest.raises(SignatureBodyMismatchError):
184+
tree.verify([con])

0 commit comments

Comments
 (0)