From 2a40419b2bc417c0e2a5b82efe5fc8d77493d02b Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Wed, 8 Jun 2011 14:21:20 +0200 Subject: [PATCH] Fixed crash in handleDisconnect handler --- backends/libircclient-qt/session.cpp | 2 ++ src/networkpluginserver.cpp | 4 +++ tests/CMakeLists.txt | 1 + tests/login/main.cpp | 2 -- tests/login_bad_name/CMakeLists.txt | 6 ++++ tests/login_bad_name/main.cpp | 45 ++++++++++++++++++++++++++++ tests/runtests.py | 20 ++++++++----- 7 files changed, 71 insertions(+), 9 deletions(-) create mode 100644 tests/login_bad_name/CMakeLists.txt create mode 100644 tests/login_bad_name/main.cpp diff --git a/backends/libircclient-qt/session.cpp b/backends/libircclient-qt/session.cpp index 64e87962..e8e5b9e8 100644 --- a/backends/libircclient-qt/session.cpp +++ b/backends/libircclient-qt/session.cpp @@ -17,6 +17,7 @@ MyIrcSession::MyIrcSession(const std::string &user, NetworkPlugin *np, QObject* { this->np = np; this->user = user; + connect(this, SIGNAL(disconnected()), SLOT(on_disconnected())); } void MyIrcSession::on_connected(){ @@ -26,6 +27,7 @@ void MyIrcSession::on_connected(){ void MyIrcSession::on_disconnected() { std::cout << "disconnected:\n"; + np->handleDisconnected(user, "", 0, ""); } void MyIrcSession::on_bufferAdded(Irc::Buffer* buffer) diff --git a/src/networkpluginserver.cpp b/src/networkpluginserver.cpp index 2e635fcb..ce39caa3 100644 --- a/src/networkpluginserver.cpp +++ b/src/networkpluginserver.cpp @@ -201,6 +201,10 @@ void NetworkPluginServer::handleDisconnectedPayload(const std::string &data) { } m_component->m_userRegistry->onPasswordInvalid(payload.user()); + user = m_userManager->getUser(payload.user()); + if (!user) { + return; + } user->handleDisconnected(payload.message()); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bdbd3c65..2151b4c6 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,4 @@ ADD_SUBDIRECTORY(login) +ADD_SUBDIRECTORY(login_bad_name) add_custom_target(tests python runtests.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/tests/login/main.cpp b/tests/login/main.cpp index 77ab9a44..3e55d9db 100644 --- a/tests/login/main.cpp +++ b/tests/login/main.cpp @@ -10,12 +10,10 @@ using namespace boost; Client* client; static void handleDisconnected(const boost::optional &) { -// std::cout << "Disconnected..." << std::endl; exit(1); } static void handleConnected() { -// std::cout << "Connected..." << std::endl; exit(0); } diff --git a/tests/login_bad_name/CMakeLists.txt b/tests/login_bad_name/CMakeLists.txt new file mode 100644 index 00000000..7801614f --- /dev/null +++ b/tests/login_bad_name/CMakeLists.txt @@ -0,0 +1,6 @@ +FILE(GLOB SRC *.cpp) + +ADD_EXECUTABLE(login_bad_name_test ${SRC}) + +TARGET_LINK_LIBRARIES(login_bad_name_test transport ${SWIFTEN_LIBRARIES} -lgconf-2 -lgobject-2.0 -lglib-2.0) + diff --git a/tests/login_bad_name/main.cpp b/tests/login_bad_name/main.cpp new file mode 100644 index 00000000..4df61cdb --- /dev/null +++ b/tests/login_bad_name/main.cpp @@ -0,0 +1,45 @@ +#include +#include + +#include +#include + +using namespace Swift; +using namespace boost; + +Client* client; + +static void handleDisconnected(const boost::optional &error) { + exit(error->getType() != ClientError::AuthenticationFailedError); +} + +static void handleConnected() { + exit(1); +} + +static void handleMessageReceived(Message::ref message) { + // Echo back the incoming message + message->setTo(message->getFrom()); + message->setFrom(JID()); + client->sendMessage(message); +} + +int main(int, char **argv) { + SimpleEventLoop eventLoop; + BoostNetworkFactories networkFactories(&eventLoop); + + JID jid(JID(argv[1]).getNode() + "something", JID(argv[1]).getDomain()); + client = new Client(jid, argv[2], &networkFactories); + client->setAlwaysTrustCertificates(); + client->onConnected.connect(&handleConnected); + client->onDisconnected.connect(bind(&handleDisconnected, _1)); + client->onMessageReceived.connect(bind(&handleMessageReceived, _1)); + ClientOptions opt; + opt.allowPLAINOverNonTLS = true; + client->connect(opt); + + eventLoop.run(); + + delete client; + return 0; +} diff --git a/tests/runtests.py b/tests/runtests.py index cfd08614..5386ff9e 100644 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -3,7 +3,8 @@ import sys from subprocess import * import time -def run_spectrum(backend): +def run_spectrum(backend, test): + os.system("rm test.sql") f = open("sample.cfg", "w") f.write("\ [service]\n\ @@ -21,13 +22,13 @@ def run_spectrum(backend): " % (backend, backend) ) f.close() - p = Popen("../spectrum/src/spectrum sample.cfg >> test.log 2> /dev/null", shell=True) + p = Popen("../spectrum/src/spectrum sample.cfg > " + backend + "_" + test + ".log 2>&1", shell=True) time.sleep(2) return p os.system("killall spectrum 2> /dev/null") -os.system("rm test.log") +os.system("rm *.log") for backend in os.listdir("../backends"): if not os.path.isdir("../backends/" + backend) or backend == "CMakeFiles": @@ -38,7 +39,7 @@ for backend in os.listdir("../backends"): if not os.path.exists(binary): continue - p = run_spectrum(backend); + p = run_spectrum(backend, d) if backend.find("purple") >= 0: p = Popen(binary + " pyjim%jabber.cz@localhost test", shell=True) @@ -46,13 +47,18 @@ for backend in os.listdir("../backends"): else: p = Popen(binary + " testnickname%irc.freenode.net@localhost test", shell=True) - time.sleep(5) + seconds = 0 + while p.poll() is None and seconds < 20: + time.sleep(1) + seconds += 1 - p.poll() if p.returncode == 0: print "[ PASS ]", backend, binary else: - print "[ FAIL ]", backend, binary + if seconds == 20: + print "[ TIME ]", backend, binary + else: + print "[ FAIL ]", backend, binary os.system("killall spectrum 2> /dev/null")