2017-05-13 23:12:26 +07:00
|
|
|
import * as Assert from "assert";
|
2017-09-03 20:22:09 +07:00
|
|
|
import {
|
|
|
|
UserConfiguration,
|
|
|
|
LdapConfiguration, ACLConfiguration
|
2017-10-07 05:09:42 +07:00
|
|
|
} from "../../src/lib/configuration/Configuration";
|
2017-10-11 02:59:20 +07:00
|
|
|
import { ConfigurationParser } from "../../src/lib/configuration/ConfigurationParser";
|
2017-05-13 23:12:26 +07:00
|
|
|
|
2017-10-11 02:59:20 +07:00
|
|
|
describe("test config parser", function () {
|
|
|
|
function buildYamlConfig(): UserConfiguration {
|
2017-09-03 06:25:43 +07:00
|
|
|
const yaml_config: UserConfiguration = {
|
2017-05-13 23:12:26 +07:00
|
|
|
port: 8080,
|
2017-05-17 04:17:46 +07:00
|
|
|
ldap: {
|
|
|
|
url: "http://ldap",
|
2017-09-03 03:38:26 +07:00
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
additional_users_dn: "ou=users",
|
|
|
|
additional_groups_dn: "ou=groups",
|
2017-05-17 04:17:46 +07:00
|
|
|
user: "user",
|
|
|
|
password: "pass"
|
|
|
|
},
|
2017-05-13 23:12:26 +07:00
|
|
|
session: {
|
|
|
|
domain: "example.com",
|
|
|
|
secret: "secret",
|
2017-09-03 06:25:43 +07:00
|
|
|
expiration: 40000
|
2017-05-13 23:12:26 +07:00
|
|
|
},
|
2017-07-20 02:06:12 +07:00
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
path: "/mydirectory"
|
|
|
|
}
|
|
|
|
},
|
2017-09-03 06:25:43 +07:00
|
|
|
regulation: {
|
|
|
|
max_retries: 3,
|
|
|
|
find_time: 5 * 60,
|
|
|
|
ban_time: 5 * 60
|
|
|
|
},
|
2017-05-17 04:17:46 +07:00
|
|
|
logs_level: "debug",
|
|
|
|
notifier: {
|
2017-10-25 15:28:56 +07:00
|
|
|
email: {
|
2017-05-20 14:49:05 +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: "gmail"
|
2017-05-17 04:17:46 +07:00
|
|
|
}
|
|
|
|
}
|
2017-05-13 23:12:26 +07:00
|
|
|
};
|
|
|
|
return yaml_config;
|
|
|
|
}
|
|
|
|
|
2017-10-08 20:34:58 +07:00
|
|
|
describe("port", function () {
|
|
|
|
it("should read the port from the yaml file", function () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const yaml_config = buildYamlConfig();
|
2017-10-08 20:34:58 +07:00
|
|
|
yaml_config.port = 7070;
|
2017-10-11 02:59:20 +07:00
|
|
|
const config = ConfigurationParser.parse(yaml_config);
|
2017-10-08 20:34:58 +07:00
|
|
|
Assert.equal(config.port, 7070);
|
|
|
|
});
|
2017-05-13 23:12:26 +07:00
|
|
|
|
2017-10-08 20:34:58 +07:00
|
|
|
it("should default the port to 8080 if not provided", function () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const yaml_config = buildYamlConfig();
|
2017-10-08 20:34:58 +07:00
|
|
|
delete yaml_config.port;
|
2017-10-11 02:59:20 +07:00
|
|
|
const config = ConfigurationParser.parse(yaml_config);
|
2017-10-08 20:34:58 +07:00
|
|
|
Assert.equal(config.port, 8080);
|
|
|
|
});
|
2017-05-13 23:12:26 +07:00
|
|
|
});
|
|
|
|
|
2017-10-17 05:38:10 +07:00
|
|
|
describe("test session configuration", function() {
|
|
|
|
it("should get the session attributes", function () {
|
|
|
|
const yaml_config = buildYamlConfig();
|
|
|
|
yaml_config.session = {
|
|
|
|
domain: "example.com",
|
|
|
|
secret: "secret",
|
|
|
|
expiration: 3600,
|
|
|
|
inactivity: 4000
|
|
|
|
};
|
|
|
|
const config = ConfigurationParser.parse(yaml_config);
|
|
|
|
Assert.equal(config.session.domain, "example.com");
|
|
|
|
Assert.equal(config.session.secret, "secret");
|
|
|
|
Assert.equal(config.session.expiration, 3600);
|
|
|
|
Assert.equal(config.session.inactivity, 4000);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should be ok not specifying inactivity", function () {
|
|
|
|
const yaml_config = buildYamlConfig();
|
|
|
|
yaml_config.session = {
|
|
|
|
domain: "example.com",
|
|
|
|
secret: "secret",
|
|
|
|
expiration: 3600
|
|
|
|
};
|
|
|
|
const config = ConfigurationParser.parse(yaml_config);
|
|
|
|
Assert.equal(config.session.domain, "example.com");
|
|
|
|
Assert.equal(config.session.secret, "secret");
|
|
|
|
Assert.equal(config.session.expiration, 3600);
|
|
|
|
Assert.equal(config.session.inactivity, undefined);
|
|
|
|
});
|
2017-05-13 23:12:26 +07:00
|
|
|
});
|
|
|
|
|
2017-09-03 03:38:26 +07:00
|
|
|
it("should get the log level", function () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const yaml_config = buildYamlConfig();
|
2017-05-13 23:12:26 +07:00
|
|
|
yaml_config.logs_level = "debug";
|
2017-10-11 02:59:20 +07:00
|
|
|
const config = ConfigurationParser.parse(yaml_config);
|
2017-05-13 23:12:26 +07:00
|
|
|
Assert.equal(config.logs_level, "debug");
|
|
|
|
});
|
|
|
|
|
2017-09-03 03:38:26 +07:00
|
|
|
it("should get the notifier config", function () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const userConfig = buildYamlConfig();
|
|
|
|
userConfig.notifier = {
|
2017-10-25 15:28:56 +07:00
|
|
|
email: {
|
2017-05-20 14:49:05 +07:00
|
|
|
username: "user",
|
2017-10-10 05:07:12 +07:00
|
|
|
password: "pass",
|
2017-10-25 15:28:56 +07:00
|
|
|
sender: "admin@example.com",
|
|
|
|
service: "gmail"
|
2017-05-17 04:17:46 +07:00
|
|
|
}
|
|
|
|
};
|
2017-10-11 02:59:20 +07:00
|
|
|
const config = ConfigurationParser.parse(userConfig);
|
2017-05-17 04:17:46 +07:00
|
|
|
Assert.deepEqual(config.notifier, {
|
2017-10-25 15:28:56 +07:00
|
|
|
email: {
|
2017-05-20 14:49:05 +07:00
|
|
|
username: "user",
|
2017-10-10 05:07:12 +07:00
|
|
|
password: "pass",
|
2017-10-25 15:28:56 +07:00
|
|
|
sender: "admin@example.com",
|
|
|
|
service: "gmail"
|
2017-05-17 04:17:46 +07:00
|
|
|
}
|
|
|
|
});
|
2017-05-13 23:12:26 +07:00
|
|
|
});
|
|
|
|
|
2017-10-08 20:34:58 +07:00
|
|
|
describe("access_control", function() {
|
|
|
|
it("should adapt access_control when it is already ok", function () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const userConfig = buildYamlConfig();
|
|
|
|
userConfig.access_control = {
|
2017-10-08 20:34:58 +07:00
|
|
|
default_policy: "deny",
|
|
|
|
any: [{
|
|
|
|
domain: "public.example.com",
|
|
|
|
policy: "allow"
|
|
|
|
}],
|
|
|
|
users: {
|
|
|
|
"user": [{
|
|
|
|
domain: "www.example.com",
|
|
|
|
policy: "allow"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
groups: {}
|
|
|
|
};
|
2017-10-11 02:59:20 +07:00
|
|
|
const config = ConfigurationParser.parse(userConfig);
|
2017-10-08 20:34:58 +07:00
|
|
|
Assert.deepEqual(config.access_control, {
|
|
|
|
default_policy: "deny",
|
|
|
|
any: [{
|
|
|
|
domain: "public.example.com",
|
|
|
|
policy: "allow"
|
|
|
|
}],
|
|
|
|
users: {
|
|
|
|
"user": [{
|
|
|
|
domain: "www.example.com",
|
|
|
|
policy: "allow"
|
|
|
|
}]
|
|
|
|
},
|
|
|
|
groups: {}
|
|
|
|
} as ACLConfiguration);
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("should adapt access_control when it is empty", function () {
|
2017-10-11 02:59:20 +07:00
|
|
|
const userConfig = buildYamlConfig();
|
|
|
|
userConfig.access_control = {} as any;
|
|
|
|
const config = ConfigurationParser.parse(userConfig);
|
2017-10-08 20:34:58 +07:00
|
|
|
Assert.deepEqual(config.access_control, {
|
|
|
|
default_policy: "deny",
|
|
|
|
any: [],
|
|
|
|
users: {},
|
|
|
|
groups: {}
|
|
|
|
} as ACLConfiguration);
|
|
|
|
});
|
2017-05-13 23:12:26 +07:00
|
|
|
});
|
2017-10-18 04:24:02 +07:00
|
|
|
|
|
|
|
describe("default_redirection_url", function() {
|
|
|
|
it("should parse default_redirection_url", function() {
|
|
|
|
const userConfig = buildYamlConfig();
|
|
|
|
userConfig.default_redirection_url = "dummy_url";
|
|
|
|
const config = ConfigurationParser.parse(userConfig);
|
|
|
|
Assert.deepEqual(config.default_redirection_url, "dummy_url");
|
|
|
|
});
|
|
|
|
});
|
2017-05-13 23:12:26 +07:00
|
|
|
});
|