Changeset - 495d881c5a91
[Not reviewed]
0 2 0
HanzZ - 13 years ago 2012-09-13 10:38:06
hanzz.k@gmail.com
registration.needPassword works
2 files changed with 33 insertions and 3 deletions:
0 comments (0 inline, 0 general)
src/tests/userregistration.cpp
Show inline comments
 
@@ -27,12 +27,13 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 
	CPPUNIT_TEST(getFormRegistered);
 
	CPPUNIT_TEST(registerUser);
 
	CPPUNIT_TEST(unregisterUser);
 
	CPPUNIT_TEST(unregisterEmptyPayload);
 
	CPPUNIT_TEST(changePassword);
 
	CPPUNIT_TEST(registerUserEmpty);
 
	CPPUNIT_TEST(registerUserNoNeedPassword);
 
	CPPUNIT_TEST_SUITE_END();
 

	
 
	public:
 
		void setUp (void) {
 
			setMeUp();
 
			received.clear();
 
@@ -210,9 +211,33 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest
 
			CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unsubscribe, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getType());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unsubscribed, dynamic_cast<Swift::Presence *>(getStanza(received[1]))->getType());
 
		}
 

	
 
		void registerUserNoNeedPassword() {
 
			cfg->updateBackendConfig("[registration]\nneedPassword=0\n");
 
			Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload();
 
			reg->setUsername("legacyname");
 
			boost::shared_ptr<Swift::IQ> iq = Swift::IQ::createRequest(Swift::IQ::Set, Swift::JID("localhost"), "id", boost::shared_ptr<Swift::Payload>(reg));
 
			iq->setFrom("user@localhost");
 
			injectIQ(iq);
 
			loop->processEvents();
 

	
 
			CPPUNIT_ASSERT_EQUAL(2, (int) received.size());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::Presence *>(getStanza(received[0])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribe, dynamic_cast<Swift::Presence *>(getStanza(received[0]))->getType());
 

	
 
			CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[1])));
 
			CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[1]))->getType());
 

	
 
			UserInfo user;
 
			CPPUNIT_ASSERT_EQUAL(true, storage->getUser("user@localhost", user));
 

	
 
			CPPUNIT_ASSERT_EQUAL(std::string("legacyname"), user.uin);
 
			CPPUNIT_ASSERT_EQUAL(std::string(""), user.password);
 
		}
 

	
 
};
 

	
 
CPPUNIT_TEST_SUITE_REGISTRATION (UserRegistrationTest);
src/userregistration.cpp
Show inline comments
 
@@ -186,14 +186,15 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
 
	std::string usernameField = CONFIG_STRING(m_config, "registration.username_label");
 

	
 
	// normal jabber:iq:register
 
	reg->setInstructions(instructions);
 
	reg->setRegistered(registered);
 
	reg->setUsername(res.uin);
 
	if (CONFIG_STRING(m_config, "service.protocol") != "twitter" && CONFIG_STRING(m_config, "service.protocol") != "bonjour")
 
	if (CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true)) {
 
		reg->setPassword("");
 
	}
 

	
 

	
 
	// form
 
	Form::ref form(new Form(Form::FormType));
 
	form->setTitle((("Registration")));
 
	form->setInstructions((instructions));
 
@@ -207,13 +208,13 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID
 
	username->setName("username");
 
	username->setLabel((usernameField));
 
	username->setValue(res.uin);
 
	username->setRequired(true);
 
	form->addField(username);
 

	
 
	if (CONFIG_STRING(m_config, "service.protocol") != "twitter" && CONFIG_STRING(m_config, "service.protocol") != "bonjour") {
 
	if (CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true)) {
 
		TextPrivateFormField::ref password = TextPrivateFormField::create();
 
		password->setName("password");
 
		password->setLabel((("Password")));
 
		password->setRequired(true);
 
		form->addField(password);
 
	}
 
@@ -394,17 +395,21 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID
 
		if (!validLocal) {
 
			sendError(from, id, ErrorPayload::NotAuthorized, ErrorPayload::Modify);
 
			return true;
 
		}
 
	}
 

	
 
	if (!payload->getUsername() || !payload->getPassword()) {
 
	if (!payload->getUsername() || (!payload->getPassword() && CONFIG_BOOL_DEFAULTED(m_config, "registration.needPassword", true))) {
 
		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
		return true;
 
	}
 

	
 
	if (!payload->getPassword()) {
 
		payload->setPassword("");
 
	}
 

	
 
	// Register or change password
 
	if (payload->getUsername()->empty()) {
 
		sendError(from, id, ErrorPayload::NotAcceptable, ErrorPayload::Modify);
 
		return true;
 
	}
 

	
0 comments (0 inline, 0 general)