Merge pull request #3482 from thelounge/xpaw/fix-3219

Load existing users on startup when LDAP is enabled
This commit is contained in:
Pavel Djundik 2019-11-01 13:32:24 +02:00 committed by GitHub
commit ddebb22afe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 14 deletions

View File

@ -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 <name>"
)}.`;
if (users.length === 0) {
log.info(noUsersWarning);
log.info(
`There are currently no users. Create one with ${colors.bold("thelounge add <name>")}.`
);
}
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 <name>"
)}.`
);
}
// Reload all users. Existing users will only have their passwords reloaded.

View File

@ -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() {

View File

@ -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;

View File

@ -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({

View File

@ -52,11 +52,6 @@ describe("Server", function() {
let client;
before((done) => {
Helper.config.public = true;
done();
});
beforeEach(() => {
client = io(webURL, {
path: "/socket.io/",