fix whitespace account name for ad-hoc command add-user

This commit is contained in:
David Rousselie
2011-10-08 12:58:49 +02:00
parent 5ef25b59bb
commit ec929f5880
6 changed files with 83 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: jcl
Version: 0.1b3
Version: 0.1rc2
Summary: Jabber Component Library
Home-page: http://people.happycoders.org/dax/projects/jcl
Author: David Rousselie

View File

@@ -1,3 +1,4 @@
FormEncode
SQLObject>=0.8
pyxmpp>=1.0.1
pysqlite>=2.0

View File

@@ -34,6 +34,7 @@ from pyxmpp.jabber.dataforms import Form, Field
from pyxmpp.message import Message
from jcl.jabber.disco import DiscoHandler, RootDiscoGetInfoHandler
from jcl.jabber.register import SetRegisterHandler
from jcl.model import account
from jcl.model.account import Account, User
@@ -579,13 +580,18 @@ class JCLCommandManager(CommandManager):
{"c": "http://jabber.org/protocol/commands",
"jxd" : "jabber:x:data"})[0]
x_data = Form(x_node)
to_send = self.component.account_manager.create_account_from_type(\
account_name=session_context["name"][0],
from_jid=JID(session_context["user_jid"][0]),
account_type=session_context["account_type"][0],
lang_class=lang_class,
x_data=x_data)
command_node.setProp("status", STATUS_COMPLETED)
errors = SetRegisterHandler(self.component).validate_form(\
x_data, info_query, lang_class)
if errors is not None:
raise CommandError("bad-request")
else:
to_send = self.component.account_manager.create_account_from_type(\
account_name=session_context["name"][0],
from_jid=JID(session_context["user_jid"][0]),
account_type=session_context["account_type"][0],
lang_class=lang_class,
x_data=x_data)
command_node.setProp("status", STATUS_COMPLETED)
return (None, to_send)
###########################################################################

View File

@@ -1020,6 +1020,63 @@ class JCLCommandManagerAddUserCommand_TestCase(JCLCommandManagerTestCase):
self.check_step_3(result, session_id,
"test4@test.com", "test4@test.com")
def test_execute_add_user_invalid_name(self):
"""
test 'add-user' ad-hoc command with an invalid name (with spaces).
"""
self.info_query.set_from("test4@test.com")
result = self.command_manager.apply_command_action(\
self.info_query,
"http://jabber.org/protocol/admin#add-user",
"execute")
session_id = self.check_step_1(result, "test4@test.com")
# Second step
info_query = prepare_submit(\
node="http://jabber.org/protocol/admin#add-user",
session_id=session_id,
from_jid="test4@test.com",
fields=[Field(field_type="list-single",
name="account_type",
value="Example")])
result = self.command_manager.apply_command_action(\
info_query,
"http://jabber.org/protocol/admin#add-user",
"next")
context_session = self.check_step_2(result, session_id,
"test4@test.com", "test4@test.com")
# Third step
info_query = prepare_submit(\
node="http://jabber.org/protocol/admin#add-user",
session_id=session_id,
from_jid="test4@test.com",
fields=[Field(field_type="text-single",
name="name",
value="account 1"),
Field(field_type="text-single",
name="login",
value="login1"),
Field(field_type="text-private",
name="password",
value="pass1"),
Field(field_type="boolean",
name="store_password",
value="1"),
Field(field_type="list-single",
name="test_enum",
value="choice2"),
Field(field_type="text-single",
name="test_int",
value="42")],
action="complete")
result = self.command_manager.apply_command_action(\
info_query,
"http://jabber.org/protocol/admin#add-user",
"execute")
self.assertEquals(result[0].get_type(), "error")
self.assertEquals(result[0].get_error().get_type(), "modify")
def test_execute_add_user_prev(self):
"""
test 'add-user' ad-hoc command with an admin user. Test 'prev' action.
@@ -1079,6 +1136,8 @@ class JCLCommandManagerAddUserCommand_TestCase(JCLCommandManagerTestCase):
other_session_id = self.check_step_1(result, "admin@test.com",
is_admin=True)
self.assertEquals(other_session_id, session_id)
def test_execute_add_user_cancel(self):
"""
Test cancel 'add-user' ad-hoc command .