Browse Source

Merge branch 'develop' of https://gogs.informatik.hs-fulda.de/sheogorath/ircd-js into feature/index.js

feature/index.js
Sheogorath 6 years ago
parent
commit
4ef2a6f885
No known key found for this signature in database GPG Key ID: 1F05CC3635CDDFFD
  1. 5
      src/server.js
  2. 3
      src/user.js
  3. 24
      test/command_pass.js

5
src/server.js

@ -75,6 +75,11 @@ server.create = function create() {
case "QUIT": case "QUIT":
server.closeConnection(user.nickname) server.closeConnection(user.nickname)
break; break;
case "PASS":
if (tokenized[1])
user.setPassword(tokenized[1])
break;
default: default:
console.error(`Unknown command: ${command}`); console.error(`Unknown command: ${command}`);
} }

3
src/user.js

@ -12,6 +12,9 @@ function User(socket) {
this.getNickname = function(nickname) { this.getNickname = function(nickname) {
return this.nickname return this.nickname
} }
this.setPassword = function (password) {
this.password = password
}
this.register = function(username, realname) { this.register = function(username, realname) {
this.username = username this.username = username

24
test/command_pass.js

@ -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()
})
})
Loading…
Cancel
Save