Do not double escape JID if we receive it already escaped from broken client
This commit is contained in:
parent
4028a34608
commit
978808c187
2 changed files with 92 additions and 1 deletions
|
@ -54,8 +54,15 @@ bool GatewayResponder::handleGetRequest(const Swift::JID& from, const Swift::JID
|
|||
bool GatewayResponder::handleSetRequest(const Swift::JID& from, const Swift::JID& to, const std::string& id, boost::shared_ptr<Swift::GatewayPayload> payload) {
|
||||
std::string prompt = payload->getPrompt();
|
||||
std::string escaped = Swift::JID::getEscapedNode(prompt);
|
||||
// This code is here to workaround Gajim (and probably other clients bug too) bug
|
||||
// https://trac.gajim.org/ticket/7277
|
||||
if (prompt.find("\\40") != std::string::npos) {
|
||||
LOG4CXX_WARN(logger, from.toString() << " Received already escaped JID " << prompt << ". Not escaping again.");
|
||||
escaped = prompt;
|
||||
}
|
||||
|
||||
std::string jid = escaped + "@" + m_userManager->getComponent()->getJID().toBare().toString();
|
||||
|
||||
|
||||
sendResponse(from, id, boost::shared_ptr<GatewayPayload>(new GatewayPayload(jid)));
|
||||
return true;
|
||||
}
|
||||
|
|
84
src/tests/gatewayresponder.cpp
Normal file
84
src/tests/gatewayresponder.cpp
Normal file
|
@ -0,0 +1,84 @@
|
|||
#include "transport/userregistry.h"
|
||||
#include "transport/config.h"
|
||||
#include "transport/storagebackend.h"
|
||||
#include "transport/user.h"
|
||||
#include "transport/transport.h"
|
||||
#include "transport/conversation.h"
|
||||
#include "transport/rosterresponder.h"
|
||||
#include "transport/usermanager.h"
|
||||
#include "transport/localbuddy.h"
|
||||
#include "transport/gatewayresponder.h"
|
||||
#include <cppunit/TestFixture.h>
|
||||
#include <cppunit/extensions/HelperMacros.h>
|
||||
#include <Swiften/Swiften.h>
|
||||
#include <Swiften/EventLoop/DummyEventLoop.h>
|
||||
#include <Swiften/Server/Server.h>
|
||||
#include <Swiften/Network/DummyNetworkFactories.h>
|
||||
#include <Swiften/Network/DummyConnectionServer.h>
|
||||
#include "Swiften/Server/ServerStanzaChannel.h"
|
||||
#include "Swiften/Server/ServerFromClientSession.h"
|
||||
#include "Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h"
|
||||
#include "basictest.h"
|
||||
|
||||
using namespace Transport;
|
||||
|
||||
class GatewayResponderTest : public CPPUNIT_NS :: TestFixture, public BasicTest {
|
||||
CPPUNIT_TEST_SUITE(GatewayResponderTest);
|
||||
CPPUNIT_TEST(escape);
|
||||
CPPUNIT_TEST(noEscapeEscaped);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
public:
|
||||
GatewayResponder *m_gatewayResponder;
|
||||
|
||||
void setUp (void) {
|
||||
setMeUp();
|
||||
connectUser();
|
||||
|
||||
m_gatewayResponder = new GatewayResponder(component->getIQRouter(), userManager);
|
||||
m_gatewayResponder->start();
|
||||
|
||||
received.clear();
|
||||
}
|
||||
|
||||
void tearDown (void) {
|
||||
received.clear();
|
||||
disconnectUser();
|
||||
delete m_gatewayResponder;
|
||||
tearMeDown();
|
||||
}
|
||||
|
||||
void escape() {
|
||||
boost::shared_ptr<Swift::IQ> iq(new Swift::IQ(Swift::IQ::Set));
|
||||
iq->setTo("icq.localhost");
|
||||
iq->setFrom("user@localhost");
|
||||
iq->addPayload(boost::shared_ptr<Swift::GatewayPayload>(new Swift::GatewayPayload(Swift::JID(), "", "a@b")));
|
||||
iq->setID("123");
|
||||
injectIQ(iq);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
|
||||
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::GatewayPayload>());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("a\\40b@localhost"), getStanza(received[0])->getPayload<Swift::GatewayPayload>()->getJID().toString());
|
||||
}
|
||||
|
||||
void noEscapeEscaped() {
|
||||
boost::shared_ptr<Swift::IQ> iq(new Swift::IQ(Swift::IQ::Set));
|
||||
iq->setTo("icq.localhost");
|
||||
iq->setFrom("user@localhost");
|
||||
iq->addPayload(boost::shared_ptr<Swift::GatewayPayload>(new Swift::GatewayPayload(Swift::JID(), "", "a\\40b")));
|
||||
iq->setID("123");
|
||||
injectIQ(iq);
|
||||
CPPUNIT_ASSERT_EQUAL(1, (int) received.size());
|
||||
|
||||
CPPUNIT_ASSERT(dynamic_cast<Swift::IQ *>(getStanza(received[0])));
|
||||
CPPUNIT_ASSERT_EQUAL(Swift::IQ::Result, dynamic_cast<Swift::IQ *>(getStanza(received[0]))->getType());
|
||||
CPPUNIT_ASSERT(getStanza(received[0])->getPayload<Swift::GatewayPayload>());
|
||||
CPPUNIT_ASSERT_EQUAL(std::string("a\\40b@localhost"), getStanza(received[0])->getPayload<Swift::GatewayPayload>()->getJID().toString());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
CPPUNIT_TEST_SUITE_REGISTRATION (GatewayResponderTest);
|
Loading…
Add table
Reference in a new issue