From b44919ed9b6b28fda79d8a2acf639230d3cdf085 Mon Sep 17 00:00:00 2001 From: Jan Kaluza Date: Thu, 17 Dec 2015 18:25:26 +0100 Subject: [PATCH] Handle situation when sending /whois with non existing nickname :) --- backends/libcommuni/ircnetworkplugin.cpp | 1 + backends/libcommuni/session.cpp | 8 ++++++++ spectrum/src/tests/muc_whois.py | 8 ++++++-- spectrum/src/tests/ngircd.conf | 4 ++-- spectrum/src/tests/start.py | 3 +++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/backends/libcommuni/ircnetworkplugin.cpp b/backends/libcommuni/ircnetworkplugin.cpp index 641d8980..cb3f516d 100644 --- a/backends/libcommuni/ircnetworkplugin.cpp +++ b/backends/libcommuni/ircnetworkplugin.cpp @@ -183,6 +183,7 @@ void IRCNetworkPlugin::handleMessageSendRequest(const std::string &user, const s } else if (message.find("/whois") == 0 || message.find(".whois") == 0) { m_sessions[session]->sendWhoisCommand(target, message.substr(7)); + return; } else { m_sessions[session]->sendCommand(IrcCommand::createMessage(FROM_UTF8(target), FROM_UTF8(message))); diff --git a/backends/libcommuni/session.cpp b/backends/libcommuni/session.cpp index 6a58c558..10bdd37c 100644 --- a/backends/libcommuni/session.cpp +++ b/backends/libcommuni/session.cpp @@ -376,6 +376,14 @@ void MyIrcSession::on_numericMessageReceived(IrcMessage *message) { LOG4CXX_INFO(logger, m_user << "Asking /who for channel " << TO_UTF8(channel)); sendCommand(IrcCommand::createWho(channel)); break; + case 401: + case 402: + nick = TO_UTF8(parameters[1]); + if (m_whois.find(nick) != m_whois.end()) { + sendMessageToFrontend(m_whois[nick], "whois", nick + ": No such client"); + m_whois.erase(nick); + } + break; case 432: m_np->handleDisconnected(m_user, pbnetwork::CONNECTION_ERROR_INVALID_USERNAME, "Erroneous Nickname"); break; diff --git a/spectrum/src/tests/muc_whois.py b/spectrum/src/tests/muc_whois.py index 8c8b08b8..bf91b281 100644 --- a/spectrum/src/tests/muc_whois.py +++ b/spectrum/src/tests/muc_whois.py @@ -29,12 +29,15 @@ class Client(sleekxmpp.ClientXMPP): self.finished = False self.tests = {} - self.tests["whois_received"] = ["libcommuni: Receive /whois command response", False] + self.tests["whois1_received"] = ["libcommuni: Receive /whois command response", False] + self.tests["whois2_received"] = ["libcommuni: Receive /whois command response for invalid nickname", False] def muc_message(self, msg): if msg['mucnick'] != self.nick: if msg["body"] == "responder is connected to irc.example.net (responder)\nresponder is a user on channels: @#channel": - self.tests["whois_received"][1] = True + self.tests["whois1_received"][1] = True + elif msg["body"] == "nonexisting: No such client": + self.tests["whois2_received"][1] = True self.finished = True def start(self, event): @@ -42,3 +45,4 @@ class Client(sleekxmpp.ClientXMPP): self.sendPresence() self.plugin['xep_0045'].joinMUC(self.room, self.nick, wait=True) self.send_message(mto=self.room, mbody="/whois responder", mtype='groupchat') + self.send_message(mto=self.room, mbody="/whois nonexisting", mtype='groupchat') diff --git a/spectrum/src/tests/ngircd.conf b/spectrum/src/tests/ngircd.conf index 50d9eb2c..d34f2b66 100644 --- a/spectrum/src/tests/ngircd.conf +++ b/spectrum/src/tests/ngircd.conf @@ -171,12 +171,12 @@ ;DefaultUserModes = i # Do DNS lookups when a client connects to the server. - ;DNS = yes + DNS = no # Do IDENT lookups if ngIRCd has been compiled with support for it. # Users identified using IDENT are registered without the "~" character # prepended to their user name. - ;Ident = yes + Ident = no # Directory containing configuration snippets (*.conf), that should # be read in after parsing this configuration file. diff --git a/spectrum/src/tests/start.py b/spectrum/src/tests/start.py index 71ea884a..3dba667e 100644 --- a/spectrum/src/tests/start.py +++ b/spectrum/src/tests/start.py @@ -103,6 +103,9 @@ for conf in configurations: if not f.endswith(".py") or f == "start.py": continue + if len(sys.argv) == 2 and sys.argv[1] != f: + continue + print conf.__class__.__name__ + ": Starting " + f + " test ..." test = imp.load_source('test', './' + f) try: