Filter command execution with regexp associated to the command

darcs-hash:20071205172404-86b55-fd35e97e0bfed032b789d17481596938616c78d1.gz
This commit is contained in:
David Rousselie
2007-12-05 18:24:04 +01:00
parent 05c3358feb
commit 40e18d3cea
2 changed files with 22 additions and 3 deletions

View File

@@ -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):

View File

@@ -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()