From d6b44717caac615c7d08d2d59208b03951a10fa0 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 12 Nov 2015 14:23:12 +0100 Subject: [PATCH] Swiften 3.x.y uses FormField::UnknownType as a default type for form fields without any type. Handle that properly in the UserRegistration. --- src/tests/userregistration.cpp | 45 ++++++++++++++++++++++++++++++++++ src/userregistration.cpp | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/tests/userregistration.cpp b/src/tests/userregistration.cpp index c2d3de59..cefa43b6 100644 --- a/src/tests/userregistration.cpp +++ b/src/tests/userregistration.cpp @@ -34,6 +34,7 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest CPPUNIT_TEST(changePassword); CPPUNIT_TEST(registerUserEmpty); CPPUNIT_TEST(registerUserNoNeedPassword); + CPPUNIT_TEST(registerUserFormUnknownType); CPPUNIT_TEST_SUITE_END(); public: @@ -362,6 +363,50 @@ class UserRegistrationTest : public CPPUNIT_NS :: TestFixture, public BasicTest CPPUNIT_ASSERT_EQUAL(std::string(""), user.password); } + void registerUserFormUnknownType() { +#if HAVE_SWIFTEN_3 + Swift::Form::ref form(new Swift::Form(Swift::Form::FormType)); + + Swift::FormField::ref type = boost::make_shared(Swift::FormField::UnknownType, "jabber:iq:register"); + type->setName("FORM_TYPE"); + form->addField(type); + + Swift::FormField::ref username = boost::make_shared(Swift::FormField::UnknownType, "legacyname"); + username->setName("username"); + form->addField(username); + + Swift::FormField::ref password = boost::make_shared(Swift::FormField::UnknownType, "password"); + password->setName("password"); + form->addField(password); + + Swift::FormField::ref language = boost::make_shared(Swift::FormField::UnknownType, "language"); + language->setName("en"); + form->addField(language); + + Swift::InBandRegistrationPayload *reg = new Swift::InBandRegistrationPayload(); + reg->setForm(form); + + 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(getStanza(received[0])->getPayload()); + CPPUNIT_ASSERT(dynamic_cast(getStanza(received[1]))); + CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast(getStanza(received[1]))->getType()); + + iq = Swift::IQ::createError(Swift::JID("localhost"), getStanza(received[0])->getTo(), getStanza(received[0])->getID()); + received.clear(); + injectIQ(iq); + loop->processEvents(); + + CPPUNIT_ASSERT(dynamic_cast(getStanza(received[0]))); + CPPUNIT_ASSERT_EQUAL(Swift::Presence::Subscribe, dynamic_cast(getStanza(received[0]))->getType()); +#endif + } + }; CPPUNIT_TEST_SUITE_REGISTRATION (UserRegistrationTest); diff --git a/src/userregistration.cpp b/src/userregistration.cpp index f8a76981..90d4074b 100644 --- a/src/userregistration.cpp +++ b/src/userregistration.cpp @@ -382,7 +382,7 @@ bool UserRegistration::handleSetRequest(const Swift::JID& from, const Swift::JID for (std::vector::const_iterator it = fields.begin(); it != fields.end(); it++) { #if HAVE_SWIFTEN_3 FormField::ref textSingle = *it; - if (textSingle->getType() == FormField::TextSingleType) { + if (textSingle->getType() == FormField::TextSingleType || textSingle->getType() == FormField::UnknownType) { #else TextSingleFormField::ref textSingle = boost::dynamic_pointer_cast(*it); if (textSingle) {