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