From fe4e0343a4d0894a82d87e5ef2af2b99963aa489 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Thu, 31 Oct 2019 11:01:44 +0200 Subject: [PATCH] Load existing users on startup when LDAP is enabled Fixes #3219 --- src/clientManager.js | 27 +++++++++++++++++++-------- test/models/network.js | 4 +++- test/plugins/auth/ldap.js | 5 +++++ test/plugins/storage.js | 4 ++++ test/server.js | 5 ----- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/src/clientManager.js b/src/clientManager.js index 27ea6dd1..b8502fbf 100644 --- a/src/clientManager.js +++ b/src/clientManager.js @@ -20,8 +20,14 @@ ClientManager.prototype.init = function(identHandler, sockets) { this.identHandler = identHandler; this.webPush = new WebPush(); - if (!Helper.config.public && !Helper.config.ldap.enable) { - this.autoloadUsers(); + if (!Helper.config.public) { + this.loadUsers(); + + // LDAP does not have user commands, and users are dynamically + // created upon logon, so we don't need to watch for new files + if (!Helper.config.ldap.enable) { + this.autoloadUsers(); + } } }; @@ -29,18 +35,19 @@ ClientManager.prototype.findClient = function(name) { return this.clients.find((u) => u.name === name); }; -ClientManager.prototype.autoloadUsers = function() { +ClientManager.prototype.loadUsers = function() { const users = this.getUsers(); - const noUsersWarning = `There are currently no users. Create one with ${colors.bold( - "thelounge add " - )}.`; if (users.length === 0) { - log.info(noUsersWarning); + log.info( + `There are currently no users. Create one with ${colors.bold("thelounge add ")}.` + ); } users.forEach((name) => this.loadUser(name)); +}; +ClientManager.prototype.autoloadUsers = function() { fs.watch( Helper.getUsersPath(), _.debounce( @@ -49,7 +56,11 @@ ClientManager.prototype.autoloadUsers = function() { const updatedUsers = this.getUsers(); if (updatedUsers.length === 0) { - log.info(noUsersWarning); + log.info( + `There are currently no users. Create one with ${colors.bold( + "thelounge add " + )}.` + ); } // Reload all users. Existing users will only have their passwords reloaded. diff --git a/test/models/network.js b/test/models/network.js index 1555490d..f794ad4d 100644 --- a/test/models/network.js +++ b/test/models/network.js @@ -73,6 +73,8 @@ describe("Network", function() { it("lockNetwork should be enforced when validating", function() { Helper.config.lockNetwork = true; + + // Make sure we lock in private mode Helper.config.public = false; const network = new Network({ @@ -87,6 +89,7 @@ describe("Network", function() { expect(network.tls).to.be.true; expect(network.rejectUnauthorized).to.be.true; + // Make sure we lock in public mode (also resets public=true for other tests) Helper.config.public = true; const network2 = new Network({ @@ -96,7 +99,6 @@ describe("Network", function() { expect(network2.host).to.equal("chat.freenode.net"); Helper.config.lockNetwork = false; - Helper.config.public = false; }); it("editing a network should enforce correct types", function() { diff --git a/test/plugins/auth/ldap.js b/test/plugins/auth/ldap.js index 8fcf45f8..6ae06118 100644 --- a/test/plugins/auth/ldap.js +++ b/test/plugins/auth/ldap.js @@ -150,6 +150,11 @@ describe("LDAP authentication plugin", function() { Helper.config.ldap.primaryKey = primaryKey; }); + afterEach(function() { + Helper.config.public = true; + Helper.config.ldap.enable = false; + }); + describe("LDAP authentication availability", function() { it("checks that the configuration is correctly tied to isEnabled()", function() { Helper.config.ldap.enable = true; diff --git a/test/plugins/storage.js b/test/plugins/storage.js index 9b1f9519..dc6d8ab1 100644 --- a/test/plugins/storage.js +++ b/test/plugins/storage.js @@ -56,6 +56,10 @@ describe("Image storage", function() { Helper.config.prefetchStorage = true; }); + afterEach(function() { + Helper.config.prefetchStorage = false; + }); + it("should store the thumbnail", function(done) { const port = this.port; const message = this.irc.createMessage({ diff --git a/test/server.js b/test/server.js index 8adea400..0f56b626 100644 --- a/test/server.js +++ b/test/server.js @@ -52,11 +52,6 @@ describe("Server", function() { let client; - before((done) => { - Helper.config.public = true; - done(); - }); - beforeEach(() => { client = io(webURL, { path: "/socket.io/",