diff --git a/src/tests/userregistration.cpp b/src/tests/userregistration.cpp index 50f23626..d97db6db 100644 --- a/src/tests/userregistration.cpp +++ b/src/tests/userregistration.cpp @@ -30,6 +30,7 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest CPPUNIT_TEST(unregisterEmptyPayload); CPPUNIT_TEST(changePassword); CPPUNIT_TEST(registerUserEmpty); + CPPUNIT_TEST(registerUserNoNeedPassword); CPPUNIT_TEST_SUITE_END(); public: @@ -213,6 +214,30 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest CPPUNIT_ASSERT_EQUAL(Swift::Presence::Unsubscribed, dynamic_cast(getStanza(received[1]))->getType()); } + void registerUserNoNeedPassword() { + cfg->updateBackendConfig("[registration]\nneedPassword=0\n"); + Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload(); + reg->setUsername("legacyname"); + boost::shared_ptr iq = Swift::IQ::createRequest(Swift::IQ::Set, Swift::JID("localhost"), "id", boost::shared_ptr(reg)); + iq->setFrom("user@localhost"); + injectIQ(iq); + loop->processEvents(); + + CPPUNIT_ASSERT_EQUAL(2, (int) received.size()); + + CPPUNIT_ASSERT(dynamic_cast(getStanza(received[0]))); + CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribe, dynamic_cast(getStanza(received[0]))->getType()); + + CPPUNIT_ASSERT(dynamic_cast(getStanza(received[1]))); + CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast(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); diff --git a/src/userregistration.cpp b/src/userregistration.cpp index 6dea9047..1fbdd82d 100644 --- a/src/userregistration.cpp +++ b/src/userregistration.cpp @@ -189,8 +189,9 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID 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 @@ -210,7 +211,7 @@ bool UserRegistration::handleGetRequest(const Swift::JID& from, const Swift::JID 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"))); @@ -397,11 +398,15 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID } } - 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);