Sheogorath
5 years ago
No known key found for this signature in database
GPG Key ID: 1F05CC3635CDDFFD
3 changed files with
39 additions and
7 deletions
-
src/server.js
-
src/user.js
-
test/command_pass.js
|
|
@ -70,15 +70,20 @@ server.create = function create() { |
|
|
|
let target = userlist[tokenized[1]] |
|
|
|
let message = tokenized[2] |
|
|
|
|
|
|
|
target.sendMsg(user, message) |
|
|
|
break; |
|
|
|
target.sendMsg(user, message) |
|
|
|
break; |
|
|
|
case "QUIT": |
|
|
|
server.closeConnection(user.nickname) |
|
|
|
break; |
|
|
|
server.closeConnection(user.nickname) |
|
|
|
break; |
|
|
|
case "PASS": |
|
|
|
if (tokenized[1]) |
|
|
|
user.setPassword(tokenized[1]) |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
console.error(`Unknown command: ${command}`); |
|
|
|
} |
|
|
|
}); |
|
|
|
console.error(`Unknown command: ${command}`); |
|
|
|
} |
|
|
|
}); |
|
|
|
}).on('error', (err) => { |
|
|
|
console.error(err); |
|
|
|
}) |
|
|
|
|
|
@ -12,6 +12,9 @@ function User(socket) { |
|
|
|
this.getNickname = function(nickname) { |
|
|
|
return this.nickname |
|
|
|
} |
|
|
|
this.setPassword = function (password) { |
|
|
|
this.password = password |
|
|
|
} |
|
|
|
|
|
|
|
this.register = function(username, realname) { |
|
|
|
this.username = username |
|
|
|
|
|
@ -0,0 +1,24 @@ |
|
|
|
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() |
|
|
|
let mockedSock = new EventEmitter() |
|
|
|
|
|
|
|
|
|
|
|
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("NICK some_nick\r\n", "ascii")) |
|
|
|
|
|
|
|
user = server.getUserlist()["some_nick"] |
|
|
|
assert.equal("some_pass", user["password"]) |
|
|
|
done() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |