registration.needPassword works

This commit is contained in:
HanzZ 2012-09-13 10:38:06 +02:00
parent cb6af593b6
commit 495d881c5a
2 changed files with 33 additions and 3 deletions

View file

@ -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<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);

View file

@ -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);