Filter command execution with regexp associated to the command
darcs-hash:20071205172404-86b55-fd35e97e0bfed032b789d17481596938616c78d1.gz
This commit is contained in:
@@ -116,7 +116,9 @@ class CommandManager(object):
|
|||||||
"""Apply action on command"""
|
"""Apply action on command"""
|
||||||
if self.commands.has_key(command_name):
|
if self.commands.has_key(command_name):
|
||||||
(must_be_admin, to_jid_re) = self.commands[command_name]
|
(must_be_admin, to_jid_re) = self.commands[command_name]
|
||||||
if not must_be_admin or \
|
to_jid = info_query.get_to()
|
||||||
|
if to_jid_re.match(unicode(to_jid)) and \
|
||||||
|
not must_be_admin or \
|
||||||
(must_be_admin and
|
(must_be_admin and
|
||||||
self.component.is_admin(info_query.get_from())):
|
self.component.is_admin(info_query.get_from())):
|
||||||
short_command_name = self.get_short_command_name(command_name)
|
short_command_name = self.get_short_command_name(command_name)
|
||||||
|
|||||||
@@ -224,6 +224,23 @@ class CommandManager_TestCase(unittest.TestCase):
|
|||||||
"execute")
|
"execute")
|
||||||
self.assertEquals(result, [])
|
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):
|
def test_apply_command_non_existing_action(self):
|
||||||
command.command_manager.commands["command1"] = (False, command.root_node_re)
|
command.command_manager.commands["command1"] = (False, command.root_node_re)
|
||||||
command.command_manager.component = MockComponent()
|
command.command_manager.component = MockComponent()
|
||||||
|
|||||||
Reference in New Issue
Block a user