mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
66449eedb0
Previously, string "{0}" was replaced by the user dn in the groups_filter attributes of the LDAP configuration. However, if the groups children only have a memberUid attribute, one would like to use the username instead of the user dn. Since the user dn can be built from the username, "{0}" is now replaced by the username instead of the user dn so that an LDAP relying on attribute 'memberUid' can be used.
99 lines
2.8 KiB
TypeScript
99 lines
2.8 KiB
TypeScript
import * as Assert from "assert";
|
|
import { UserConfiguration, LdapConfiguration } from "../../src/lib/configuration/Configuration";
|
|
import { ConfigurationAdapter } from "../../src/lib/configuration/ConfigurationAdapter";
|
|
|
|
describe("test ldap configuration adaptation", function () {
|
|
function build_yaml_config(): UserConfiguration {
|
|
const yaml_config: UserConfiguration = {
|
|
port: 8080,
|
|
ldap: {
|
|
url: "http://ldap",
|
|
base_dn: "dc=example,dc=com",
|
|
additional_users_dn: "ou=users",
|
|
additional_groups_dn: "ou=groups",
|
|
user: "user",
|
|
password: "pass"
|
|
},
|
|
session: {
|
|
domain: "example.com",
|
|
secret: "secret",
|
|
expiration: 40000
|
|
},
|
|
storage: {
|
|
local: {
|
|
path: "/mydirectory"
|
|
}
|
|
},
|
|
regulation: {
|
|
max_retries: 3,
|
|
ban_time: 5 * 60,
|
|
find_time: 5 * 60,
|
|
},
|
|
logs_level: "debug",
|
|
notifier: {
|
|
gmail: {
|
|
username: "user",
|
|
password: "password"
|
|
}
|
|
}
|
|
};
|
|
return yaml_config;
|
|
}
|
|
|
|
it("should adapt correctly while user only specify mandatory fields", function () {
|
|
const yaml_config = build_yaml_config();
|
|
yaml_config.ldap = {
|
|
url: "http://ldap",
|
|
base_dn: "dc=example,dc=com",
|
|
user: "admin",
|
|
password: "password"
|
|
};
|
|
|
|
const config = ConfigurationAdapter.adapt(yaml_config);
|
|
const expectedConfig: LdapConfiguration = {
|
|
url: "http://ldap",
|
|
users_dn: "dc=example,dc=com",
|
|
users_filter: "cn={0}",
|
|
groups_dn: "dc=example,dc=com",
|
|
groups_filter: "member=cn={0},dc=example,dc=com",
|
|
group_name_attribute: "cn",
|
|
mail_attribute: "mail",
|
|
user: "admin",
|
|
password: "password"
|
|
};
|
|
|
|
Assert.deepEqual(config.ldap, expectedConfig);
|
|
});
|
|
|
|
it("should adapt correctly while user specify every fields", function () {
|
|
const yaml_config = build_yaml_config();
|
|
yaml_config.ldap = {
|
|
url: "http://ldap-server",
|
|
base_dn: "dc=example,dc=com",
|
|
additional_users_dn: "ou=users",
|
|
users_filter: "uid={0}",
|
|
additional_groups_dn: "ou=groups",
|
|
groups_filter: "uniqueMember={0}",
|
|
mail_attribute: "email",
|
|
group_name_attribute: "groupName",
|
|
user: "admin2",
|
|
password: "password2"
|
|
};
|
|
|
|
const config = ConfigurationAdapter.adapt(yaml_config);
|
|
const expectedConfig: LdapConfiguration = {
|
|
url: "http://ldap-server",
|
|
users_dn: "ou=users,dc=example,dc=com",
|
|
users_filter: "uid={0}",
|
|
groups_dn: "ou=groups,dc=example,dc=com",
|
|
groups_filter: "uniqueMember={0}",
|
|
mail_attribute: "email",
|
|
group_name_attribute: "groupName",
|
|
user: "admin2",
|
|
password: "password2"
|
|
};
|
|
|
|
Assert.deepEqual(config.ldap, expectedConfig);
|
|
});
|
|
});
|