authelia/server/test/ServerConfiguration.test.ts

80 lines
2.0 KiB
TypeScript
Raw Normal View History

2017-05-17 04:17:46 +07:00
import Assert = require("assert");
import Sinon = require("sinon");
2017-05-17 04:17:46 +07:00
import nedb = require("nedb");
import express = require("express");
import winston = require("winston");
import speakeasy = require("speakeasy");
import u2f = require("u2f");
import session = require("express-session");
import { AppConfiguration, UserConfiguration } from "../src/lib/configuration/Configuration";
import { GlobalDependencies } from "../types/Dependencies";
import Server from "../src/lib/Server";
2018-04-27 04:20:10 +07:00
import { LdapjsMock, LdapjsClientMock } from "./mocks/ldapjs";
2017-05-17 04:17:46 +07:00
describe("test server configuration", function () {
let deps: GlobalDependencies;
let sessionMock: Sinon.SinonSpy;
2018-04-27 04:20:10 +07:00
let ldapjsMock: LdapjsMock;
2017-05-17 04:17:46 +07:00
before(function () {
sessionMock = Sinon.spy(session);
2018-04-27 04:20:10 +07:00
ldapjsMock = new LdapjsMock();
2017-05-17 04:17:46 +07:00
deps = {
speakeasy: speakeasy,
u2f: u2f,
nedb: nedb,
winston: winston,
2018-04-27 04:20:10 +07:00
ldapjs: ldapjsMock as any,
session: sessionMock as any,
2018-04-27 04:20:10 +07:00
ConnectRedis: Sinon.spy(),
Redis: Sinon.spy() as any
2017-05-17 04:17:46 +07:00
};
});
it("should set cookie scope to domain set in the config", function () {
const config: UserConfiguration = {
2018-05-17 05:06:07 +07:00
port: 8081,
2017-05-17 04:17:46 +07:00
session: {
domain: "example.com",
secret: "secret"
},
ldap: {
url: "http://ldap",
user: "user",
password: "password",
base_dn: "dc=example,dc=com"
2017-05-17 04:17:46 +07:00
},
notifier: {
email: {
2017-05-20 14:49:05 +07:00
username: "user@example.com",
password: "password",
sender: "test@authelia.com",
service: "gmail"
2017-05-17 04:17:46 +07:00
}
},
regulation: {
max_retries: 3,
ban_time: 5 * 60,
find_time: 5 * 60
},
storage: {
local: {
in_memory: true
}
2017-05-17 04:17:46 +07:00
}
};
2017-05-17 04:17:46 +07:00
const server = new Server(deps);
server.start(config, deps)
.then(function () {
Assert(sessionMock.calledOnce);
Assert.equal(sessionMock.getCall(0).args[0].cookie.domain, "example.com");
2018-03-29 05:04:59 +07:00
server.stop();
});
2017-05-17 04:17:46 +07:00
});
});