Browse Source

Merge commit '16d708dfb9cd36b21c9becddcdc2f0797e66751e' into HEAD

develop
Jenkins 5 years ago
parent
commit
33835b7bfd
  1. 5
      src/server.js
  2. 23
      test/command_join.js

5
src/server.js

@ -92,7 +92,12 @@ server.create = function create(config = {}) {
break; break;
case "JOIN": case "JOIN":
if (!(tokenized[1].charAt(0) === "#")) {
socket.write(`:irc.example.com ${ERR_CANNOTSENDTOCHAN}: invalid channel name`)
break;
}
let channelname = tokenized[1] let channelname = tokenized[1]
if (Object.keys(channellist).includes(channelname)) { if (Object.keys(channellist).includes(channelname)) {
channellist[channelname].join(user) channellist[channelname].join(user)
} else { } else {

23
test/command_join.js

@ -25,6 +25,29 @@ describe("JOIN OK", function () {
mockedSock.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii")) mockedSock.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii"))
mockedSock.emit('data', Buffer.from("JOIN #testchan\r\n", "ascii")) mockedSock.emit('data', Buffer.from("JOIN #testchan\r\n", "ascii"))
}) })
it("try to join/create channel with invalid channel name (no #)", 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) {
let answer = data.toString("ascii")
if (answer.indexOf("404") >= 0) {
assert.equal(answer, ":irc.example.com 404: invalid channel name")
done()
}
}
mockedSock.destroy = function () {
done("Destroyed socket without answering")
}
server.emit("connection", mockedSock)
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"))
mockedSock.emit('data', Buffer.from("JOIN testchan\r\n", "ascii"))
})
it("should handle a JOIN command for more than one user -> JOIN #testchan and send join events to all channel members", function (done) { it("should handle a JOIN command for more than one user -> JOIN #testchan and send join events to all channel members", function (done) {
const server = IRCServer.create() const server = IRCServer.create()

Loading…
Cancel
Save