Browse Source

Fix nickname handling

IRC doesn't send an answer when nickname is changed. It only sends a
message back on error.
feature/user
Sheogorath 6 years ago
parent
commit
08125c3788
No known key found for this signature in database GPG Key ID: 1F05CC3635CDDFFD
  1. 1
      src/server.js
  2. 24
      test/command_nick.js

1
src/server.js

@ -32,7 +32,6 @@ server.create = function create() {
// nick collision test
if (!Object.keys(userlist).includes(nickname)) {
user.setNickname(nickname)
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.")
userlist[user.nickname] = user
} else {
socket.write(ERR_NICKNAMEINUSE, " nickname in use")

24
test/command_nick.js

@ -3,7 +3,7 @@ const EventEmitter = require('events');
const IRCServer = require("../src/server.js");
describe("NICK OK", function () {
it("should handle a NICK command -> NICK some_nickname", function (done) {
it("should handle a NICK command -> NICK some_nickname", function () {
const server = IRCServer.create()
let mockedSock = new EventEmitter()
mockedSock.write = function (data) {
@ -16,22 +16,32 @@ describe("NICK OK", function () {
server.emit("connection", mockedSock)
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
assert.deepEqual(Object.keys(server.getUserlist()), ["some_nick"]);
})
})
describe("NICK already registered", function () {
it("should handle a NICK command -> NICK some_nickname", function (done) {
const server = IRCServer.create()
let mockedSock = new EventEmitter()
mockedSock.write = function (data) {
let mockedSock1 = new EventEmitter()
mockedSock1.write = function (data) {
done("send data to wrong socket")
}
mockedSock1.destroy = function () {
done("Destroyed socket without answering")
}
let mockedSock2 = new EventEmitter()
mockedSock2.write = function (data) {
assert.equal(data.toString("ascii"), "433")
done()
}
mockedSock.destroy = function () {
mockedSock2.destroy = function () {
done("Destroyed socket without answering")
}
server.emit("connection", mockedSock)
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
server.emit("connection", mockedSock1)
server.emit("connection", mockedSock2)
mockedSock1.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
mockedSock2.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
})
})
describe("NICK no NICK given", function () {
@ -49,4 +59,4 @@ describe("NICK no NICK given", function () {
server.emit("connection", mockedSock)
mockedSock.emit('data', Buffer.from("NICK \r\n", "ascii"))
})
})
})
Loading…
Cancel
Save