2017-10-10 06:14:36 +07:00
|
|
|
import { Validator } from "../../src/lib/configuration/Validator";
|
|
|
|
import Assert = require("assert");
|
|
|
|
|
2017-10-11 02:59:20 +07:00
|
|
|
describe("test validator", function () {
|
|
|
|
it("should validate wrong user configurations", function () {
|
|
|
|
// Some examples
|
|
|
|
Assert.deepStrictEqual(Validator.isValid({}), [
|
|
|
|
"data should have required property 'ldap'",
|
|
|
|
"data should have required property 'notifier'",
|
|
|
|
"data should have required property 'regulation'",
|
|
|
|
"data should have required property 'session'",
|
|
|
|
"data should have required property 'storage'"
|
|
|
|
]);
|
|
|
|
|
|
|
|
Assert.deepStrictEqual(Validator.isValid({
|
|
|
|
ldap: {},
|
|
|
|
notifier: {},
|
|
|
|
regulation: {},
|
|
|
|
session: {},
|
|
|
|
storage: {}
|
|
|
|
}), [
|
|
|
|
"data.ldap should have required property 'base_dn'",
|
|
|
|
"data.ldap should have required property 'password'",
|
|
|
|
"data.ldap should have required property 'url'",
|
|
|
|
"data.ldap should have required property 'user'",
|
|
|
|
"data.regulation should have required property 'ban_time'",
|
|
|
|
"data.regulation should have required property 'find_time'",
|
|
|
|
"data.regulation should have required property 'max_retries'",
|
|
|
|
"data.session should have required property 'secret'",
|
|
|
|
"Storage must be either 'local' or 'mongo'",
|
2017-10-22 22:42:05 +07:00
|
|
|
"A notifier needs to be declared when server is used with two-factor"
|
2017-10-11 02:59:20 +07:00
|
|
|
]);
|
|
|
|
|
|
|
|
Assert.deepStrictEqual(Validator.isValid({
|
|
|
|
ldap: {
|
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
password: "password",
|
|
|
|
url: "ldap://ldap",
|
|
|
|
user: "user"
|
|
|
|
},
|
|
|
|
notifier: {
|
|
|
|
abcd: []
|
|
|
|
},
|
|
|
|
regulation: {
|
|
|
|
ban_time: 120,
|
|
|
|
find_time: 30,
|
|
|
|
max_retries: 3
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
secret: "unsecure_secret"
|
|
|
|
},
|
|
|
|
storage: {
|
|
|
|
abc: {}
|
|
|
|
}
|
|
|
|
}), [
|
|
|
|
"data.storage has unknown key 'abc'",
|
2017-10-22 22:42:05 +07:00
|
|
|
"Notifier must be either 'filesystem', 'email' or 'smtp'"
|
2017-10-11 02:59:20 +07:00
|
|
|
]);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should validate correct user configurations", function () {
|
|
|
|
Assert.deepStrictEqual(Validator.isValid({
|
|
|
|
ldap: {
|
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
password: "password",
|
|
|
|
url: "ldap://ldap",
|
|
|
|
user: "user"
|
|
|
|
},
|
|
|
|
notifier: {
|
2017-10-25 15:28:56 +07:00
|
|
|
email: {
|
2017-10-11 02:59:20 +07:00
|
|
|
username: "user@gmail.com",
|
|
|
|
password: "pass",
|
2017-10-25 15:28:56 +07:00
|
|
|
sender: "admin@example.com",
|
|
|
|
service: "gmail"
|
2017-10-11 02:59:20 +07:00
|
|
|
}
|
|
|
|
},
|
|
|
|
regulation: {
|
|
|
|
ban_time: 120,
|
|
|
|
find_time: 30,
|
|
|
|
max_retries: 3
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
secret: "unsecure_secret"
|
|
|
|
},
|
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
path: "/var/lib/authelia"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}), []);
|
2017-10-10 06:14:36 +07:00
|
|
|
});
|
2017-10-22 22:42:05 +07:00
|
|
|
|
|
|
|
it("should return false when notifier is not defined while there is at least \
|
|
|
|
one second factor enabled sub-domain", function () {
|
|
|
|
const options1 = {
|
|
|
|
ldap: {
|
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
password: "password",
|
|
|
|
url: "ldap://ldap",
|
|
|
|
user: "user"
|
|
|
|
},
|
|
|
|
authentication_methods: {
|
|
|
|
default_method: "two_factor"
|
|
|
|
},
|
|
|
|
notifier: {},
|
|
|
|
regulation: {
|
|
|
|
ban_time: 120,
|
|
|
|
find_time: 30,
|
|
|
|
max_retries: 3
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
secret: "unsecure_secret"
|
|
|
|
},
|
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
path: "/var/lib/authelia"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const options2 = {
|
|
|
|
ldap: {
|
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
password: "password",
|
|
|
|
url: "ldap://ldap",
|
|
|
|
user: "user"
|
|
|
|
},
|
|
|
|
authentication_methods: {
|
|
|
|
default_method: "two_factor"
|
|
|
|
},
|
|
|
|
notifier: {
|
|
|
|
email: {
|
|
|
|
username: "user@gmail.com",
|
|
|
|
password: "pass",
|
|
|
|
sender: "admin@example.com",
|
|
|
|
service: "gmail"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
regulation: {
|
|
|
|
ban_time: 120,
|
|
|
|
find_time: 30,
|
|
|
|
max_retries: 3
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
secret: "unsecure_secret"
|
|
|
|
},
|
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
path: "/var/lib/authelia"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
const options3 = {
|
|
|
|
ldap: {
|
|
|
|
base_dn: "dc=example,dc=com",
|
|
|
|
password: "password",
|
|
|
|
url: "ldap://ldap",
|
|
|
|
user: "user"
|
|
|
|
},
|
|
|
|
authentication_methods: {
|
|
|
|
default_method: "single_factor"
|
|
|
|
},
|
|
|
|
notifier: {},
|
|
|
|
regulation: {
|
|
|
|
ban_time: 120,
|
|
|
|
find_time: 30,
|
|
|
|
max_retries: 3
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
secret: "unsecure_secret"
|
|
|
|
},
|
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
path: "/var/lib/authelia"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
Assert.deepStrictEqual(Validator.isValid(options1), ["A notifier needs to be declared when server is used with two-factor"]);
|
|
|
|
Assert.deepStrictEqual(Validator.isValid(options2), []);
|
|
|
|
Assert.deepStrictEqual(Validator.isValid(options3), []);
|
|
|
|
});
|
2017-10-10 06:14:36 +07:00
|
|
|
});
|