2017-09-03 03:38:26 +07:00
|
|
|
import * as Assert from "assert";
|
2017-10-07 05:09:42 +07:00
|
|
|
import { UserConfiguration, LdapConfiguration } from "../../src/lib/configuration/Configuration";
|
2017-10-11 02:59:20 +07:00
|
|
|
import { ConfigurationParser } from "../../src/lib/configuration/ConfigurationParser";
|
2017-09-03 03:38:26 +07:00
|
|
|
|
|
|
|
describe("test ldap configuration adaptation", function () {
|
|
|
|
function build_yaml_config(): UserConfiguration {
|
2017-09-03 06:25:43 +07:00
|
|
|
const yaml_config: UserConfiguration = {
|
2017-09-03 03:38:26 +07:00
|
|
|
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",
|
2017-09-03 06:25:43 +07:00
|
|
|
expiration: 40000
|
2017-09-03 03:38:26 +07:00
|
|
|
},
|
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
path: "/mydirectory"
|
|
|
|
}
|
|
|
|
},
|
2017-09-03 06:25:43 +07:00
|
|
|
regulation: {
|
|
|
|
max_retries: 3,
|
|
|
|
ban_time: 5 * 60,
|
|
|
|
find_time: 5 * 60,
|
|
|
|
},
|
2017-09-03 03:38:26 +07:00
|
|
|
logs_level: "debug",
|
|
|
|
notifier: {
|
2017-10-25 15:28:56 +07:00
|
|
|
email: {
|
2017-09-03 03:38:26 +07:00
|
|
|
username: "user",
|
2017-10-10 05:07:12 +07:00
|
|
|
password: "password",
|
2017-10-25 15:28:56 +07:00
|
|
|
sender: "admin@example.com",
|
|
|
|
service: "email"
|
2017-09-03 03:38:26 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
return yaml_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
it("should adapt correctly while user only specify mandatory fields", function () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const userConfig = build_yaml_config();
|
|
|
|
userConfig.ldap = {
|
2017-09-03 03:38:26 +07:00
|
|
|
url: "http://ldap",
|
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
user: "admin",
|
|
|
|
password: "password"
|
|
|
|
};
|
|
|
|
|
2017-10-11 02:59:20 +07:00
|
|
|
const config = ConfigurationParser.parse(userConfig);
|
2017-09-03 03:38:26 +07:00
|
|
|
const expectedConfig: LdapConfiguration = {
|
|
|
|
url: "http://ldap",
|
|
|
|
users_dn: "dc=example,dc=com",
|
|
|
|
users_filter: "cn={0}",
|
|
|
|
groups_dn: "dc=example,dc=com",
|
2017-10-15 19:27:20 +07:00
|
|
|
groups_filter: "member={dn}",
|
2017-09-03 03:38:26 +07:00
|
|
|
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 () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const userConfig = build_yaml_config();
|
|
|
|
userConfig.ldap = {
|
2017-09-03 03:38:26 +07:00
|
|
|
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"
|
|
|
|
};
|
|
|
|
|
2017-10-11 02:59:20 +07:00
|
|
|
const config = ConfigurationParser.parse(userConfig);
|
2017-09-03 03:38:26 +07:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|