Browse Source
Feature: Provide correct error response code for missing nick
test/nick-command-no-param
Sheogorath
6 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
2 changed files with
20 additions and
3 deletions
-
src/server.js
-
test/server.js
|
|
@ -9,6 +9,7 @@ const ERR_UNKNOWNCOMMAND = '421' |
|
|
|
const ERR_ERRONEUSNICKNAME = '432' |
|
|
|
const ERR_NICKNAMEINUSE = '433' |
|
|
|
const ERR_NEEDMOREPARAMS = '461' |
|
|
|
const ERR_NONICKNAMEGIVEN = '431' |
|
|
|
|
|
|
|
let server = {} |
|
|
|
let registeredUserlist = require("../src/userlist.js") |
|
|
@ -29,17 +30,18 @@ server.create = function create() { |
|
|
|
if (tokenized[1]) { |
|
|
|
let nickname = tokenized[1] |
|
|
|
// nick collision test
|
|
|
|
console.log(Object.keys(registeredUserlist)); |
|
|
|
if (!Object.keys(registeredUserlist).includes(nickname)) { |
|
|
|
user.setNickname(nickname) |
|
|
|
registeredUserlist[nickname] = user |
|
|
|
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.") |
|
|
|
socket.write(RPL_WELCOME, " nick " + nickname + " succesfully added.\r\n") |
|
|
|
} else { |
|
|
|
socket.write(ERR_NICKNAMEINUSE, " nickname in use") |
|
|
|
socket.write(ERR_NICKNAMEINUSE, " nickname in use\r\n") |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
socket.write("ERROR: NO NICKNAME PROVIDED") |
|
|
|
socket.write(ERR_NONICKNAMEGIVEN, " :No nickname given\r\n") |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
@ -40,5 +40,20 @@ describe('IRC server', function() { |
|
|
|
server.emit("connection", mockedSock) |
|
|
|
mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii")) |
|
|
|
}) |
|
|
|
|
|
|
|
it("should send 431 on NICK command with no parameter -> NICK", function (done) { |
|
|
|
const server = IRCServer.create() |
|
|
|
let mockedSock = new EventEmitter() |
|
|
|
mockedSock.write = function (data) { |
|
|
|
assert.equal(data.toString("ascii"), "431") |
|
|
|
done() |
|
|
|
} |
|
|
|
mockedSock.destroy = function () { |
|
|
|
done("Destroyed socket without answering") |
|
|
|
} |
|
|
|
|
|
|
|
server.emit("connection", mockedSock) |
|
|
|
mockedSock.emit('data', Buffer.from("NICK\r\n", "ascii")) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |