2017-05-17 04:17:46 +07:00
|
|
|
|
2017-10-17 05:35:34 +07:00
|
|
|
import Assert = require("assert");
|
2017-07-16 22:37:13 +07:00
|
|
|
import Sinon = require("sinon");
|
2017-05-17 04:17:46 +07:00
|
|
|
import nedb = require("nedb");
|
2017-05-21 00:16:57 +07:00
|
|
|
import express = require("express");
|
|
|
|
import winston = require("winston");
|
|
|
|
import speakeasy = require("speakeasy");
|
2017-05-25 20:09:29 +07:00
|
|
|
import u2f = require("u2f");
|
2017-05-21 00:16:57 +07:00
|
|
|
import session = require("express-session");
|
2017-05-17 04:17:46 +07:00
|
|
|
|
2017-10-07 05:09:42 +07:00
|
|
|
import { AppConfiguration, UserConfiguration } from "../src/lib/configuration/Configuration";
|
2017-10-08 05:46:57 +07:00
|
|
|
import { GlobalDependencies } from "../types/Dependencies";
|
2017-10-07 05:09:42 +07:00
|
|
|
import Server from "../src/lib/Server";
|
2017-05-17 04:17:46 +07:00
|
|
|
|
|
|
|
|
|
|
|
describe("test server configuration", function () {
|
|
|
|
let deps: GlobalDependencies;
|
2017-07-16 22:37:13 +07:00
|
|
|
let sessionMock: Sinon.SinonSpy;
|
2017-05-17 04:17:46 +07:00
|
|
|
|
|
|
|
before(function () {
|
2017-07-16 22:37:13 +07:00
|
|
|
sessionMock = Sinon.spy(session);
|
2017-05-17 04:17:46 +07:00
|
|
|
|
|
|
|
deps = {
|
|
|
|
speakeasy: speakeasy,
|
|
|
|
u2f: u2f,
|
|
|
|
nedb: nedb,
|
|
|
|
winston: winston,
|
|
|
|
ldapjs: {
|
2017-07-16 22:37:13 +07:00
|
|
|
createClient: Sinon.spy(function () {
|
2017-06-15 05:22:16 +07:00
|
|
|
return {
|
2017-07-16 22:37:13 +07:00
|
|
|
on: Sinon.spy(),
|
|
|
|
bind: Sinon.spy(),
|
2017-06-15 05:22:16 +07:00
|
|
|
};
|
2017-05-17 04:17:46 +07:00
|
|
|
})
|
|
|
|
},
|
2017-06-30 00:41:05 +07:00
|
|
|
session: sessionMock as any,
|
2017-07-16 22:37:13 +07:00
|
|
|
ConnectRedis: Sinon.spy(),
|
|
|
|
dovehash: Sinon.spy() as any
|
2017-05-17 04:17:46 +07:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
it("should set cookie scope to domain set in the config", function () {
|
2017-07-20 02:06:12 +07:00
|
|
|
const config: UserConfiguration = {
|
2017-05-17 04:17:46 +07:00
|
|
|
session: {
|
|
|
|
domain: "example.com",
|
|
|
|
secret: "secret"
|
|
|
|
},
|
|
|
|
ldap: {
|
|
|
|
url: "http://ldap",
|
|
|
|
user: "user",
|
2017-07-20 02:06:12 +07:00
|
|
|
password: "password",
|
|
|
|
base_dn: "dc=example,dc=com"
|
2017-05-17 04:17:46 +07:00
|
|
|
},
|
|
|
|
notifier: {
|
2017-10-25 15:28:56 +07:00
|
|
|
email: {
|
2017-05-20 14:49:05 +07:00
|
|
|
username: "user@example.com",
|
2017-10-10 05:07:12 +07:00
|
|
|
password: "password",
|
2017-10-25 15:28:56 +07:00
|
|
|
sender: "test@authelia.com",
|
|
|
|
service: "gmail"
|
2017-05-17 04:17:46 +07:00
|
|
|
}
|
2017-07-20 02:06:12 +07:00
|
|
|
},
|
2017-09-03 06:25:43 +07:00
|
|
|
regulation: {
|
|
|
|
max_retries: 3,
|
|
|
|
ban_time: 5 * 60,
|
|
|
|
find_time: 5 * 60
|
|
|
|
},
|
2017-07-20 02:06:12 +07:00
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
in_memory: true
|
|
|
|
}
|
2017-05-17 04:17:46 +07:00
|
|
|
}
|
2017-07-20 02:06:12 +07:00
|
|
|
};
|
2017-05-17 04:17:46 +07:00
|
|
|
|
2017-10-08 05:46:57 +07:00
|
|
|
const server = new Server(deps);
|
2017-10-17 05:35:34 +07:00
|
|
|
server.start(config, deps)
|
|
|
|
.then(function () {
|
|
|
|
Assert(sessionMock.calledOnce);
|
|
|
|
Assert.equal(sessionMock.getCall(0).args[0].cookie.domain, "example.com");
|
|
|
|
});
|
2017-05-17 04:17:46 +07:00
|
|
|
});
|
|
|
|
});
|