15 Commits
8a00bf6cb8
...
f816cd1ada
8 changed files with 236 additions and 63 deletions
-
18README.md
-
3index.js
-
126src/server.js
-
11src/user.js
-
57test/command_pass.js
-
59test/command_privmsg.js
-
2test/command_user.js
-
23test/hexchat.js
@ -0,0 +1,18 @@ |
|||||
|
ircd-js |
||||
|
=== |
||||
|
|
||||
|
A simple IRCd project to provide an IRCd. |
||||
|
|
||||
|
Running |
||||
|
=== |
||||
|
|
||||
|
```bash |
||||
|
# Install all dev dependencies |
||||
|
npm install |
||||
|
|
||||
|
# Run mocha tests |
||||
|
npm test |
||||
|
|
||||
|
# Start the index.js |
||||
|
npm start |
||||
|
``` |
@ -0,0 +1,3 @@ |
|||||
|
const server = require("./src/server.js") |
||||
|
|
||||
|
server.create().listen(6667) |
@ -0,0 +1,57 @@ |
|||||
|
const assert = require('assert'); |
||||
|
const EventEmitter = require('events'); |
||||
|
const IRCServer = require("../src/server.js"); |
||||
|
|
||||
|
describe("PASS OK", function () { |
||||
|
it("should handle a PASS command -> PASS some_passwd", function (done) { |
||||
|
const server = IRCServer.create({ |
||||
|
password: "itsJustATest" |
||||
|
}) |
||||
|
let mockedSock = new EventEmitter() |
||||
|
|
||||
|
mockedSock.address = function() { |
||||
|
return { port: 12346, family: 'IPv4', address: '127.0.0.1' } |
||||
|
} |
||||
|
|
||||
|
mockedSock.write = function (data) { |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
mockedSock.destroy = function () { |
||||
|
done("Destroyed socket without answering") |
||||
|
} |
||||
|
|
||||
|
server.emit("connection", mockedSock) |
||||
|
mockedSock.emit('data', Buffer.from("PASS itsJustATest\r\n", "ascii")) |
||||
|
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
||||
|
mockedSock.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii")) |
||||
|
|
||||
|
user = server.getUserlist()["some_nick"] |
||||
|
assert.equal(user["registered"], true) |
||||
|
done() |
||||
|
}) |
||||
|
|
||||
|
it("should end connection on wrong password", function (done) { |
||||
|
const server = IRCServer.create({ |
||||
|
password: "itsJustATest" |
||||
|
}) |
||||
|
let mockedSock = new EventEmitter() |
||||
|
|
||||
|
mockedSock.address = function() { |
||||
|
return { port: 12346, family: 'IPv4', address: '127.0.0.1' } |
||||
|
} |
||||
|
|
||||
|
mockedSock.write = function (data) { |
||||
|
return |
||||
|
} |
||||
|
|
||||
|
mockedSock.destroy = function () { |
||||
|
// connection has to be destroyed
|
||||
|
done("") |
||||
|
} |
||||
|
|
||||
|
server.emit("connection", mockedSock) |
||||
|
mockedSock.emit('data', Buffer.from("PASS wrongpassword\r\n", "ascii")) |
||||
|
|
||||
|
}) |
||||
|
}) |
@ -0,0 +1,23 @@ |
|||||
|
const assert = require('assert'); |
||||
|
const EventEmitter = require('events'); |
||||
|
const IRCServer = require("../src/server.js"); |
||||
|
|
||||
|
describe("hexchat", function () { |
||||
|
it("should handle hexchat inital command list", function (done) { |
||||
|
const server = IRCServer.create() |
||||
|
let mockedSock = new EventEmitter() |
||||
|
mockedSock.address = function() { |
||||
|
return { port: 12346, family: 'IPv4', address: '127.0.0.1' } |
||||
|
} |
||||
|
mockedSock.write = function (data) { |
||||
|
assert.equal(data.toString("ascii"), ":irc.example.com 001 some_nick :Welcome to the example IRC Project some_nick!~guest@127.0.0.1\r\n") |
||||
|
done() |
||||
|
} |
||||
|
mockedSock.destroy = function () { |
||||
|
done("Destroyed socket without answering") |
||||
|
} |
||||
|
|
||||
|
server.emit("connection", mockedSock) |
||||
|
mockedSock.emit('data', Buffer.from("CAP LS 302\r\nNICK some_nick\r\nUSER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii")) |
||||
|
}) |
||||
|
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue