Skip to content

Commit

Permalink
Test TypeError when setting non-callable callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ch3pjw authored and hoefling committed Sep 5, 2021
1 parent 7b41f27 commit 9798d6d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,16 @@ def _expect_sign_failure(self):
with self.assertRaisesRegex(xmlsec.Error, 'failed to sign'):
self._sign_doc()

def _register_mismatch_callbacks(self, match_cb=lambda filename: False):
xmlsec.register_callbacks(
def _mismatch_callbacks(self, match_cb=lambda filename: False):
return [
match_cb,
lambda filename: None,
lambda none, buf: 0,
lambda none: None,
)
]

def _register_mismatch_callbacks(self, match_cb=lambda filename: False):
xmlsec.register_callbacks(*self._mismatch_callbacks(match_cb))

def _register_match_callbacks(self):
xmlsec.register_callbacks(
Expand Down Expand Up @@ -147,3 +150,9 @@ def mismatch_cb(filename):
self._register_mismatch_callbacks(mismatch_cb)
self._expect_sign_failure()
self.assertEqual(mismatch_calls, 2)

def test_register_non_callables(self):
for idx in range(4):
cbs = self._mismatch_callbacks()
cbs[idx] = None
self.assertRaises(TypeError, xmlsec.register_callbacks, *cbs)

0 comments on commit 9798d6d

Please sign in to comment.