|
|
@ -4,21 +4,54 @@ 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() |
|
|
|
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 some_pass\r\n", "ascii")) |
|
|
|
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("some_pass", user["password"]) |
|
|
|
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")) |
|
|
|
|
|
|
|
}) |
|
|
|
}) |