You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

  1. const assert = require('assert');
  2. const EventEmitter = require('events');
  3. const IRCServer = require("../src/server.js");
  4. describe("PASS OK", function () {
  5. it("should handle a PASS command -> PASS some_passwd", function (done) {
  6. const server = IRCServer.create({
  7. password: "itsJustATest"
  8. })
  9. let mockedSock = new EventEmitter()
  10. mockedSock.address = function() {
  11. return { port: 12346, family: 'IPv4', address: '127.0.0.1' }
  12. }
  13. mockedSock.write = function (data) {
  14. return
  15. }
  16. mockedSock.destroy = function () {
  17. done("Destroyed socket without answering")
  18. }
  19. server.emit("connection", mockedSock)
  20. mockedSock.emit('data', Buffer.from("PASS itsJustATest\r\n", "ascii"))
  21. mockedSock.emit('data', Buffer.from("NICK some_nick\r\n", "ascii"))
  22. mockedSock.emit('data', Buffer.from("USER guest tolmoon tolsun :Ronnie Reagan\r\n", "ascii"))
  23. user = server.getUserlist()["some_nick"]
  24. assert.equal(user["registered"], true)
  25. done()
  26. })
  27. it("should end connection on wrong password", function (done) {
  28. const server = IRCServer.create({
  29. password: "itsJustATest"
  30. })
  31. let mockedSock = new EventEmitter()
  32. mockedSock.address = function() {
  33. return { port: 12346, family: 'IPv4', address: '127.0.0.1' }
  34. }
  35. mockedSock.write = function (data) {
  36. return
  37. }
  38. mockedSock.destroy = function () {
  39. // connection has to be destroyed
  40. done("")
  41. }
  42. server.emit("connection", mockedSock)
  43. mockedSock.emit('data', Buffer.from("PASS wrongpassword\r\n", "ascii"))
  44. })
  45. })