Merge pull request #2955 from moundahiwale/moun/catch-ldap-messages

Catch LDAP bind error and search warning log messages in ldap tests
This commit is contained in:
Pavel Djundik 2019-01-15 13:32:23 +02:00 committed by GitHub
commit c9f407c224
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,6 +5,8 @@ const ldapAuth = require("../../../src/plugins/auth/ldap");
const Helper = require("../../../src/helper");
const ldap = require("thelounge-ldapjs-non-maintained-fork");
const expect = require("chai").expect;
const stub = require("sinon").stub;
const TestUtil = require("../../util");
const user = "johndoe";
const wrongUser = "eve";
@ -95,15 +97,25 @@ function testLdapAuth() {
});
it("should fail to authenticate with incorrect password", function(done) {
let error = "";
stub(log, "error").callsFake(TestUtil.sanitizeLog((str) => error += str));
ldapAuth.auth(manager, client, user, wrongPassword, function(valid) {
expect(valid).to.equal(false);
expect(error).to.equal("LDAP bind failed: InsufficientAccessRightsError: InsufficientAccessRightsError\n");
log.error.restore();
done();
});
});
it("should fail to authenticate with incorrect username", function(done) {
let warning = "";
stub(log, "warn").callsFake(TestUtil.sanitizeLog((str) => warning += str));
ldapAuth.auth(manager, client, wrongUser, correctPassword, function(valid) {
expect(valid).to.equal(false);
expect(warning).to.equal("LDAP Search did not find anything for: eve (0)\n");
log.warn.restore();
done();
});
});