Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions varlink/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ def filter_params(self, parent_name, varlink_type, _namespaced, args, kwargs):
)
return args
else:
InvalidParameter(parent_name)
raise InvalidParameter(parent_name)

if isinstance(varlink_type, _CustomType):
# print("CustomType", varlink_type.name)
Expand All @@ -307,7 +307,8 @@ def filter_params(self, parent_name, varlink_type, _namespaced, args, kwargs):
return args

if isinstance(varlink_type, _Enum) and isinstance(args, str):
# print("Returned str:", args)
if args not in varlink_type.fields:
raise InvalidParameter(parent_name)
return args

if isinstance(varlink_type, _Array):
Expand Down
16 changes: 16 additions & 0 deletions varlink/tests/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,19 @@ def test_interfacename(self):
self.assertIsNotNone(
varlink.Interface("interface xn--c1yn36f.xn--c1yn36f.xn--c1yn36f\nmethod F()->()").name
)

def test_bad_types(self):
interface = varlink.Interface("""
interface org.example.testerrors
type TypeEnum ( a, b, c )
type TypeDict (dict: [string]string)

method Foo(param: TypeEnum) -> ()
method Bar(param: TypeDict) -> ()
""")
foo = interface.get_method("Foo")
with self.assertRaises(varlink.InvalidParameter):
interface.filter_params("test.call", foo.in_type, False, (), {"param": "d"})
bar = interface.get_method("Bar")
with self.assertRaises(varlink.InvalidParameter):
interface.filter_params("test.call", bar.in_type, False, (), {"param": {"dict": [1, 2, 3]}})