summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-08-28 10:01:54 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-08-28 10:01:54 (GMT)
commitb1a9a1b61ebce0f64d656006a85607c8c8491f4a (patch)
treea3157084893c6fa0f41f85a4de1b36f280334c02
parent66f820c2c7e2d7c6d883c995bf7b2da37aa963c7 (diff)
parent2faca4242e4de2568eb917df83fd1b9c21f33897 (diff)
downloadswift-contrib-b1a9a1b61ebce0f64d656006a85607c8c8491f4a.zip
swift-contrib-b1a9a1b61ebce0f64d656006a85607c8c8491f4a.tar.bz2
Merge branch 'swift-1.x'
* swift-1.x: Remove relaxation of not checking JIDs if the IQRouter's JID isn't set. Fixed Request::isAccountJID(). Check sender on incoming IQ responses.
-rw-r--r--Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp2
-rw-r--r--Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp2
-rw-r--r--Swiften/Client/CoreClient.cpp1
-rw-r--r--Swiften/Disco/UnitTest/CapsManagerTest.cpp14
-rw-r--r--Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp4
-rw-r--r--Swiften/Queries/IQRouter.h15
-rw-r--r--Swiften/Queries/Request.cpp43
-rw-r--r--Swiften/Queries/Request.h2
-rw-r--r--Swiften/Queries/UnitTest/RequestTest.cpp109
-rw-r--r--Swiften/VCards/UnitTest/VCardManagerTest.cpp8
10 files changed, 160 insertions, 40 deletions
diff --git a/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp
index 0c2633a..bd96b2d 100644
--- a/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp
+++ b/Swiften/Avatars/UnitTest/VCardAvatarManagerTest.cpp
@@ -129,7 +129,7 @@ class VCardAvatarManagerTest : public CppUnit::TestFixture {
void sendVCardResult() {
VCard::ref vcard(new VCard());
vcard->setFullName("Foo Bar");
- stanzaChannel->onIQReceived(IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getID(), vcard));
+ stanzaChannel->onIQReceived(IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard));
}
private:
diff --git a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp
index e0fd080..821412b 100644
--- a/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp
+++ b/Swiften/Avatars/UnitTest/VCardUpdateAvatarManagerTest.cpp
@@ -167,7 +167,7 @@ class VCardUpdateAvatarManagerTest : public CppUnit::TestFixture {
if (!avatar.empty()) {
vcard->setPhoto(avatar);
}
- return IQ::createResult(JID("baz@fum.com"), stanzaChannel->sentStanzas[0]->getID(), vcard);
+ return IQ::createResult(JID("baz@fum.com"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
}
void handleAvatarChanged(const JID& jid) {
diff --git a/Swiften/Client/CoreClient.cpp b/Swiften/Client/CoreClient.cpp
index 4b438f6..9aaa66b 100644
--- a/Swiften/Client/CoreClient.cpp
+++ b/Swiften/Client/CoreClient.cpp
@@ -36,6 +36,7 @@ CoreClient::CoreClient(const JID& jid, const SafeByteArray& password, NetworkFac
stanzaChannel_->onAvailableChanged.connect(boost::bind(&CoreClient::handleStanzaChannelAvailableChanged, this, _1));
iqRouter_ = new IQRouter(stanzaChannel_);
+ iqRouter_->setJID(jid);
tlsFactories = new PlatformTLSFactories();
}
diff --git a/Swiften/Disco/UnitTest/CapsManagerTest.cpp b/Swiften/Disco/UnitTest/CapsManagerTest.cpp
index 6d4be30..699e96f 100644
--- a/Swiften/Disco/UnitTest/CapsManagerTest.cpp
+++ b/Swiften/Disco/UnitTest/CapsManagerTest.cpp
@@ -124,7 +124,7 @@ class CapsManagerTest : public CppUnit::TestFixture {
void testReceiveSameHashFromDifferentUserAfterFailedDiscoRequestsDisco() {
boost::shared_ptr<CapsManager> testling = createManager();
sendPresenceWithCaps(user1, capsInfo1);
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
stanzaChannel->sentStanzas.clear();
sendPresenceWithCaps(user2, capsInfo1);
@@ -175,7 +175,7 @@ class CapsManagerTest : public CppUnit::TestFixture {
boost::shared_ptr<CapsManager> testling = createManager();
sendPresenceWithCaps(user1, capsInfo1);
sendPresenceWithCaps(user2, capsInfo1alt);
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<DiscoInfo>(1, user2, IQ::Get));
boost::shared_ptr<DiscoInfo> discoInfo(stanzaChannel->sentStanzas[1]->getPayload<DiscoInfo>());
@@ -188,8 +188,8 @@ class CapsManagerTest : public CppUnit::TestFixture {
sendPresenceWithCaps(user1, capsInfo1);
sendPresenceWithCaps(user2, capsInfo1alt);
sendPresenceWithCaps(user3, capsInfo1);
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[1]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[1]->getTo(), stanzaChannel->sentStanzas[1]->getID()));
CPPUNIT_ASSERT(stanzaChannel->isRequestAtIndex<DiscoInfo>(2, user3, IQ::Get));
}
@@ -197,7 +197,7 @@ class CapsManagerTest : public CppUnit::TestFixture {
void testReceiveSameHashFromFailingUserAfterReconnectRequestsDisco() {
boost::shared_ptr<CapsManager> testling = createManager();
sendPresenceWithCaps(user1, capsInfo1);
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
stanzaChannel->setAvailable(false);
stanzaChannel->setAvailable(true);
stanzaChannel->sentStanzas.clear();
@@ -215,7 +215,7 @@ class CapsManagerTest : public CppUnit::TestFixture {
stanzaChannel->setAvailable(true);
stanzaChannel->sentStanzas.clear();
sendPresenceWithCaps(user1, capsInfo1);
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(stanzaChannel->sentStanzas.size()));
}
@@ -251,7 +251,7 @@ class CapsManagerTest : public CppUnit::TestFixture {
}
void sendDiscoInfoResult(boost::shared_ptr<DiscoInfo> discoInfo) {
- stanzaChannel->onIQReceived(IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getID(), discoInfo));
+ stanzaChannel->onIQReceived(IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), discoInfo));
}
private:
diff --git a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp
index 558a3d7..5b43f69 100644
--- a/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp
+++ b/Swiften/FileTransfer/UnitTest/IBBSendSessionTest.cpp
@@ -103,7 +103,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {
boost::shared_ptr<IBBSendSession> testling = createSession("foo@bar.com/baz");
testling->setBlockSize(3);
testling->start();
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
CPPUNIT_ASSERT(finished);
CPPUNIT_ASSERT(error);
@@ -139,7 +139,7 @@ class IBBSendSessionTest : public CppUnit::TestFixture {
private:
IQ::ref createIBBResult() {
- return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[stanzaChannel->sentStanzas.size()-1]->getID(), boost::shared_ptr<IBB>());
+ return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[stanzaChannel->sentStanzas.size()-1]->getTo(), stanzaChannel->sentStanzas[stanzaChannel->sentStanzas.size()-1]->getID(), boost::shared_ptr<IBB>());
}
private:
diff --git a/Swiften/Queries/IQRouter.h b/Swiften/Queries/IQRouter.h
index 80d623c..167cb8f 100644
--- a/Swiften/Queries/IQRouter.h
+++ b/Swiften/Queries/IQRouter.h
@@ -22,6 +22,20 @@ namespace Swift {
~IQRouter();
/**
+ * Sets the JID of this IQ router.
+ *
+ * This JID is used by requests to check whether incoming
+ * results are addressed correctly.
+ */
+ void setJID(const JID& jid) {
+ jid_ = jid;
+ }
+
+ const JID& getJID() {
+ return jid_;
+ }
+
+ /**
* Sets the 'from' JID for all outgoing IQ stanzas.
*
* By default, IQRouter does not add a from to IQ stanzas, since
@@ -55,6 +69,7 @@ namespace Swift {
private:
IQChannel* channel_;
+ JID jid_;
JID from_;
std::vector< boost::shared_ptr<IQHandler> > handlers_;
std::vector< boost::shared_ptr<IQHandler> > queuedRemoves_;
diff --git a/Swiften/Queries/Request.cpp b/Swiften/Queries/Request.cpp
index 359c6a6..0126d62 100644
--- a/Swiften/Queries/Request.cpp
+++ b/Swiften/Queries/Request.cpp
@@ -41,27 +41,42 @@ bool Request::handleIQ(boost::shared_ptr<IQ> iq) {
bool handled = false;
if (iq->getType() == IQ::Result || iq->getType() == IQ::Error) {
if (sent_ && iq->getID() == id_) {
- if (iq->getType() == IQ::Result) {
- boost::shared_ptr<Payload> payload = iq->getPayloadOfSameType(payload_);
- if (!payload && boost::dynamic_pointer_cast<RawXMLPayload>(payload_) && !iq->getPayloads().empty()) {
- payload = iq->getPayloads().front();
- }
- handleResponse(payload, ErrorPayload::ref());
- }
- else {
- ErrorPayload::ref errorPayload = iq->getPayload<ErrorPayload>();
- if (errorPayload) {
- handleResponse(boost::shared_ptr<Payload>(), errorPayload);
+ if (isCorrectSender(iq->getFrom())) {
+ if (iq->getType() == IQ::Result) {
+ boost::shared_ptr<Payload> payload = iq->getPayloadOfSameType(payload_);
+ if (!payload && boost::dynamic_pointer_cast<RawXMLPayload>(payload_) && !iq->getPayloads().empty()) {
+ payload = iq->getPayloads().front();
+ }
+ handleResponse(payload, ErrorPayload::ref());
}
else {
- handleResponse(boost::shared_ptr<Payload>(), ErrorPayload::ref(new ErrorPayload(ErrorPayload::UndefinedCondition)));
+ ErrorPayload::ref errorPayload = iq->getPayload<ErrorPayload>();
+ if (errorPayload) {
+ handleResponse(boost::shared_ptr<Payload>(), errorPayload);
+ }
+ else {
+ handleResponse(boost::shared_ptr<Payload>(), ErrorPayload::ref(new ErrorPayload(ErrorPayload::UndefinedCondition)));
+ }
}
+ router_->removeHandler(this);
+ handled = true;
}
- router_->removeHandler(this);
- handled = true;
}
}
return handled;
}
+bool Request::isCorrectSender(const JID& jid) {
+ if (isAccountJID(receiver_)) {
+ return isAccountJID(jid);
+ }
+ else {
+ return jid.equals(receiver_, JID::WithResource);
+ }
+}
+
+bool Request::isAccountJID(const JID& jid) {
+ return jid.isValid() ? router_->getJID().toBare().equals(jid, JID::WithResource) : true;
+}
+
}
diff --git a/Swiften/Queries/Request.h b/Swiften/Queries/Request.h
index 19687c1..a7139cf 100644
--- a/Swiften/Queries/Request.h
+++ b/Swiften/Queries/Request.h
@@ -59,6 +59,8 @@ namespace Swift {
private:
bool handleIQ(boost::shared_ptr<IQ>);
+ bool isCorrectSender(const JID& jid);
+ bool isAccountJID(const JID& jid);
private:
IQRouter* router_;
diff --git a/Swiften/Queries/UnitTest/RequestTest.cpp b/Swiften/Queries/UnitTest/RequestTest.cpp
index b1d1b07..52d62fb 100644
--- a/Swiften/Queries/UnitTest/RequestTest.cpp
+++ b/Swiften/Queries/UnitTest/RequestTest.cpp
@@ -31,6 +31,12 @@ class RequestTest : public CppUnit::TestFixture {
CPPUNIT_TEST(testHandleIQ_RawXMLPayload);
CPPUNIT_TEST(testHandleIQ_GetWithSameID);
CPPUNIT_TEST(testHandleIQ_SetWithSameID);
+ CPPUNIT_TEST(testHandleIQ_IncorrectSender);
+ CPPUNIT_TEST(testHandleIQ_IncorrectSenderForServerQuery);
+ CPPUNIT_TEST(testHandleIQ_IncorrectOtherResourceSenderForServerQuery);
+ CPPUNIT_TEST(testHandleIQ_ServerRespondsWithDomain);
+ CPPUNIT_TEST(testHandleIQ_ServerRespondsWithBareJID);
+ CPPUNIT_TEST(testHandleIQ_ServerRespondsWithoutFrom);
CPPUNIT_TEST_SUITE_END();
public:
@@ -98,7 +104,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
- channel_->onIQReceived(createResponse("test-id"));
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
@@ -111,7 +117,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
- channel_->onIQReceived(createResponse("different-id"));
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"different-id"));
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
@@ -123,7 +129,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
- boost::shared_ptr<IQ> error = createError("test-id");
+ boost::shared_ptr<IQ> error = createError(JID("foo@bar.com/baz"),"test-id");
boost::shared_ptr<Payload> errorPayload = boost::shared_ptr<ErrorPayload>(new ErrorPayload(ErrorPayload::InternalServerError));
error->addPayload(errorPayload);
channel_->onIQReceived(error);
@@ -139,7 +145,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
- channel_->onIQReceived(createError("test-id"));
+ channel_->onIQReceived(createError(JID("foo@bar.com/baz"),"test-id"));
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(receivedErrors.size()));
@@ -150,7 +156,7 @@ class RequestTest : public CppUnit::TestFixture {
void testHandleIQ_BeforeSend() {
MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
- channel_->onIQReceived(createResponse("test-id"));
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
@@ -163,7 +169,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.send();
responsePayload_ = boost::make_shared<MyOtherPayload>();
- channel_->onIQReceived(createResponse("test-id"));
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
@@ -177,7 +183,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.send();
responsePayload_ = boost::make_shared<MyOtherPayload>();
- channel_->onIQReceived(createResponse("test-id"));
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"),"test-id"));
CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
@@ -189,7 +195,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
- boost::shared_ptr<IQ> response = createResponse("test-id");
+ boost::shared_ptr<IQ> response = createResponse(JID("foo@bar.com/baz"),"test-id");
response->setType(IQ::Get);
channel_->onIQReceived(response);
@@ -203,7 +209,7 @@ class RequestTest : public CppUnit::TestFixture {
testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
testling.send();
- boost::shared_ptr<IQ> response = createResponse("test-id");
+ boost::shared_ptr<IQ> response = createResponse(JID("foo@bar.com/baz"), "test-id");
response->setType(IQ::Set);
channel_->onIQReceived(response);
@@ -212,6 +218,85 @@ class RequestTest : public CppUnit::TestFixture {
CPPUNIT_ASSERT_EQUAL(2, static_cast<int>(channel_->iqs_.size()));
}
+ void testHandleIQ_IncorrectSender() {
+ MyRequest testling(IQ::Get, JID("foo@bar.com/baz"), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("anotherfoo@bar.com/baz"), "test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_IncorrectSenderForServerQuery() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("foo@bar.com/baz"), "test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_IncorrectOtherResourceSenderForServerQuery() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("alice@wonderland.lit/RabbitHole"), "test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_ServerRespondsWithDomain() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("wonderland.lit"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(0, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_ServerRespondsWithBareJID() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID("alice@wonderland.lit"),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+ void testHandleIQ_ServerRespondsWithoutFrom() {
+ MyRequest testling(IQ::Get, JID(), payload_, router_);
+ router_->setJID("alice@wonderland.lit/TeaParty");
+ testling.onResponse.connect(boost::bind(&RequestTest::handleResponse, this, _1, _2));
+ testling.send();
+
+ channel_->onIQReceived(createResponse(JID(),"test-id"));
+
+ CPPUNIT_ASSERT_EQUAL(1, responsesReceived_);
+ CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(receivedErrors.size()));
+ CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(channel_->iqs_.size()));
+ }
+
+
private:
void handleResponse(boost::shared_ptr<Payload> p, ErrorPayload::ref e) {
@@ -239,15 +324,17 @@ class RequestTest : public CppUnit::TestFixture {
++responsesReceived_;
}
- boost::shared_ptr<IQ> createResponse(const std::string& id) {
+ boost::shared_ptr<IQ> createResponse(const JID& from, const std::string& id) {
boost::shared_ptr<IQ> iq(new IQ(IQ::Result));
+ iq->setFrom(from);
iq->addPayload(responsePayload_);
iq->setID(id);
return iq;
}
- boost::shared_ptr<IQ> createError(const std::string& id) {
+ boost::shared_ptr<IQ> createError(const JID& from, const std::string& id) {
boost::shared_ptr<IQ> iq(new IQ(IQ::Error));
+ iq->setFrom(from);
iq->setID(id);
return iq;
}
diff --git a/Swiften/VCards/UnitTest/VCardManagerTest.cpp b/Swiften/VCards/UnitTest/VCardManagerTest.cpp
index bea93eb..eecec7b 100644
--- a/Swiften/VCards/UnitTest/VCardManagerTest.cpp
+++ b/Swiften/VCards/UnitTest/VCardManagerTest.cpp
@@ -92,7 +92,7 @@ class VCardManagerTest : public CppUnit::TestFixture {
void testRequest_Error() {
boost::shared_ptr<VCardManager> testling = createManager();
testling->requestVCard(JID("foo@bar.com/baz"));
- stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getID()));
+ stanzaChannel->onIQReceived(IQ::createError(JID("baz@fum.com/foo"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID()));
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(changes.size()));
CPPUNIT_ASSERT_EQUAL(JID("foo@bar.com/baz"), changes[0].first);
@@ -180,17 +180,17 @@ class VCardManagerTest : public CppUnit::TestFixture {
IQ::ref createVCardResult() {
VCard::ref vcard(new VCard());
vcard->setFullName("Foo Bar");
- return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getID(), vcard);
+ return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
}
IQ::ref createOwnVCardResult() {
VCard::ref vcard(new VCard());
vcard->setFullName("Myself");
- return IQ::createResult(JID(), stanzaChannel->sentStanzas[0]->getID(), vcard);
+ return IQ::createResult(JID(), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), vcard);
}
IQ::ref createSetVCardResult() {
- return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getID(), VCard::ref());
+ return IQ::createResult(JID("baz@fum.com/dum"), stanzaChannel->sentStanzas[0]->getTo(), stanzaChannel->sentStanzas[0]->getID(), VCard::ref());
}