Changeset - cb6af593b6a6
[Not reviewed]
0 5 0
HanzZ - 13 years ago 2012-09-13 10:13:44
hanzz.k@gmail.com
registration.needRegistration works
5 files changed with 33 insertions and 4 deletions:
0 comments (0 inline, 0 general)
include/transport/networkplugin.h
Show inline comments
 
@@ -37,14 +37,16 @@ class NetworkPlugin {
 

	
 
		class PluginConfig {
 
			public:
 
				PluginConfig() : m_needPassword(true) {}
 
				PluginConfig() : m_needPassword(true), m_needRegistration(false) {}
 
				virtual ~PluginConfig() {}
 

	
 
				void setNeedRegistration(bool needRegistration = false) { m_needRegistration = needRegistration; }
 
				void setNeedPassword(bool needPassword = true) { m_needPassword = needPassword; }
 
				void setExtraFields(const std::vector<std::string> &fields) { m_extraFields = fields; }
 

	
 
			private:
 
				bool m_needPassword;
 
				bool m_needRegistration;
 
				std::vector<std::string> m_extraFields;
 

	
 
				friend class NetworkPlugin;
plugin/cpp/networkplugin.cpp
Show inline comments
 
@@ -65,6 +65,7 @@ NetworkPlugin::~NetworkPlugin() {
 
void NetworkPlugin::sendConfig(const PluginConfig &cfg) {
 
	std::string data = "[registration]";
 
	data += std::string("needPassword=") + (cfg.m_needPassword ? "1" : "0") + "\n";
 
	data += std::string("needRegistration=") + (cfg.m_needRegistration ? "1" : "0") + "\n";
 

	
 
	for (std::vector<std::string>::const_iterator it = cfg.m_extraFields.begin(); it != cfg.m_extraFields.end(); it++) {
 
		data += std::string("extraField=") + (*it) + "\n";
src/config.cpp
Show inline comments
 
@@ -288,6 +288,7 @@ void Config::updateBackendConfig(const std::string &backendConfig) {
 
	options_description opts("Backend options");
 
	opts.add_options()
 
		("registration.needPassword", value<bool>()->default_value(true), "")
 
		("registration.needRegistration", value<bool>()->default_value(false), "")
 
		("registration.extraField", value<std::vector<std::string> >()->multitoken(), "")
 
	;
 

	
src/tests/usermanager.cpp
Show inline comments
 
@@ -24,6 +24,8 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
	CPPUNIT_TEST_SUITE(UserManagerTest);
 
	CPPUNIT_TEST(connectUser);
 
	CPPUNIT_TEST(connectUserTransportDisabled);
 
	CPPUNIT_TEST(connectUserRegistrationNeeded);
 
	CPPUNIT_TEST(connectUserRegistrationNeededRegistered);
 
	CPPUNIT_TEST(handleProbePresence);
 
	CPPUNIT_TEST(disconnectUser);
 
	CPPUNIT_TEST_SUITE_END();
 
@@ -49,6 +51,24 @@ class UserManagerTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
 
		CPPUNIT_ASSERT(!user);
 
	}
 

	
 
	void connectUserRegistrationNeeded() {
 
		cfg->updateBackendConfig("[registration]\nneedRegistration=1\n");
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
 
		loop->processEvents();
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		CPPUNIT_ASSERT(streamEnded);
 
	}
 

	
 
	void connectUserRegistrationNeededRegistered() {
 
		addUser();
 
		cfg->updateBackendConfig("[registration]\nneedRegistration=1\n");
 
		CPPUNIT_ASSERT_EQUAL(0, userManager->getUserCount());
 
		userRegistry->isValidUserPassword(Swift::JID("user@localhost/resource"), serverFromClientSession.get(), Swift::createSafeByteArray("password"));
 
		loop->processEvents();
 
		CPPUNIT_ASSERT_EQUAL(1, userManager->getUserCount());
 
		CPPUNIT_ASSERT(!streamEnded);
 
	}
 

	
 
	void handleProbePresence() {
 
		Swift::Presence::ref response = Swift::Presence::create();
src/usermanager.cpp
Show inline comments
 
@@ -200,11 +200,16 @@ void UserManager::handlePresence(Swift::Presence::ref presence) {
 
		UserInfo res;
 
		bool registered = m_storageBackend ? m_storageBackend->getUser(userkey, res) : false;
 

	
 
		// In server mode, there's no registration, but we store users into database
 
		// (if storagebackend is available) because of caching. Passwords are not stored
 
		// in server mode.
 
		// In server mode, we don't need registration normally, but for networks like IRC
 
		// or Twitter where there's no real authorization using password, we have to force
 
		// registration otherwise some data (like bookmarked rooms) could leak.
 
		if (m_component->inServerMode()) {
 
			if (!registered) {
 
				// If we need registration, stop login process because user is not registered
 
				if (CONFIG_BOOL_DEFAULTED(m_component->getConfig(), "registration.needRegistration", false)) {
 
					m_userRegistry->onPasswordInvalid(presence->getFrom());
 
					return;
 
				}
 
				res.password = "";
 
				res.uin = presence->getFrom().getNode();
 
				res.jid = userkey;
0 comments (0 inline, 0 general)