2017-10-09 23:14:36 +00:00
|
|
|
import { Validator } from "../../src/lib/configuration/Validator";
|
|
|
|
import Assert = require("assert");
|
|
|
|
|
2017-10-10 19:59:20 +00: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 15:42:05 +00:00
|
|
|
"A notifier needs to be declared when server is used with two-factor"
|
2017-10-10 19:59:20 +00: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 15:42:05 +00:00
|
|
|
"Notifier must be either 'filesystem', 'email' or 'smtp'"
|
2017-10-10 19:59:20 +00: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 08:28:56 +00:00
|
|
|
email: {
|
2017-10-10 19:59:20 +00:00
|
|
|
username: "user@gmail.com",
|
|
|
|
password: "pass",
|
2017-10-25 08:28:56 +00:00
|
|
|
sender: "admin@example.com",
|
|
|
|
service: "gmail"
|
2017-10-10 19:59:20 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
regulation: {
|
|
|
|
ban_time: 120,
|
|
|
|
find_time: 30,
|
|
|
|
max_retries: 3
|
|
|
|
},
|
|
|
|
session: {
|
|
|
|
secret: "unsecure_secret"
|
|
|
|
},
|
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
path: "/var/lib/authelia"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}), []);
|
2017-10-09 23:14:36 +00:00
|
|
|
});
|
2017-10-22 15:42:05 +00: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-09 23:14:36 +00:00
|
|
|
});
|