2016-12-10 00:47:58 +00:00
|
|
|
|
2017-01-19 00:01:37 +00:00
|
|
|
var ldap = require('../../src/lib/ldap');
|
2016-12-10 00:47:58 +00:00
|
|
|
var sinon = require('sinon');
|
|
|
|
var sinonPromise = require('sinon-promise');
|
|
|
|
|
|
|
|
sinonPromise(sinon);
|
|
|
|
|
|
|
|
var autoResolving = sinon.promise().resolves();
|
|
|
|
|
|
|
|
function test_validate(bind_mock) {
|
|
|
|
var username = 'user';
|
|
|
|
var password = 'password';
|
|
|
|
var ldap_url = 'http://ldap';
|
|
|
|
var users_dn = 'dc=example,dc=com';
|
|
|
|
|
|
|
|
var ldap_client_mock = {
|
|
|
|
bind: bind_mock
|
|
|
|
}
|
|
|
|
|
2017-01-19 00:01:37 +00:00
|
|
|
return ldap.validate(ldap_client_mock, username, password, ldap_url, users_dn);
|
2016-12-10 00:47:58 +00:00
|
|
|
}
|
|
|
|
|
2017-01-19 00:01:37 +00:00
|
|
|
describe('test ldap validation', function() {
|
2016-12-10 00:47:58 +00:00
|
|
|
it('should bind the user if good credentials provided', function() {
|
|
|
|
var bind_mock = sinon.mock().yields();
|
|
|
|
return test_validate(bind_mock);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should not bind the user if wrong credentials provided', function() {
|
|
|
|
var bind_mock = sinon.mock().yields('wrong credentials');
|
|
|
|
var promise = test_validate(bind_mock);
|
2017-01-19 00:01:37 +00:00
|
|
|
return promise.error(autoResolving);
|
2016-12-10 00:47:58 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|