Skip to content
This repository was archived by the owner on Sep 10, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ function Client(server, nick, opt) {
}
});

self.addListener('kick', function(channel) {
if (self.opt.autoRejoin)
self.addListener('kick', function(channel, nick) {
if (self.opt.autoRejoin && nick.toLowerCase() === self.nick.toLowerCase())
self.send.apply(self, ['JOIN'].concat(channel.split(' ')));
});
self.addListener('motd', function() {
Expand Down
6 changes: 6 additions & 0 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ var MockIrcd = function(port, encoding, isSecure) {
c.on('data', function(data) {
var msg = data.toString(self.encoding).split('\r\n').filter(function(m) { return m; });
self.incoming = self.incoming.concat(msg);
msg.forEach(function(line) { self.emit('line', line); });
});

self.on('send', function(data) {
Expand Down Expand Up @@ -68,6 +69,11 @@ MockIrcd.prototype.getIncomingMsgs = function() {
return this.incoming;
};

MockIrcd.prototype.greet = function(username) {
username = username || 'testbot';
this.send(':localhost 001 ' + username + ' :Welcome to the Internet Relay Chat Network testbot\r\n');
}

var fixtures = require('./data/fixtures');
module.exports.getFixtures = function(testSuite) {
return fixtures[testSuite];
Expand Down
2 changes: 1 addition & 1 deletion test/test-433-before-001.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('connect and sets hostmask when nick in use', function(t) {

mock.server.on('connection', function() {
mock.send(':localhost 433 * testbot :Nickname is already in use.\r\n')
mock.send(':localhost 001 testbot1 :Welcome to the Internet Relay Chat Network testbot\r\n');
mock.greet('testbot1');
});

client.on('registered', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/test-auditorium.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('user gets opped in auditorium', function(t) {

mock.server.on('connection', function() {
// Initiate connection
mock.send(':localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n');
mock.greet();

// Set prefix modes
mock.send(':localhost 005 testbot PREFIX=(ov)@+ CHANTYPES=#& :are supported by this server\r\n');
Expand Down
13 changes: 3 additions & 10 deletions test/test-irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ var testHelpers = require('./helpers');

var expected = testHelpers.getFixtures('basic');
var withClient = testHelpers.withClient;
var greeting = ':localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n';

function runTests(t, isSecure, useSecureObject) {
var port = isSecure ? 6697 : 6667;
Expand Down Expand Up @@ -34,9 +33,7 @@ function runTests(t, isSecure, useSecureObject) {

t.plan(expected.sent.length + expected.received.length);

mock.server.on(isSecure ? 'secureConnection' : 'connection', function() {
mock.send(greeting);
});
mock.server.on(isSecure ? 'secureConnection' : 'connection', function() { mock.greet(); });

client.on('registered', function() {
t.equal(mock.outgoing[0], expected.received[0][0], expected.received[0][1]);
Expand Down Expand Up @@ -120,9 +117,7 @@ test ('does not crash when disconnected and trying to send messages', function(t
var client = obj.client;
var mock = obj.mock;

mock.server.on('connection', function() {
mock.send(greeting);
});
mock.server.on('connection', function() { mock.greet(); });

client.on('registered', function() {
client.say('#channel', 'message');
Expand All @@ -145,9 +140,7 @@ test ('unhandled messages are emitted appropriately', function(t) {
obj.closeWithEnd(t);
var endTimeout;

mock.server.on('connection', function() {
mock.send(greeting);
});
mock.server.on('connection', function(){ mock.greet(); });

client.on('registered', function() {
mock.send(':127.0.0.1 150 :test\r\n');
Expand Down
4 changes: 1 addition & 3 deletions test/test-mode.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ test('handles various origins and types of chanmodes correctly', function(t) {
{ key: '#channel', serverName: '#channel', users: { testbot: '@' }, mode: '+ntbKF', modeParams: { F: [], K: [], b: ['*!*@AN.IP.1', '*!*@AN.IP.3'], n: [], t: [] } }
];

mock.server.on('connection', function() {
mock.send(':localhost 001 testbot :Welcome!\r\n');
});
mock.server.on('connection', function() { mock.greet(); });

client.on('registered', function() {
mock.send(':localhost 005 testbot MODES=12 CHANTYPES=# PREFIX=(ohv)@%+ CHANMODES=beIqa,kfL,lj,psmntirRcOAQKVCuzNSMTGHFEB\r\n');
Expand Down
4 changes: 1 addition & 3 deletions test/test-quit.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ test('connect and quit with message', function(t) {

t.plan(expected.sent.length + expected.received.length + 1);

mock.server.on('connection', function() {
mock.send(':localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n');
});
mock.server.on('connection', function() { mock.greet(); });

client.on('registered', function() {
t.equal(mock.outgoing[0], expected.received[0][0], expected.received[0][1]);
Expand Down
6 changes: 2 additions & 4 deletions test/test-reconnect.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var testHelpers = require('./helpers');

mock.server.on('connection', function(c) {
conns.push(c);
mock.send(':localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n');
mock.greet();
});

var firstTime = function() {
Expand Down Expand Up @@ -73,9 +73,7 @@ test('it disallows double connections', function(t) {

var count = 0;

mock.server.on('connection', function() {
mock.send(':localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n');
});
mock.server.on('connection', function() { mock.greet(); });

client.on('registered', function() {
var oldConn = client.conn;
Expand Down
71 changes: 68 additions & 3 deletions test/test-user-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ test('joins, parts, renicks and quits', function(t) {
];
var actual = [];

mock.server.on('connection', function() {
mock.send(':localhost 001 testbot :Welcome to the Internet Relay Chat Network testbot\r\n');
});
mock.server.on('connection', function() { mock.greet(); });

client.on('registered', function() {
// welcome bot, give relevant prefix symbols
Expand Down Expand Up @@ -90,3 +88,70 @@ test('joins, parts, renicks and quits', function(t) {
t.end();
});
});

var withKickSetup = function(t, client, mock, performKicks, onMockClose) {
// onMockClose receives a parameter of the number of joins that occurred.
mock.server.on('connection', function() { mock.greet(); });

var joinCount = 0;
// prep test to cause client to disconnect on 'endtest' ping
mock.on('line', function(line) {
if (line.indexOf("JOIN") >= 0) joinCount++;
if (line === 'PING endtest') client.disconnect();
});

client.on('registered', function() {
// #test: testbot joins, users: testbot, user1, user2
client.join('#test');
mock.send(':testbot!~testbot@EXAMPLE.HOST JOIN :#test\r\n')
mock.send(':localhost 353 testbot = #test :testbot @user1 user2\r\n');
mock.send(':localhost 366 testbot #test :End of /NAMES list.\r\n');

performKicks();
});

client.on('kick', function() {
t.ok(true, 'client must receive kick');
client.send('PING', 'endtest');
});

mock.on('end', function() {
mock.close(function(){ onMockClose(joinCount); });
});
};

test ('does not rejoin after kick when config disabled', function(t) {
var mock = testHelpers.MockIrcd();
var client = new irc.Client('localhost', 'testbot', {debug: true, autoRejoin: false});

withKickSetup(t, client, mock, function() {
mock.send(':user1!~user1@example.host KICK #test testbot\r\n');
}, function(joinCount) {
t.equal(joinCount, 1, 'server must receive just one join');
t.end();
});
});

test ('rejoins when kicked', function(t) {
var mock = testHelpers.MockIrcd();
var client = new irc.Client('localhost', 'testbot', {debug: true, autoRejoin: true});

withKickSetup(t, client, mock, function() {
mock.send(':user1!~user1@example.host KICK #test testbot\r\n');
}, function(joinCount) {
t.equal(joinCount, 2, 'server must receive two joins');
t.end();
});
});

test ('only rejoins when self kicked', function(t) {
var mock = testHelpers.MockIrcd();
var client = new irc.Client('localhost', 'testbot', {debug: true, autoRejoin: true});

withKickSetup(t, client, mock, function() {
mock.send(':user1!~user1@example.host KICK #test test2\r\n');
}, function(joinCount) {
t.equal(joinCount, 1, 'server must receive just one join');
t.end();
});
});