Implement admin ad-hoc command filtering
darcs-hash:20070905192007-86b55-e09501f370e284e62181f199af1a5a1d7138dde1.gz
This commit is contained in:
@@ -61,7 +61,7 @@ class CommandManager(object):
|
||||
self.__logger = logging.getLogger("jcl.jabber.command.CommandManager")
|
||||
self.component = component
|
||||
self.account_manager = account_manager
|
||||
self.commands = []
|
||||
self.commands = {}
|
||||
self.command_re = re.compile("([^#]*#)?(.*)")
|
||||
self.sessions = {}
|
||||
|
||||
@@ -83,9 +83,12 @@ class CommandManager(object):
|
||||
command_desc = short_command_name
|
||||
return command_desc
|
||||
|
||||
def list_commands(self, disco_items, lang_class):
|
||||
def list_commands(self, jid, disco_items, lang_class):
|
||||
"""Return DiscoItem for each supported commands"""
|
||||
for command_name in self.commands:
|
||||
for command_name in self.commands.keys():
|
||||
must_be_admin = self.commands[command_name]
|
||||
if not must_be_admin or \
|
||||
(must_be_admin and unicode(jid) in self.component.get_admins()):
|
||||
command_desc = self.get_command_desc(command_name,
|
||||
lang_class)
|
||||
DiscoItem(disco_items,
|
||||
@@ -105,6 +108,10 @@ class CommandManager(object):
|
||||
|
||||
def apply_command_action(self, info_query, command_name, action):
|
||||
"""Apply action on command"""
|
||||
must_be_admin = self.commands[command_name]
|
||||
if not must_be_admin or \
|
||||
(must_be_admin and
|
||||
unicode(info_query.get_from()) in self.component.get_admins()):
|
||||
short_command_name = self.get_short_command_name(command_name)
|
||||
action_command_method = "apply_" + action + "_command"
|
||||
if hasattr(self, action_command_method):
|
||||
@@ -113,6 +120,9 @@ class CommandManager(object):
|
||||
else:
|
||||
return [info_query.make_error_response(\
|
||||
"feature-not-implemented")]
|
||||
else:
|
||||
return [info_query.make_error_response(\
|
||||
"forbidden")]
|
||||
|
||||
def apply_execute_command(self, info_query, short_command_name):
|
||||
return self.execute_multi_step_command(\
|
||||
@@ -243,31 +253,30 @@ class JCLCommandManager(CommandManager):
|
||||
"""
|
||||
CommandManager.__init__(self, component, account_manager)
|
||||
self.__logger = logging.getLogger("jcl.jabber.command.JCLCommandManager")
|
||||
self.commands.extend(["list",
|
||||
"http://jabber.org/protocol/admin#add-user",
|
||||
"http://jabber.org/protocol/admin#delete-user",
|
||||
"http://jabber.org/protocol/admin#disable-user",
|
||||
"http://jabber.org/protocol/admin#reenable-user",
|
||||
"http://jabber.org/protocol/admin#end-user-session",
|
||||
"http://jabber.org/protocol/admin#get-user-password",
|
||||
"http://jabber.org/protocol/admin#change-user-password",
|
||||
"http://jabber.org/protocol/admin#get-user-roster",
|
||||
"http://jabber.org/protocol/admin#get-user-lastlogin",
|
||||
"http://jabber.org/protocol/admin#get-registered-users-num",
|
||||
"http://jabber.org/protocol/admin#get-disabled-users-num",
|
||||
"http://jabber.org/protocol/admin#get-online-users-num",
|
||||
"http://jabber.org/protocol/admin#get-registered-users-list",
|
||||
"http://jabber.org/protocol/admin#get-disabled-users-list",
|
||||
"http://jabber.org/protocol/admin#get-online-users-lists",
|
||||
"http://jabber.org/protocol/admin#announce",
|
||||
"http://jabber.org/protocol/admin#set-motd",
|
||||
"http://jabber.org/protocol/admin#edit-motd",
|
||||
"http://jabber.org/protocol/admin#delete-motd",
|
||||
"http://jabber.org/protocol/admin#set-welcome",
|
||||
"http://jabber.org/protocol/admin#delete-welcome",
|
||||
"http://jabber.org/protocol/admin#edit-admin",
|
||||
"http://jabber.org/protocol/admin#restart",
|
||||
"http://jabber.org/protocol/admin#shutdown"])
|
||||
self.commands["http://jabber.org/protocol/admin#add-user"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#delete-user"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#disable-user"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#reenable-user"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#end-user-session"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-user-password"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#change-user-password"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-user-roster"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-user-lastlogin"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-registered-users-num"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-disabled-users-num"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-online-users-num"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-registered-users-list"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-disabled-users-list"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#get-online-users-list"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#announce"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#set-motd"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#edit-motd"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#delete-motd"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#set-welcome"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#delete-welcome"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#edit-admin"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#restart"] = True
|
||||
self.commands["http://jabber.org/protocol/admin#shutdown"] = True
|
||||
|
||||
def get_name_and_jid(self, mixed_name_and_jid):
|
||||
return mixed_name_and_jid.split("/", 1)[:2]
|
||||
@@ -405,23 +414,6 @@ class JCLCommandManager(CommandManager):
|
||||
lang_class, format_as_xml),
|
||||
[])
|
||||
|
||||
def execute_list_1(self, info_query, session_context,
|
||||
command_node, lang_class):
|
||||
"""Execute command 'list'. List accounts"""
|
||||
self.__logger.debug("Executing 'list' command")
|
||||
result_form = Form(xmlnode_or_type="result",
|
||||
title="Registered account") # TODO : add to Lang
|
||||
result_form.reported_fields.append(FieldNoType(name="name",
|
||||
label="Account name")) # TODO: add to Lang
|
||||
bare_from_jid = unicode(info_query.get_from().bare())
|
||||
for _account in account.get_accounts(bare_from_jid):
|
||||
fields = [FieldNoType(name="name",
|
||||
value=_account.name)]
|
||||
result_form.add_item(fields)
|
||||
result_form.as_xml(command_node)
|
||||
command_node.setProp("status", STATUS_COMPLETED)
|
||||
return (result_form, [])
|
||||
|
||||
def execute_add_user_1(self, info_query, session_context,
|
||||
command_node, lang_class):
|
||||
self.__logger.debug("Executing command 'add-user' step 1")
|
||||
@@ -942,6 +934,7 @@ class CommandDiscoGetItemsHandler(DiscoHandler):
|
||||
"""
|
||||
if not disco_obj:
|
||||
disco_obj = DiscoItems()
|
||||
return [command_manager.list_commands(disco_items=disco_obj,
|
||||
return [command_manager.list_commands(jid=info_query.get_from(),
|
||||
disco_items=disco_obj,
|
||||
lang_class=lang_class)]
|
||||
|
||||
|
||||
@@ -597,7 +597,7 @@ class JCLComponent(Component, object):
|
||||
return map(string.strip,
|
||||
admins_str.split(','))
|
||||
else:
|
||||
return None
|
||||
return []
|
||||
|
||||
def set_admins(self, admins):
|
||||
self.set_config_parameter("component", "admins", ",".join(admins))
|
||||
|
||||
@@ -25,10 +25,12 @@ import os
|
||||
import tempfile
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
from pyxmpp.jid import JID
|
||||
from pyxmpp.presence import Presence
|
||||
from pyxmpp.jabber.dataforms import Form
|
||||
from pyxmpp.iq import Iq
|
||||
from pyxmpp.message import Message
|
||||
from pyxmpp.jabber.disco import DiscoItems
|
||||
|
||||
import jcl.tests
|
||||
from jcl.lang import Lang
|
||||
@@ -50,6 +52,12 @@ class FieldNoType_TestCase(unittest.TestCase):
|
||||
field.complete_xml_element(fake_iq.xmlnode, None)
|
||||
self.assertFalse(fake_iq.xmlnode.hasProp("type"))
|
||||
|
||||
class MockComponent(object):
|
||||
jid = JID("jcl.test.com")
|
||||
|
||||
def get_admins(self):
|
||||
return ["admin@test.com"]
|
||||
|
||||
class CommandManager_TestCase(unittest.TestCase):
|
||||
def test_get_short_command_name_form_long_name(self):
|
||||
command_name = command.command_manager.get_short_command_name("http://jabber.org/protocol/admin#test-command")
|
||||
@@ -59,6 +67,105 @@ class CommandManager_TestCase(unittest.TestCase):
|
||||
command_name = command.command_manager.get_short_command_name("test-command")
|
||||
self.assertEquals(command_name, "test_command")
|
||||
|
||||
def test_list_commands(self):
|
||||
command.command_manager.commands["command1"] = True
|
||||
command.command_manager.commands["command2"] = False
|
||||
command.command_manager.component = MockComponent()
|
||||
disco_items = command.command_manager.list_commands(jid="user@test.com",
|
||||
disco_items=DiscoItems(),
|
||||
lang_class=Lang.en)
|
||||
items = disco_items.get_items()
|
||||
self.assertEquals(len(items), 1)
|
||||
self.assertEquals(items[0].get_node(), "command2")
|
||||
self.assertEquals(items[0].get_name(), "command2")
|
||||
|
||||
def test_list_commands_as_admin(self):
|
||||
command.command_manager.commands = {}
|
||||
command.command_manager.commands["command1"] = True
|
||||
command.command_manager.commands["command2"] = False
|
||||
command.command_manager.component = MockComponent()
|
||||
disco_items = command.command_manager.list_commands(jid="admin@test.com",
|
||||
disco_items=DiscoItems(),
|
||||
lang_class=Lang.en)
|
||||
items = disco_items.get_items()
|
||||
self.assertEquals(len(items), 2)
|
||||
self.assertEquals(items[0].get_node(), "command1")
|
||||
self.assertEquals(items[0].get_name(), "command1")
|
||||
self.assertEquals(items[1].get_node(), "command2")
|
||||
self.assertEquals(items[1].get_name(), "command2")
|
||||
|
||||
def test_apply_admin_command_action_as_admin(self):
|
||||
command.command_manager.commands["command1"] = True
|
||||
command.command_manager.apply_execute_command = \
|
||||
lambda iq, command_name: []
|
||||
command.command_manager.component = MockComponent()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
result = command.command_manager.apply_command_action(info_query,
|
||||
"command1",
|
||||
"execute")
|
||||
self.assertEquals(result, [])
|
||||
|
||||
def test_apply_admin_command_action_as_user(self):
|
||||
command.command_manager.commands["command1"] = True
|
||||
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_non_admin_command_action_as_admin(self):
|
||||
command.command_manager.commands["command1"] = False
|
||||
command.command_manager.apply_execute_command = \
|
||||
lambda iq, command_name: []
|
||||
command.command_manager.component = MockComponent()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
result = command.command_manager.apply_command_action(info_query,
|
||||
"command1",
|
||||
"execute")
|
||||
self.assertEquals(result, [])
|
||||
|
||||
def test_apply_non_admin_command_action_as_user(self):
|
||||
command.command_manager.commands["command1"] = False
|
||||
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(result, [])
|
||||
|
||||
def test_apply_command_non_existing_action(self):
|
||||
command.command_manager.commands["command1"] = False
|
||||
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",
|
||||
"noexecute")
|
||||
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"), "cancel")
|
||||
self.assertEquals(result[0].xmlnode.children.children.name,
|
||||
"feature-not-implemented")
|
||||
|
||||
class JCLCommandManager_TestCase(JCLTestCase):
|
||||
def setUp(self):
|
||||
JCLTestCase.setUp(self, tables=[Account, ExampleAccount,
|
||||
@@ -73,6 +180,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
"5347",
|
||||
self.config,
|
||||
self.config_file)
|
||||
self.comp.set_admins(["admin@test.com"])
|
||||
self.command_manager = JCLCommandManager(self.comp,
|
||||
self.comp.account_manager)
|
||||
|
||||
@@ -98,7 +206,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
def test_add_form_select_user_jids(self):
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
self.command_manager.add_form_select_user_jids(command_node, Lang.en)
|
||||
@@ -113,7 +221,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
def test_add_form_select_user_jid(self):
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
self.command_manager.add_form_select_user_jid(command_node, Lang.en)
|
||||
@@ -153,7 +261,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account32@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
session_context = {}
|
||||
@@ -221,7 +329,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account32@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
session_context = {}
|
||||
@@ -284,7 +392,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account32@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
session_context = {}
|
||||
@@ -318,7 +426,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -353,7 +461,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -388,7 +496,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -446,15 +554,13 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertTrue(isinstance(iq_result, Iq))
|
||||
self.assertEquals(iq_result.get_node().prop("type"), "result")
|
||||
self.assertEquals(iq_result.get_from(), "jcl.test.com")
|
||||
self.assertEquals(iq_result.get_to(), "user1@test.com")
|
||||
|
||||
self.assertEquals(iq_result.get_to(), "admin@test.com")
|
||||
presence_component = stanza_sent[1]
|
||||
self.assertTrue(isinstance(presence_component, Presence))
|
||||
self.assertEquals(presence_component.get_from(), "jcl.test.com")
|
||||
self.assertEquals(presence_component.get_to(), "user2@test.com")
|
||||
self.assertEquals(presence_component.get_node().prop("type"),
|
||||
"subscribe")
|
||||
|
||||
message = stanza_sent[2]
|
||||
self.assertTrue(isinstance(message, Message))
|
||||
self.assertEquals(message.get_from(), "jcl.test.com")
|
||||
@@ -463,7 +569,6 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
_account.get_new_message_subject(Lang.en))
|
||||
self.assertEquals(message.get_body(),
|
||||
_account.get_new_message_body(Lang.en))
|
||||
|
||||
presence_account = stanza_sent[3]
|
||||
self.assertTrue(isinstance(presence_account, Presence))
|
||||
self.assertEquals(presence_account.get_from(), "account1@jcl.test.com")
|
||||
@@ -475,7 +580,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -510,7 +615,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -545,7 +650,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# First step again
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -605,7 +710,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -640,7 +745,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#add-user")
|
||||
@@ -658,7 +763,6 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertEquals(xml_command.prop("sessionid"), session_id)
|
||||
self.assertEquals(xml_command.children, None)
|
||||
|
||||
|
||||
def test_execute_delete_user(self):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
@@ -686,7 +790,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account32@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#delete-user")
|
||||
@@ -703,7 +807,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#delete-user")
|
||||
@@ -731,7 +835,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#delete-user")
|
||||
@@ -777,7 +881,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertTrue(isinstance(iq_result, Iq))
|
||||
self.assertEquals(iq_result.get_node().prop("type"), "result")
|
||||
self.assertEquals(iq_result.get_from(), "jcl.test.com")
|
||||
self.assertEquals(iq_result.get_to(), "user1@test.com")
|
||||
self.assertEquals(iq_result.get_to(), "admin@test.com")
|
||||
presence_component = stanza_sent[1]
|
||||
self.assertTrue(isinstance(presence_component, Presence))
|
||||
self.assertEquals(presence_component.get_from(), "account11@jcl.test.com")
|
||||
@@ -836,7 +940,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account32.enabled = False
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#disable-user")
|
||||
@@ -853,7 +957,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#disable-user")
|
||||
@@ -885,7 +989,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#disable-user")
|
||||
@@ -944,7 +1048,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account32.enabled = True
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#reenable-user")
|
||||
@@ -961,7 +1065,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#reenable-user")
|
||||
@@ -993,7 +1097,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#reenable-user")
|
||||
@@ -1048,7 +1152,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account32@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#end-user-session")
|
||||
@@ -1065,7 +1169,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#end-user-session")
|
||||
@@ -1097,7 +1201,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#end-user-session")
|
||||
@@ -1126,7 +1230,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertTrue(isinstance(iq_result, Iq))
|
||||
self.assertEquals(iq_result.get_node().prop("type"), "result")
|
||||
self.assertEquals(iq_result.get_from(), "jcl.test.com")
|
||||
self.assertEquals(iq_result.get_to(), "user1@test.com")
|
||||
self.assertEquals(iq_result.get_to(), "admin@test.com")
|
||||
presence_component = stanza_sent[1]
|
||||
self.assertTrue(isinstance(presence_component, Presence))
|
||||
self.assertEquals(presence_component.get_from(), "account11@jcl.test.com")
|
||||
@@ -1161,7 +1265,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account11@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-password")
|
||||
@@ -1178,7 +1282,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-password")
|
||||
@@ -1206,7 +1310,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-password")
|
||||
@@ -1233,7 +1337,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertTrue(isinstance(iq_result, Iq))
|
||||
self.assertEquals(iq_result.get_node().prop("type"), "result")
|
||||
self.assertEquals(iq_result.get_from(), "jcl.test.com")
|
||||
self.assertEquals(iq_result.get_to(), "user1@test.com")
|
||||
self.assertEquals(iq_result.get_to(), "admin@test.com")
|
||||
fields = iq_result.xpath_eval("c:command/data:x/data:field",
|
||||
{"c": "http://jabber.org/protocol/commands",
|
||||
"data": "jabber:x:data"})
|
||||
@@ -1273,7 +1377,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account11@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#change-user-password")
|
||||
@@ -1290,7 +1394,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#change-user-password")
|
||||
@@ -1322,7 +1426,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#change-user-password")
|
||||
@@ -1388,7 +1492,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account=account22)
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-roster")
|
||||
@@ -1405,7 +1509,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-roster")
|
||||
@@ -1472,7 +1576,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account11@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-lastlogin")
|
||||
@@ -1489,7 +1593,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-lastlogin")
|
||||
@@ -1517,7 +1621,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Third step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-user-lastlogin")
|
||||
@@ -1574,7 +1678,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account11@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-registered-users-num")
|
||||
@@ -1618,7 +1722,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.enabled = False
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-disabled-users-num")
|
||||
@@ -1663,7 +1767,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = "chat"
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-online-users-num")
|
||||
@@ -1705,7 +1809,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account11@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-registered-users-list")
|
||||
@@ -1755,7 +1859,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
jid="account2" + str(i) + "@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-registered-users-list")
|
||||
@@ -1794,7 +1898,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -1871,7 +1975,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.enabled = False
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -1925,7 +2029,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
_account.enabled = False
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -1966,7 +2070,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2042,7 +2146,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = "xa"
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2096,7 +2200,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
_account.status = "away"
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2137,7 +2241,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2213,7 +2317,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = "xa"
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2239,7 +2343,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2297,7 +2401,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = account.OFFLINE
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2325,7 +2429,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2361,9 +2465,6 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
def test_execute_edit_motd(self):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
|
||||
self.comp.config_file = config_file
|
||||
self.comp.config = ConfigParser()
|
||||
self.comp.set_motd("test motd")
|
||||
model.db_connect()
|
||||
user1 = User(jid="test1@test.com")
|
||||
@@ -2386,7 +2487,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = account.OFFLINE
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2414,7 +2515,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2450,14 +2551,10 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertTrue(self.comp.config.has_option("component", "motd"))
|
||||
self.assertEquals(self.comp.config.get("component", "motd"),
|
||||
"Message Of The Day")
|
||||
os.unlink(config_file)
|
||||
|
||||
def test_execute_delete_motd(self):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
|
||||
self.comp.config_file = config_file
|
||||
self.comp.config = ConfigParser()
|
||||
self.comp.set_motd("test motd")
|
||||
model.db_connect()
|
||||
user1 = User(jid="test1@test.com")
|
||||
@@ -2480,7 +2577,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = account.OFFLINE
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2498,14 +2595,10 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.__check_actions(result[0])
|
||||
self.comp.config.read(self.comp.config_file)
|
||||
self.assertFalse(self.comp.config.has_option("component", "motd"))
|
||||
os.unlink(config_file)
|
||||
|
||||
def test_execute_set_welcome(self):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
|
||||
self.comp.config_file = config_file
|
||||
self.comp.config = ConfigParser()
|
||||
self.comp.set_welcome_message("Welcome Message")
|
||||
model.db_connect()
|
||||
user1 = User(jid="test1@test.com")
|
||||
@@ -2528,7 +2621,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = account.OFFLINE
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2556,7 +2649,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2587,14 +2680,10 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertTrue(self.comp.config.has_option("component", "welcome_message"))
|
||||
self.assertEquals(self.comp.config.get("component", "welcome_message"),
|
||||
"New Welcome Message")
|
||||
os.unlink(config_file)
|
||||
|
||||
def test_execute_delete_welcome(self):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
|
||||
self.comp.config_file = config_file
|
||||
self.comp.config = ConfigParser()
|
||||
self.comp.set_motd("test motd")
|
||||
model.db_connect()
|
||||
user1 = User(jid="test1@test.com")
|
||||
@@ -2617,7 +2706,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = account.OFFLINE
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2636,14 +2725,10 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.comp.config.read(self.comp.config_file)
|
||||
self.assertFalse(self.comp.config.has_option("component",
|
||||
"welcome_message"))
|
||||
os.unlink(config_file)
|
||||
|
||||
def test_execute_edit_admin(self):
|
||||
self.comp.account_manager.account_classes = (ExampleAccount,
|
||||
Example2Account)
|
||||
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
|
||||
self.comp.config_file = config_file
|
||||
self.comp.config = ConfigParser()
|
||||
self.comp.set_admins(["admin1@test.com", "admin2@test.com"])
|
||||
model.db_connect()
|
||||
user1 = User(jid="test1@test.com")
|
||||
@@ -2666,7 +2751,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
account22.status = account.OFFLINE
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin1@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2696,7 +2781,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
|
||||
# Second step
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin1@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content(command.COMMAND_NS, "command")
|
||||
command_node.setProp("node",
|
||||
@@ -2727,12 +2812,11 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
self.assertTrue(self.comp.config.has_option("component", "admins"))
|
||||
self.assertEquals(self.comp.config.get("component", "admins"),
|
||||
"admin3@test.com,admin4@test.com")
|
||||
os.unlink(config_file)
|
||||
|
||||
# def test_execute_restart(self):
|
||||
# #TODO : implement command
|
||||
# info_query = Iq(stanza_type="set",
|
||||
# from_jid="user1@test.com",
|
||||
# from_jid="admin@test.com",
|
||||
# to_jid="jcl.test.com")
|
||||
# result = self.command_manager.execute_add_user(info_query)
|
||||
# self.assertNotEquals(result, None)
|
||||
@@ -2741,7 +2825,7 @@ class JCLCommandManager_TestCase(JCLTestCase):
|
||||
# def test_execute_shutdown(self):
|
||||
# #TODO : implement command
|
||||
# info_query = Iq(stanza_type="set",
|
||||
# from_jid="user1@test.com",
|
||||
# from_jid="admin@test.com",
|
||||
# to_jid="jcl.test.com")
|
||||
# result = self.command_manager.execute_add_user(info_query)
|
||||
# self.assertNotEquals(result, None)
|
||||
|
||||
@@ -535,7 +535,8 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
info_query = Iq(stanza_type="get",
|
||||
from_jid="user1@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
disco_info = self.comp.disco_get_info("list", info_query)
|
||||
disco_info = self.comp.disco_get_info("http://jabber.org/protocol/admin#get-disabled-users-num",
|
||||
info_query)
|
||||
self.assertEquals(len(self.comp.stream.sent), 0)
|
||||
self.assertTrue(disco_info.has_feature("http://jabber.org/protocol/commands"))
|
||||
self.assertEquals(len(disco_info.get_identities()), 1)
|
||||
@@ -544,7 +545,7 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
self.assertEquals(disco_info.get_identities()[0].get_type(),
|
||||
"command-node")
|
||||
self.assertEquals(disco_info.get_identities()[0].get_name(),
|
||||
Lang.en.command_list)
|
||||
Lang.en.command_get_disabled_users_num)
|
||||
|
||||
###########################################################################
|
||||
# 'disco_get_items' tests
|
||||
@@ -742,15 +743,17 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
def test_disco_get_items_list_commands(self):
|
||||
self.comp.stream = MockStream()
|
||||
self.comp.stream_class = MockStream
|
||||
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
|
||||
self.comp.config = ConfigParser()
|
||||
self.comp.config_file = config_file
|
||||
self.comp.config.read(config_file)
|
||||
self.comp.set_admins(["admin@test.com"])
|
||||
info_query = Iq(stanza_type="get",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
disco_items = self.comp.disco_get_items("http://jabber.org/protocol/commands",
|
||||
info_query)
|
||||
self.assertEquals(len(disco_items.get_items()), 25)
|
||||
item = disco_items.get_items()[0]
|
||||
self.assertEquals(item.get_node(), "list")
|
||||
self.assertEquals(item.get_name(), Lang.en.command_list)
|
||||
self.assertEquals(len(disco_items.get_items()), 24)
|
||||
|
||||
###########################################################################
|
||||
# 'handle_get_version' tests
|
||||
@@ -2714,7 +2717,7 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
self.comp.config.read(self.comp.config_file)
|
||||
self.comp.config.write(open(self.comp.config_file, "w"))
|
||||
admins = self.comp.get_admins()
|
||||
self.assertEquals(admins, None)
|
||||
self.assertEquals(admins, [])
|
||||
os.unlink(config_file)
|
||||
|
||||
def test_set_new_admins(self):
|
||||
@@ -2751,11 +2754,17 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
def test_handle_command_execute_list(self):
|
||||
self.comp.stream = MockStream()
|
||||
self.comp.stream_class = MockStream
|
||||
config_file = tempfile.mktemp(".conf", "jcltest", jcl.tests.DB_DIR)
|
||||
self.comp.config = ConfigParser()
|
||||
self.comp.config_file = config_file
|
||||
self.comp.config.read(config_file)
|
||||
self.comp.set_admins(["admin@test.com"])
|
||||
model.db_connect()
|
||||
user1 = User(jid="user1@test.com")
|
||||
account11 = ExampleAccount(user=user1,
|
||||
name="account11",
|
||||
jid="account11@jcl.test.com")
|
||||
account11.enabled = False
|
||||
account12 = Example2Account(user=user1,
|
||||
name="account12",
|
||||
jid="account12@jcl.test.com")
|
||||
@@ -2764,11 +2773,11 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
jid="account2@jcl.test.com")
|
||||
model.db_disconnect()
|
||||
info_query = Iq(stanza_type="set",
|
||||
from_jid="user1@test.com",
|
||||
from_jid="admin@test.com",
|
||||
to_jid="jcl.test.com")
|
||||
command_node = info_query.set_new_content("http://jabber.org/protocol/commands",
|
||||
"command")
|
||||
command_node.setProp("node", "list")
|
||||
command_node.setProp("node", "http://jabber.org/protocol/admin#get-disabled-users-num")
|
||||
command_node.setProp("action", "execute")
|
||||
self.comp.handle_command(info_query)
|
||||
result = self.comp.stream.sent
|
||||
@@ -2778,10 +2787,13 @@ class JCLComponent_TestCase(JCLTestCase):
|
||||
{"c": "http://jabber.org/protocol/commands"})
|
||||
self.assertEquals(len(command_result), 1)
|
||||
self.assertEquals(command_result[0].prop("status"), "completed")
|
||||
items = result[0].xpath_eval("c:command/data:x/data:item",
|
||||
fields = result[0].xpath_eval("c:command/data:x/data:field",
|
||||
{"c": "http://jabber.org/protocol/commands",
|
||||
"data": "jabber:x:data"})
|
||||
self.assertEquals(len(items), 2)
|
||||
self.assertEquals(len(fields), 2)
|
||||
self.assertEquals(fields[1].prop("var"), "disabledusersnum")
|
||||
self.assertEquals(fields[1].children.name, "value")
|
||||
self.assertEquals(fields[1].children.content, "1")
|
||||
|
||||
class Handler_TestCase(JCLTestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -113,7 +113,7 @@ class Lang:
|
||||
get_gateway_desc = u"Please enter the email address of your contact"
|
||||
get_gateway_prompt = u"Email address"
|
||||
|
||||
command_list = u"List accounts"
|
||||
command_get_disabled_users_num = u"get-disabled-users-num"
|
||||
command_add_user = u"Create new account"
|
||||
select_account_type = u"Select account type"
|
||||
|
||||
@@ -163,7 +163,7 @@ class Lang:
|
||||
get_gateway_desc = u"Entrer l'adresse email de votre contact"
|
||||
get_gateway_prompt = u"Adresse email"
|
||||
|
||||
command_list = u"Liste les comptes"
|
||||
command_get_disabled_users_num = u"get_disabled_users_num"
|
||||
command_add_user = u"Créer un compte"
|
||||
select_account_type = u"Selectionner le type de comptes"
|
||||
|
||||
|
||||
@@ -117,7 +117,7 @@ class Language_TestCase(unittest.TestCase):
|
||||
self.assertNotEquals(self.lang_class.get_gateway_desc, None)
|
||||
self.assertNotEquals(self.lang_class.get_gateway_prompt, None)
|
||||
|
||||
self.assertNotEquals(self.lang_class.command_list, None)
|
||||
self.assertNotEquals(self.lang_class.command_get_disabled_users_num, None)
|
||||
self.assertNotEquals(self.lang_class.command_add_user, None)
|
||||
self.assertNotEquals(self.lang_class.select_account_type, None)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user