mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
Attribute mail_attribute is not correcty taken into account
This commit is contained in:
parent
bf11bfbcf8
commit
bf3705b3e9
|
@ -108,10 +108,10 @@ export class Client implements IClient {
|
|||
.then(function (userDN) {
|
||||
return that.ldapClient.searchAsync(userDN, query);
|
||||
})
|
||||
.then(function (docs: { mail: string }[]) {
|
||||
.then(function (docs: { [mail_attribute: string]: string }[]) {
|
||||
const emails: string[] = docs
|
||||
.filter((d) => { return typeof d.mail === "string"; })
|
||||
.map((d) => { return d.mail; });
|
||||
.filter((d) => { return typeof d[that.options.mail_attribute] === "string"; })
|
||||
.map((d) => { return d[that.options.mail_attribute]; });
|
||||
that.logger.debug("LDAP: emails of user '%s' are %s", username, emails);
|
||||
return BluebirdPromise.resolve(emails);
|
||||
})
|
||||
|
|
|
@ -86,4 +86,49 @@ describe("test authelia ldap client", function () {
|
|||
Assert.deepEqual(groups, ["group1"]);
|
||||
});
|
||||
});
|
||||
|
||||
it("should retrieve mail from custom attribute", function () {
|
||||
const USER_DN = "cn=user1,ou=users,dc=example,dc=com";
|
||||
const options: LdapConfiguration = {
|
||||
url: "ldap://ldap",
|
||||
users_dn: "ou=users,dc=example,dc=com",
|
||||
users_filter: "cn={0}",
|
||||
groups_dn: "ou=groups,dc=example,dc=com",
|
||||
groups_filter: "member={dn}",
|
||||
group_name_attribute: "cn",
|
||||
mail_attribute: "custom_mail",
|
||||
user: "cn=admin,dc=example,dc=com",
|
||||
password: "password"
|
||||
};
|
||||
const factory = new LdapClientFactoryStub();
|
||||
const ldapClient = new LdapClientStub();
|
||||
|
||||
factory.createStub.returns(ldapClient);
|
||||
|
||||
// Retrieve user DN
|
||||
ldapClient.searchAsyncStub.withArgs("ou=users,dc=example,dc=com", {
|
||||
scope: "sub",
|
||||
sizeLimit: 1,
|
||||
attributes: ["dn"],
|
||||
filter: "cn=user1"
|
||||
}).returns(BluebirdPromise.resolve([{
|
||||
dn: USER_DN
|
||||
}]));
|
||||
|
||||
// Retrieve email
|
||||
ldapClient.searchAsyncStub.withArgs("cn=user1,ou=users,dc=example,dc=com", {
|
||||
scope: "base",
|
||||
sizeLimit: 1,
|
||||
attributes: ["custom_mail"],
|
||||
}).returns(BluebirdPromise.resolve([{
|
||||
custom_mail: "user1@example.com"
|
||||
}]));
|
||||
|
||||
const client = new Client(ADMIN_USER_DN, ADMIN_PASSWORD, options, factory, Winston);
|
||||
|
||||
return client.searchEmails("user1")
|
||||
.then(function (emails: string[]) {
|
||||
Assert.deepEqual(emails, ["user1@example.com"]);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user