Fixed crash in handleDisconnect handler
This commit is contained in:
parent
a9fbe73b80
commit
2a40419b2b
7 changed files with 71 additions and 9 deletions
|
@ -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)
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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})
|
||||
|
|
|
@ -10,12 +10,10 @@ using namespace boost;
|
|||
Client* client;
|
||||
|
||||
static void handleDisconnected(const boost::optional<ClientError> &) {
|
||||
// std::cout << "Disconnected..." << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void handleConnected() {
|
||||
// std::cout << "Connected..." << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
6
tests/login_bad_name/CMakeLists.txt
Normal file
6
tests/login_bad_name/CMakeLists.txt
Normal file
|
@ -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)
|
||||
|
45
tests/login_bad_name/main.cpp
Normal file
45
tests/login_bad_name/main.cpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include <iostream>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include <Swiften/Swiften.h>
|
||||
#include <Swiften/Client/ClientOptions.h>
|
||||
|
||||
using namespace Swift;
|
||||
using namespace boost;
|
||||
|
||||
Client* client;
|
||||
|
||||
static void handleDisconnected(const boost::optional<ClientError> &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;
|
||||
}
|
|
@ -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")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue