From 40e18d3ceaf1c3b491a3283b35c1120f208aaef1 Mon Sep 17 00:00:00 2001 From: David Rousselie Date: Wed, 5 Dec 2007 18:24:04 +0100 Subject: [PATCH] Filter command execution with regexp associated to the command darcs-hash:20071205172404-86b55-fd35e97e0bfed032b789d17481596938616c78d1.gz --- src/jcl/jabber/command.py | 8 +++++--- src/jcl/jabber/tests/command.py | 17 +++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/jcl/jabber/command.py b/src/jcl/jabber/command.py index b039d26..a922bda 100644 --- a/src/jcl/jabber/command.py +++ b/src/jcl/jabber/command.py @@ -116,9 +116,11 @@ class CommandManager(object): """Apply action on command""" if self.commands.has_key(command_name): (must_be_admin, to_jid_re) = self.commands[command_name] - if not must_be_admin or \ - (must_be_admin and - self.component.is_admin(info_query.get_from())): + to_jid = info_query.get_to() + if to_jid_re.match(unicode(to_jid)) and \ + not must_be_admin or \ + (must_be_admin and + self.component.is_admin(info_query.get_from())): short_command_name = self.get_short_command_name(command_name) action_command_method = "apply_" + action + "_command" if hasattr(self, action_command_method): diff --git a/src/jcl/jabber/tests/command.py b/src/jcl/jabber/tests/command.py index b91de32..f18e637 100644 --- a/src/jcl/jabber/tests/command.py +++ b/src/jcl/jabber/tests/command.py @@ -224,6 +224,23 @@ class CommandManager_TestCase(unittest.TestCase): "execute") self.assertEquals(result, []) + def test_apply_command_action_to_wrong_jid(self): + command.command_manager.commands["command1"] = (False, command.account_node_re) + command.command_manager.apply_execute_command = \ + lambda iq, command_name: [] + command.command_manager.component = MockComponent() + info_query = Iq(stanza_type="set", + from_jid="user@test.com", + to_jid="jcl.test.com") + result = command.command_manager.apply_command_action(info_query, + "command1", + "execute") + self.assertEquals(len(result), 1) + self.assertEquals(result[0].get_type(), "error") + self.assertEquals(result[0].xmlnode.children.name, "error") + self.assertEquals(result[0].xmlnode.children.prop("type"), "auth") + self.assertEquals(result[0].xmlnode.children.children.name, "forbidden") + def test_apply_command_non_existing_action(self): command.command_manager.commands["command1"] = (False, command.root_node_re) command.command_manager.component = MockComponent()