Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

...
  • 3 commits
  • 12 files changed
  • 0 commit comments
  • 1 contributor
7 History.md
View
@@ -1,3 +1,10 @@
+0.0.15 / 2012-07-04
+
+ * Default channels (Sebastian A. Espindola)
+ * Migrated tests to Mocha
+ * Tested against Node 0.8
+ * Locked down module versions
+
0.0.14 / 2012-06-05
* Added connection passwords (PASS)
2  Makefile
View
@@ -1,4 +1,4 @@
test:
- ./node_modules/.bin/nodeunit test/*.test.js
+ ./node_modules/.bin/mocha --reporter list -c --ui exports test/*.test.js
.PHONY: test
1  README.textile
View
@@ -83,4 +83,3 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see "http://www.gnu.org/licenses/":http://www.gnu.org/licenses/.
-
26 lib/server.js
View
@@ -34,8 +34,7 @@ var net = require('net'),
EventEmitter = require('events').EventEmitter,
serverCommands = require('./commands'),
winston = require('winston'),
- commander = require('commander'),
- server;
+ commander = require('commander');
function AbstractConnection(stream) {
this.stream = stream;
@@ -142,10 +141,10 @@ Server.prototype = {
},
valueExists: function(value, collection, field) {
- var context = this;
- value = context.normalizeName(value);
+ var self = this;
+ value = this.normalizeName(value);
return collection.some(function(u) {
- return context.normalizeName(u[field]) === value;
+ return self.normalizeName(u[field]) === value;
})
},
@@ -204,11 +203,11 @@ Server.prototype = {
},
createDefaultChannels: function() {
- var context = this;
+ var self = this;
if (this.config.channels) {
Object.keys(this.config.channels).forEach(function(channel) {
- var newChan = context.channels.registered[context.normalizeName(channel)] = new Channel(channel, context);
- newChan.topic = context.config.channels[channel].topic;
+ var newChannel = self.channels.registered[self.normalizeName(channel)] = new Channel(channel, self);
+ newChannel.topic = self.config.channels[channel].topic;
});
}
},
@@ -239,19 +238,18 @@ Server.prototype = {
},
start: function(callback) {
- var server = this;
+ var server = this, key, cert, options;
if (this.config.key && this.config.cert) {
try {
- var key = fs.readFileSync(this.config.key);
- var cert = fs.readFileSync(this.config.cert);
+ key = fs.readFileSync(this.config.key);
+ cert = fs.readFileSync(this.config.cert);
} catch (exception) {
winston.error('Fatal error:', exception);
}
- var options = { key: key, cert: cert };
+ options = { key: key, cert: cert };
this.server = tls.createServer(options, handleStream);
- }
- else {
+ } else {
this.server = net.createServer(handleStream);
}
10 package.json
View
@@ -1,7 +1,7 @@
{
"name": "ircdjs",
"description": "An IRCD for Node",
- "version": "0.0.14",
+ "version": "0.0.15",
"homepage": "https://github.com/alexyoung/ircd.js",
"author": "Alex R. Young (http://alexyoung.org)",
"directories": {
@@ -19,12 +19,12 @@
"dependencies": {
"carrier": ">= 0.0.3",
"bcrypt": ">= 0.4.0",
- "winston": "latest",
- "commander": "latest"
+ "winston": "0.6.1",
+ "commander": "git://github.com/visionmedia/commander.js.git"
},
"devDependencies": {
- "nodeunit": "0.6.2",
- "irc": "latest"
+ "mocha": "1.2.2",
+ "irc": "0.3.4"
},
"bin": {
"ircdjs-pwgen": "bin/pwgen.js",
295 test/channels.test.js
View
@@ -1,169 +1,182 @@
-var assert = require('assert'),
- helpers = require('./helpers'),
- createClient = helpers.createClient,
- testCase = require('nodeunit').testCase;
+var assert = require('assert')
+ , helpers = require('./helpers')
+ ;
module.exports = {
- setUp: function(done) {
- helpers.createServer(done);
- },
-
- tearDown: function(done) {
- helpers.close(done);
- },
-
- 'test bad join (#22)': function(test) {
- // Create two clients
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
-
- testbot1.on('error', function(message) {
- if (message.command === 'err_needmoreparams') {
- testbot1.disconnect();
- testbot2.disconnect();
- test.done();
- }
- });
+ 'Channels': {
+ beforeEach: function(done) {
+ this.server = new helpers.MockServer(done, false, 6660);
+ },
- testbot1.on('raw', function(data) {
- if (data.command === 'JOIN') {
- testbot1.send('join');
- }
+ afterEach: function(done) {
+ this.server.close(done);
+ },
+
+ 'test bad join (#22)': function(done) {
+ // Create two clients
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
+
+ testbot1.on('error', function(message) {
+ if (message.command === 'err_needmoreparams') {
+ testbot1.disconnect();
+ testbot2.disconnect();
+ done();
+ }
+ });
+
+ testbot1.on('raw', function(data) {
+ if (data.command === 'JOIN') {
+ testbot1.send('join');
+ }
+ });
});
});
- });
- },
-
- 'test messaging a non-existent channel (#26)': function(test) {
- // Create two clients
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
- testbot1.on('error', function(message) {
- if (message.command === 'err_nosuchnick') {
- testbot1.disconnect();
- testbot2.disconnect();
- test.done();
- }
+ },
+
+ 'test messaging a non-existent channel (#26)': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ // Create two clients
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
+ testbot1.on('error', function(message) {
+ if (message.command === 'err_nosuchnick') {
+ testbot1.disconnect();
+ testbot2.disconnect();
+ done();
+ }
+ });
+
+ testbot1.say('#error', 'Hello');
});
-
- testbot1.say('#error', 'Hello');
});
- });
- },
-
- 'remove channels when the last person leaves (#25)': function(test) {
- // Create two clients
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- function done() {
- testbot1.disconnect();
- test.done();
- }
+ },
- var seenList = false;
+ 'remove channels when the last person leaves (#25)': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
- testbot1.on('raw', function(data) {
- // Double equal, because this is returned as a string but could easily
- // be returned as an integer if the IRC client library changes
- if (data.rawCommand == 322) {
- if (seenList) {
- assert.fail('Channels should be deleted');
- } else {
- assert.equal(data.args[1], '#test', 'The #test channel should be returned by LIST');
-
- // Now part the channel
- testbot1.part('#test');
- }
- } else if (data.rawCommand == 323 && !seenList) {
- seenList = true;
- } else if (data.rawCommand == 323 && seenList) {
+ // Create two clients
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ function teardown() {
+ testbot1.disconnect();
done();
- } else if (data.command === 'PART') {
- testbot1.send('LIST');
}
- });
- // Send a list command
- testbot1.send('LIST');
- });
- },
+ var seenList = false;
- 'simultaneous user simulation': function(test) {
- var nicks = [], i;
- for (i = 1; i <= 100; i++) {
- nicks.push('user_' + i);
- }
-
- function assertReceive(bots, assertion, fn) {
- bots[0].say(bots[1].nick, assertion);
+ testbot1.on('raw', function(data) {
+ // Double equal, because this is returned as a string but could easily
+ // be returned as an integer if the IRC client library changes
+ if (data.rawCommand == 322) {
+ if (seenList) {
+ assert.fail('Channels should be deleted');
+ } else {
+ assert.equal(data.args[1], '#test', 'The #test channel should be returned by LIST');
+
+ // Now part the channel
+ testbot1.part('#test');
+ }
+ } else if (data.rawCommand == 323 && !seenList) {
+ seenList = true;
+ } else if (data.rawCommand == 323 && seenList) {
+ teardown();
+ } else if (data.command === 'PART') {
+ testbot1.send('LIST');
+ }
+ });
- var callback = function(from, to, message) {
- assert.equal(assertion, message);
- bots[1].removeListener('message', callback);
- fn();
- };
+ // Send a list command
+ testbot1.send('LIST');
+ });
+ },
- bots[1].on('message', callback);
- }
+ 'simultaneous user simulation': function(done) {
+ var nicks = [], i;
- helpers.createClients(nicks, '#test', function(bots) {
- function done() {
- bots.forEach(function(bot) {
- bot.disconnect();
- });
- test.done();
+ for (i = 1; i <= 100; i++) {
+ nicks.push('user_' + i);
}
- var tested = 0, max = bots.length - 1;
- for (var i = 0; i < max; i++) {
- assertReceive([bots[i], bots[i + 1]], 'Message ' + Math.random(), function() {
- tested++;
- if (tested === max) {
- done();
- }
- });
+ function assertReceive(bots, assertion, fn) {
+ bots[0].say(bots[1].nick, assertion);
+
+ var callback = function(from, to, message) {
+ assert.equal(assertion, message);
+ bots[1].removeListener('message', callback);
+ fn();
+ };
+
+ bots[1].on('message', callback);
}
- });
- },
-
- 'test join with invalid key': function(test) {
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- // Set the channel key to 'test'
- testbot1.send('MODE #test +k test');
- testbot1.on('raw', function(data) {
- if (data.rawCommand === '324') {
- createClient({ nick: 'testbot2', channel: '#test2' }, function(testbot2) {
- testbot2.on('error', function(message) {
- assert.equal(message.rawCommand, '475', 'Should receive a bad channel key');
- testbot1.disconnect();
- testbot2.disconnect();
- test.done();
- });
-
- // Join without the correct key
- testbot2.send('JOIN #test');
+
+ this.server.createClients(nicks, '#test', function(bots) {
+ function teardown() {
+ bots.forEach(function(bot) {
+ bot.disconnect();
+ });
+ done();
+ }
+
+ var tested = 0, max = bots.length - 1;
+ for (var i = 0; i < max; i++) {
+ assertReceive([bots[i], bots[i + 1]], 'Message ' + Math.random(), function() {
+ tested++;
+ if (tested === max) {
+ teardown();
+ }
});
}
});
- });
- },
-
- 'test join with valid key': function(test) {
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- // Set the channel key to 'password'
- testbot1.send('MODE #test +k password');
- testbot1.on('raw', function(data) {
- if (data.rawCommand === '324') {
- createClient({ nick: 'testbot2', channel: '#test password' }, function(testbot2) {
- testbot2.on('raw', function(data) {
- if (data.rawCommand === '324') {
+ },
+
+ 'test join with invalid key': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ // Set the channel key to 'test'
+ testbot1.send('MODE #test +k test');
+ testbot1.on('raw', function(data) {
+ if (data.rawCommand === '324') {
+ createClient({ nick: 'testbot2', channel: '#test2' }, function(testbot2) {
+ testbot2.on('error', function(message) {
+ assert.equal(message.rawCommand, '475', 'Should receive a bad channel key');
testbot1.disconnect();
testbot2.disconnect();
- test.done();
- }
+
+ done();
+ });
+
+ // Join without the correct key
+ testbot2.send('JOIN #test');
});
- });
- }
+ }
+ });
+ });
+ },
+
+ 'test join with valid key': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'testbotv', channel: '#test' }, function(testbot1) {
+ // Set the channel key to 'password'
+ testbot1.send('MODE #test +k password');
+ testbot1.on('raw', function(data) {
+ if (data.rawCommand === '324') {
+ createClient({ nick: 'testbot2', channel: '#test password' }, function(testbot2) {
+ testbot2.on('raw', function(data) {
+ if (data.rawCommand === '324') {
+ testbot1.disconnect();
+ testbot2.disconnect();
+ done();
+ }
+ });
+ });
+ }
+ });
});
- });
+ }
}
};
319 test/clients.test.js
View
@@ -1,173 +1,190 @@
-var assert = require('assert'),
- helpers = require('./helpers.js'),
- createClient = helpers.createClient,
- testCase = require('nodeunit').testCase;
+var assert = require('assert')
+ , helpers = require('./helpers.js')
+ ;
module.exports = {
- setUp: function(done) {
- helpers.createServer(done);
- },
-
- tearDown: function(done) {
- helpers.close(done);
- },
-
- 'test valid WHOIS': function(test) {
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
- testbot1.on('raw', function(data) {
- if (data.command === 'JOIN') {
- testbot1.send('WHOIS', 'testbot2');
- } else if (data.command === 'rpl_whoisuser') {
- assert.equal('testbot2', data.args[1]);
- testbot1.disconnect();
- testbot2.disconnect();
- test.done();
- }
+ 'Clients': {
+ beforeEach: function(done) {
+ this.server = new helpers.MockServer(done, false, 6661);
+ },
+
+ afterEach: function(done) {
+ this.server.close(done);
+ },
+
+ 'test valid WHOIS': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
+ testbot1.on('raw', function(data) {
+ if (data.command === 'JOIN') {
+ testbot1.send('WHOIS', 'testbot2');
+ } else if (data.command === 'rpl_whoisuser') {
+ assert.equal('testbot2', data.args[1]);
+ testbot1.disconnect();
+ testbot2.disconnect();
+ done();
+ }
+ });
});
});
- });
- },
-
- 'valid WHO': function(test) {
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
- testbot1.on('raw', function(data) {
- if (data.command === 'rpl_endofwho') {
- assert.equal('#test', data.args[1]);
- testbot1.disconnect();
- testbot2.disconnect();
- test.done();
- }
+ },
+
+ 'valid WHO': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
+ testbot1.on('raw', function(data) {
+ if (data.command === 'rpl_endofwho') {
+ assert.equal('#test', data.args[1]);
+ testbot1.disconnect();
+ testbot2.disconnect();
+ done();
+ }
+ });
+ testbot1.send('WHO', '#test');
+ });
+ });
+ },
+
+ 'invalid WHO (bug #9)': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
+ testbot1.addListener('error', function(message) {
+ if (message.command === 'err_nosuchchannel') {
+ testbot1.disconnect();
+ testbot2.disconnect();
+ done();
+ }
+ });
+
+ testbot1.send('WHO', '#argh');
});
- testbot1.send('WHO', '#test');
});
- });
- },
-
- 'invalid WHO (bug #9)': function(test) {
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
- testbot1.addListener('error', function(message) {
- if (message.command === 'err_nosuchchannel') {
+ },
+
+ 'socket error handling (bug #10)': function(done) {
+ var createClient = this.server.createClient.bind(this.server)
+ , server = this.server.server;
+
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
+ var user = server.users.registered.filter(function(user) { return user.nick == testbot2.nick; })[0];
+
+ // Simulate a socket issue by causing user.send to raise an exception
+ user.stream = 'bad';
+ testbot2.send('WHO', '#test');
+
+ setTimeout(function() {
+ // There should now be one user instead of two in the channel
+ assert.equal(1, server.channels.registered['#test'].users.length);
testbot1.disconnect();
testbot2.disconnect();
- test.done();
- }
+ done();
+ }, 10);
});
-
- testbot1.send('WHO', '#argh');
});
- });
- },
-
- 'socket error handling (bug #10)': function(test) {
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- createClient({ nick: 'testbot2', channel: '#test' }, function(testbot2) {
- var user = helpers.server().users.registered.filter(function(user) { return user.nick == testbot2.nick; })[0];
-
- // Simulate a socket issue by causing user.send to raise an exception
- user.stream = 'bad';
- testbot2.send('WHO', '#test');
-
- setTimeout(function() {
- // There should now be one user instead of two in the channel
- assert.equal(1, helpers.server().channels.registered['#test'].users.length);
- testbot1.disconnect();
- testbot2.disconnect();
- test.done();
- }, 10);
- });
- });
- },
-
- "users shouldn't be able to join channel twice (bug #12)": function(test) {
- createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
- testbot1.join('#test', function() {
- setTimeout(function() {
- assert.equal(helpers.server().channels.registered['#test'].users.length, 1);
- testbot1.disconnect();
- test.done();
- }, 10);
- });
- });
- },
-
- 'invalid ban mask (bug #19)': function(test) {
- createClient({ nick: 'huey', channel: '#aff' }, function(huey) {
- huey.send('MODE', '#aff', '+b');
- huey.on('error', function(data) {
- if (data.command === 'err_needmoreparams') {
- createClient({ nick: 'dewey', channel: '#aff' }, function(dewey) {
- huey.disconnect();
- dewey.disconnect();
- test.done();
- });
- }
+ },
+
+ "users shouldn't be able to join channel twice (bug #12)": function(done) {
+ var createClient = this.server.createClient.bind(this.server)
+ , server = this.server.server;
+
+ createClient({ nick: 'testbot1', channel: '#test' }, function(testbot1) {
+ testbot1.join('#test', function() {
+ setTimeout(function() {
+ assert.equal(server.channels.registered['#test'].users.length, 1);
+ testbot1.disconnect();
+ done();
+ }, 10);
+ });
});
- });
- },
-
- 'invalid away status (bug #18)': function(test) {
- createClient({ nick: 'huey', channel: '#aff' }, function(huey) {
- var dewey;
-
- huey.send('AWAY');
- huey.on('message', function(from, to, message) {
- assert.equal('dewey', from);
- assert.equal('huey', to);
- assert.equal('Hello', message);
- huey.disconnect();
- dewey.disconnect();
- test.done();
+ },
+
+ 'invalid ban mask (bug #19)': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'huey', channel: '#aff' }, function(huey) {
+ huey.send('MODE', '#aff', '+b');
+ huey.on('error', function(data) {
+ if (data.command === 'err_needmoreparams') {
+ createClient({ nick: 'dewey', channel: '#aff' }, function(dewey) {
+ huey.disconnect();
+ dewey.disconnect();
+ done();
+ });
+ }
+ });
});
+ },
+
+ 'invalid away status (bug #18)': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+
+ createClient({ nick: 'huey', channel: '#aff' }, function(huey) {
+ var dewey;
+
+ huey.send('AWAY');
+ huey.on('message', function(from, to, message) {
+ assert.equal('dewey', from);
+ assert.equal('huey', to);
+ assert.equal('Hello', message);
+ huey.disconnect();
+ dewey.disconnect();
+ done();
+ });
- huey.on('error', function(data) {
- if (data.command === 'err_needmoreparams') {
- createClient({ nick: 'dewey', channel: '#aff' }, function(client) {
- dewey = client;
- dewey.say('huey', 'Hello');
- });
- }
+ huey.on('error', function(data) {
+ if (data.command === 'err_needmoreparams') {
+ createClient({ nick: 'dewey', channel: '#aff' }, function(client) {
+ dewey = client;
+ dewey.say('huey', 'Hello');
+ });
+ }
+ });
});
- });
- },
+ },
- 'simultaneous user simulation': function(test) {
- var nicks = [], i;
- for (i = 1; i <= 10; i++) {
- nicks.push('user_' + i);
- }
+ 'simultaneous user simulation': function(done) {
+ var nicks = [], i;
+ for (i = 1; i <= 10; i++) {
+ nicks.push('user_' + i);
+ }
- function assertReceive(bots, assertion, fn) {
- bots[0].say(bots[1].nick, assertion);
+ function assertReceive(bots, assertion, fn) {
+ bots[0].say(bots[1].nick, assertion);
- var callback = function(from, to, message) {
- assert.equal(assertion, message);
- bots[1].removeListener('message', callback);
- fn();
- };
+ var callback = function(from, to, message) {
+ assert.equal(assertion, message);
+ bots[1].removeListener('message', callback);
+ fn();
+ };
- bots[1].addListener('message', callback);
- }
-
- helpers.createClients(nicks, '#test', function(bots) {
- function done() {
- bots.forEach(function(bot) {
- bot.disconnect();
- });
- test.done();
+ bots[1].addListener('message', callback);
}
- var tested = 0, max = bots.length - 1;
- for (var i = 0; i < max; i++) {
- assertReceive([bots[i], bots[i + 1]], 'Message ' + Math.random(), function() {
- tested++;
- if (tested === max) {
- done();
- }
- });
- }
- });
+ this.server.createClients(nicks, '#test', function(bots) {
+ function teardown() {
+ bots.forEach(function(bot) {
+ bot.disconnect();
+ });
+ done();
+ }
+
+ var i, tested = 0, max = bots.length - 1;
+ for (i = 0; i < max; i++) {
+ assertReceive([bots[i], bots[i + 1]], 'Message ' + Math.random(), function() {
+ tested++;
+ if (tested === max) {
+ teardown();
+ }
+ });
+ }
+ });
+ }
}
};
94 test/helpers.js
View
@@ -1,16 +1,15 @@
-var path = require('path'),
- Server = require(path.join(__dirname, '..', 'lib', 'server')).Server,
- irc = require('irc'),
- winston = require('winston'),
- port = 6711,
- server;
+var path = require('path')
+ , Server = require(path.join(__dirname, '..', 'lib', 'server')).Server
+ , irc = require('irc')
+ , winston = require('winston')
+ ;
winston.remove(winston.transports.Console);
-function createServer(test, usepass) {
- server = new Server();
- server.showLog = false;
- server.config = {
+function MockServer(done, usepass, port) {
+ this.server = new Server();
+ this.server.showLog = false;
+ this.server.config = {
'network': 'ircn',
'hostname': 'localhost',
'serverDescription': 'A Node IRC daemon',
@@ -24,51 +23,54 @@ function createServer(test, usepass) {
};
if (usepass) {
- server.config.serverPassword = '$2a$10$T1UJYlinVUGHqfInKSZQz./CHrYIVVqbDO3N1fRNEUvFvSEcshNdC';
+ this.server.config.serverPassword = '$2a$10$T1UJYlinVUGHqfInKSZQz./CHrYIVVqbDO3N1fRNEUvFvSEcshNdC';
}
- server.start(test);
+ this.server.start(done);
}
-function createClient(options, fn) {
- var ranCallback = false,
- client = new irc.Client('localhost', options.nick, {
- channels: [options.channel],
- port: port,
- debug: false,
- password: options.password
- });
+MockServer.prototype = {
+ close: function(done) {
+ this.server.close(done);
+ },
- client.addListener('join', function() {
- if (!ranCallback) {
- fn(client);
- ranCallback = true;
- }
- });
-}
+ createClient: function(options, fn) {
+ options.port = this.server.config.port;
-function createClients(nicks, channel, fn) {
- var connected = [];
+ var ranCallback = false
+ , client = new irc.Client('localhost', options.nick, {
+ channels: [options.channel]
+ , port: options.port
+ , debug: false
+ , password: options.password
+ });
- nicks.forEach(function(nick) {
- createClient({ nick: nick, channel: channel }, function(bot) {
- connected.push(bot);
- if (connected.length == nicks.length) {
- fn(connected);
+ client.addListener('join', function() {
+ if (!ranCallback) {
+ fn(client);
+ ranCallback = true;
}
});
- });
-}
+ },
+
+ createClients: function(nicks, channel, fn) {
+ var connected = []
+ , createClient = this.createClient.bind(this);
+
+ nicks.forEach(function(nick) {
+ createClient({ nick: nick, channel: channel }, function(bot) {
+ connected.push(bot);
+ if (connected.length == nicks.length) {
+ fn(connected);
+ }
+ });
+ });
+ }
+};
module.exports = {
- createServer: createServer,
- createClient: createClient,
- createClients: createClients,
- close: function(fn) {
- server.close(fn);
- },
- server: function() {
- return server;
- },
- port: port
+ MockServer: MockServer
+, createServer: function(usepass, port, fn) {
+ var server = new MockServer(function() { fn(server); }, usepass, port);
+ }
};
118 test/protocol.test.js
View
@@ -1,67 +1,71 @@
-var path = require('path'),
- assert = require('assert'),
- protocol = require(path.join(__dirname, '..', 'lib', 'protocol')),
- invalidNick = protocol.validations.invalidNick,
- invalidChannel = protocol.validations.invalidChannel,
- invalidChannelKey = protocol.validations.invalidChannelKey;
+var path = require('path')
+ , assert = require('assert')
+ , protocol = require(path.join(__dirname, '..', 'lib', 'protocol'))
+ , invalidNick = protocol.validations.invalidNick
+ , invalidChannel = protocol.validations.invalidChannel
+ , invalidChannelKey = protocol.validations.invalidChannelKey
+ ;
-exports['nickname validation'] = function(test) {
- // Valid nicknames
- test.strictEqual('alexyoung'.match(invalidNick), null);
- test.strictEqual('AbC123'.match(invalidNick), null);
- test.strictEqual('a{b[}]'.match(invalidNick), null);
+module.exports = {
+ 'Protocol': {
+ 'test nickname validation': function(done) {
+ // Valid nicknames
+ assert.strictEqual('alexyoung'.match(invalidNick), null);
+ assert.strictEqual('AbC123'.match(invalidNick), null);
+ assert.strictEqual('a{b[}]'.match(invalidNick), null);
- // Invalid nicknames
- // Nicknames shall not contain some special characters
- test.notStrictEqual('abc#'.match(invalidNick), null);
- test.notStrictEqual('abc*defg'.match(invalidNick), null);
- test.notStrictEqual('abc~'.match(invalidNick), null);
- test.notStrictEqual('a\0a'.match(invalidNick), null, 'NULL');
- test.notStrictEqual('abc\ndefg'.match(invalidNick), null, 'LF');
- test.notStrictEqual('abc\7xyz'.match(invalidNick), null, 'BELL');
+ // Invalid nicknames
+ // Nicknames shall not contain some special characters
+ assert.notStrictEqual('abc#'.match(invalidNick), null);
+ assert.notStrictEqual('abc*defg'.match(invalidNick), null);
+ assert.notStrictEqual('abc~'.match(invalidNick), null);
+ assert.notStrictEqual('a\0a'.match(invalidNick), null, 'NULL');
+ assert.notStrictEqual('abc\ndefg'.match(invalidNick), null, 'LF');
+ assert.notStrictEqual('abc\7xyz'.match(invalidNick), null, 'BELL');
- // Invalid nicknames
- // RFC1459 says nicks must start with a letter
- // https://github.com/alexyoung/ircd.js/blob/5d7443847311d4d6d1ff7371fa1fdee021315b0f/doc/rfc1459.txt#L492
- test.notStrictEqual('9abc'.match(protocol.validations.invalidNick), null, 'starting with a digit');
- test.notStrictEqual('^abc123'.match(protocol.validations.invalidNick), null, 'starting with a special character');
+ // Invalid nicknames
+ // RFC1459 says nicks must start with a letter
+ // https://github.com/alexyoung/ircd.js/blob/5d7443847311d4d6d1ff7371fa1fdee021315b0f/doc/rfc1459.txt#L492
+ assert.notStrictEqual('9abc'.match(protocol.validations.invalidNick), null, 'starting with a digit');
+ assert.notStrictEqual('^abc123'.match(protocol.validations.invalidNick), null, 'starting with a special character');
- test.done();
-};
-
-exports['channelname validation'] = function(test) {
- // Valid channelnames
- test.strictEqual('node.js'.match(invalidChannel), null);
- test.strictEqual('#9'.match(invalidChannel), null);
- test.strictEqual('bla\u01D2'.match(invalidChannel), null, 'random 8 bit character');
+ done();
+ },
- // Invalid channelnames
- // https://github.com/alexyoung/ircd.js/blob/5d7443847311d4d6d1ff7371fa1fdee021315b0f/doc/rfc1459.txt#L494
- test.notStrictEqual('word1 word2'.match(invalidChannel), null, 'SPACE');
- test.notStrictEqual('ring\x07'.match(invalidChannel), null, 'BELL');
- test.notStrictEqual('zero\x00'.match(invalidChannel), null, 'NUL');
- test.notStrictEqual('word\rword'.match(invalidChannel), null, 'CR');
- test.notStrictEqual('word\nword'.match(invalidChannel), null, 'LF');
- test.notStrictEqual('first,secound,third'.match(invalidChannel), null, 'Comma (,)');
+ 'test channelname validation': function(done) {
+ // Valid channelnames
+ assert.strictEqual('node.js'.match(invalidChannel), null);
+ assert.strictEqual('#9'.match(invalidChannel), null);
+ assert.strictEqual('bla\u01D2'.match(invalidChannel), null, 'random 8 bit character');
- test.done();
-}
+ // Invalid channelnames
+ // https://github.com/alexyoung/ircd.js/blob/5d7443847311d4d6d1ff7371fa1fdee021315b0f/doc/rfc1459.txt#L494
+ assert.notStrictEqual('word1 word2'.match(invalidChannel), null, 'SPACE');
+ assert.notStrictEqual('ring\x07'.match(invalidChannel), null, 'BELL');
+ assert.notStrictEqual('zero\x00'.match(invalidChannel), null, 'NUL');
+ assert.notStrictEqual('word\rword'.match(invalidChannel), null, 'CR');
+ assert.notStrictEqual('word\nword'.match(invalidChannel), null, 'LF');
+ assert.notStrictEqual('first,secound,third'.match(invalidChannel), null, 'Comma (,)');
-exports['channelkey validation'] = function(test) {
- // Valid channelkeys
- test.strictEqual('key'.match(invalidChannelKey), null);
- test.strictEqual('key*'.match(invalidChannelKey), null);
+ done();
+ },
- // Invalid channelkeys
- // any 7-bit US_ASCII character is valid, except NUL, CR, LF, FF, h/v TABs, and " "
- test.notStrictEqual('bla\u01D2'.match(invalidChannelKey), null, 'random 8 bit character');
- test.notStrictEqual('zero\x00'.match(invalidChannelKey), null, 'NUL');
- test.notStrictEqual('word\rword'.match(invalidChannelKey), null, 'CR');
- test.notStrictEqual('word\nword'.match(invalidChannelKey), null, 'LF');
- test.notStrictEqual('word\x0C'.match(invalidChannelKey), null, 'FF');
- test.notStrictEqual('horizontal\x09vertical\x0B'.match(invalidChannelKey), null, 'tabs');
- test.notStrictEqual('space s'.match(invalidChannelKey), null, 'SPACE')
+ 'test channelkey validation': function(done) {
+ // Valid channelkeys
+ assert.strictEqual('key'.match(invalidChannelKey), null);
+ assert.strictEqual('key*'.match(invalidChannelKey), null);
- test.done();
-}
+ // Invalid channelkeys
+ // any 7-bit US_ASCII character is valid, except NUL, CR, LF, FF, h/v TABs, and " "
+ assert.notStrictEqual('bla\u01D2'.match(invalidChannelKey), null, 'random 8 bit character');
+ assert.notStrictEqual('zero\x00'.match(invalidChannelKey), null, 'NUL');
+ assert.notStrictEqual('word\rword'.match(invalidChannelKey), null, 'CR');
+ assert.notStrictEqual('word\nword'.match(invalidChannelKey), null, 'LF');
+ assert.notStrictEqual('word\x0C'.match(invalidChannelKey), null, 'FF');
+ assert.notStrictEqual('horizontal\x09vertical\x0B'.match(invalidChannelKey), null, 'tabs');
+ assert.notStrictEqual('space s'.match(invalidChannelKey), null, 'SPACE')
+ done();
+ }
+ }
+};
38 test/server.test.js
View
@@ -1,25 +1,27 @@
-var assert = require('assert'),
- helpers = require('./helpers.js'),
- createClient = helpers.createClient,
- testCase = require('nodeunit').testCase;
+var assert = require('assert')
+ , helpers = require('./helpers.js')
+ ;
module.exports = {
- setUp: function(done) {
- helpers.createServer(done, true);
- },
+ 'Server': {
+ beforeEach: function(done) {
+ this.server = new helpers.MockServer(done, true, 6662);
+ },
- tearDown: function(done) {
- helpers.close(done);
- },
+ afterEach: function(done) {
+ this.server.close(done);
+ },
- 'test connection passwords': function(test) {
- createClient({ nick: 'testbot1', channel: '#test', password: 'test' }, function(testbot1) {
- testbot1.on('raw', function(data) {
- if (data.command === 'rpl_channelmodeis') {
- testbot1.disconnect();
- test.done();
- }
+ 'test connection passwords': function(done) {
+ var createClient = this.server.createClient.bind(this.server);
+ createClient({ nick: 'testbot1', channel: '#test', password: 'test' }, function(testbot1) {
+ testbot1.on('raw', function(data) {
+ if (data.command === 'rpl_channelmodeis') {
+ testbot1.disconnect();
+ done();
+ }
+ });
});
- });
+ }
}
};
57 test/sockets.test.js
View
@@ -1,32 +1,37 @@
-var assert = require('assert'),
- net = require('net'),
- helpers = require('./helpers'),
- testCase = require('nodeunit').testCase;
+var assert = require('assert')
+ , net = require('net')
+ , helpers = require('./helpers')
+ ;
module.exports = {
- setUp: function(done) {
- helpers.createServer(done);
- },
+ 'Sockets': {
+ beforeEach: function(done) {
+ this.server = new helpers.MockServer(done, false, 6663);
+ },
- tearDown: function(done) {
- helpers.close(done);
- },
+ afterEach: function(done) {
+ this.server.close(done);
+ },
- 'test destroy a socket': function(test) {
- var bob = net.createConnection(helpers.server().config.port, helpers.server().config.hostname);
- bob.write('garbage');
- process.nextTick(function() {
- bob.destroy();
- test.done();
- });
- },
-
- 'test send garbage': function(test) {
- var alice = net.createConnection(helpers.server().config.port, helpers.server().config.hostname);
- alice.write('NICK alice\n\x00\x07abc\r\uAAAA', 'ascii', function() {
- alice.end();
- test.done();
- });
+ 'test destroy a socket': function(done) {
+ var server = this.server.server
+ , bob = net.createConnection(server.config.port, server.config.hostname);
+
+ bob.write('garbage');
+ process.nextTick(function() {
+ bob.destroy();
+ done();
+ });
+ },
+
+ 'test send garbage': function(done) {
+ var server = this.server.server
+ , alice = net.createConnection(server.config.port, server.config.hostname);
+
+ alice.write('NICK alice\n\x00\x07abc\r\uAAAA', 'ascii', function() {
+ alice.end();
+ done();
+ });
+ }
}
};
-
28 test/user.test.js
View
@@ -1,19 +1,21 @@
-var assert = require('assert'),
- path = require('path'),
- User = require(path.join(__dirname, '..', 'lib', 'user')).User,
- testCase = require('nodeunit').testCase;
+var assert = require('assert')
+ , path = require('path')
+ , User = require(path.join(__dirname, '..', 'lib', 'user')).User
+ ;
module.exports = {
- 'test timeout calculation': function(test) {
- var server = {
- config: { idleTimeout: 60 }
- }
- , user = new User(null, server);
+ 'User': {
+ 'test timeout calculation': function(done) {
+ var server = {
+ config: { idleTimeout: 60 }
+ }
+ , user = new User(null, server);
- assert.ok(!user.hasTimedOut());
- user.lastPing = (Date.now() - 60001);
- assert.ok(user.hasTimedOut());
+ assert.ok(!user.hasTimedOut());
+ user.lastPing = (Date.now() - 60001);
+ assert.ok(user.hasTimedOut());
- test.done();
+ done();
+ }
}
};

No commit comments for this range

Something went wrong with that request. Please try again.