From 90a511ed523cfaf500dd27316b12e128e0c70ce3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Remko=20Tron=C3=A7on?= <git@el-tramo.be>
Date: Sun, 6 Feb 2011 12:50:46 +0100
Subject: Only assume we are logged in when we have bound our resource.

Resolves: #758

diff --git a/Swiften/Client/ClientSession.cpp b/Swiften/Client/ClientSession.cpp
index 9950a76..49334a3 100644
--- a/Swiften/Client/ClientSession.cpp
+++ b/Swiften/Client/ClientSession.cpp
@@ -225,7 +225,13 @@ void ClientSession::handleElement(boost::shared_ptr<Element> element) {
 			needSessionStart = streamFeatures->hasSession();
 			needResourceBind = streamFeatures->hasResourceBind();
 			needAcking = streamFeatures->hasStreamManagement();
-			continueSessionInitialization();
+			if (!needResourceBind) {
+				// Resource binding is a MUST
+				finishSession(Error::ResourceBindError);
+			}
+			else {
+				continueSessionInitialization();
+			}
 		}
 	}
 	else if (boost::dynamic_pointer_cast<Compressed>(element)) {
diff --git a/Swiften/Client/UnitTest/ClientSessionTest.cpp b/Swiften/Client/UnitTest/ClientSessionTest.cpp
index 5d0e2aa..af8a4c3 100644
--- a/Swiften/Client/UnitTest/ClientSessionTest.cpp
+++ b/Swiften/Client/UnitTest/ClientSessionTest.cpp
@@ -39,6 +39,7 @@ class ClientSessionTest : public CppUnit::TestFixture {
 		CPPUNIT_TEST(testStartTLS_ServerError);
 		CPPUNIT_TEST(testStartTLS_ConnectError);
 		CPPUNIT_TEST(testStartTLS_InvalidIdentity);
+		CPPUNIT_TEST(testStart_StreamFeaturesWithoutResourceBindingFails);
 		CPPUNIT_TEST(testAuthenticate);
 		CPPUNIT_TEST(testAuthenticate_Unauthorized);
 		CPPUNIT_TEST(testAuthenticate_NoValidAuthMechanisms);
@@ -157,6 +158,18 @@ class ClientSessionTest : public CppUnit::TestFixture {
 			CPPUNIT_ASSERT_EQUAL(CertificateVerificationError::InvalidServerIdentity, boost::dynamic_pointer_cast<CertificateVerificationError>(sessionFinishedError)->getType());
 		}
 
+		void testStart_StreamFeaturesWithoutResourceBindingFails() {
+			boost::shared_ptr<ClientSession> session(createSession());
+			session->start();
+			server->receiveStreamStart();
+			server->sendStreamStart();
+			server->sendEmptyStreamFeatures();
+
+			CPPUNIT_ASSERT_EQUAL(ClientSession::Finished, session->getState());
+			CPPUNIT_ASSERT(sessionFinishedReceived);
+			CPPUNIT_ASSERT(sessionFinishedError);
+		}
+
 		void testAuthenticate() {
 			boost::shared_ptr<ClientSession> session(createSession());
 			session->start();
@@ -404,6 +417,10 @@ class ClientSessionTest : public CppUnit::TestFixture {
 					onElementReceived(streamFeatures);
 				}
 
+				void sendEmptyStreamFeatures() {
+					onElementReceived(boost::make_shared<StreamFeatures>());
+				}
+
 				void sendAuthSuccess() {
 					onElementReceived(boost::shared_ptr<AuthSuccess>(new AuthSuccess()));
 				}
-- 
cgit v0.10.2-6-g49f6