authelia/test/server/server_config.test.ts

73 lines
1.8 KiB
TypeScript
Raw Normal View History

2017-05-16 21:17:46 +00:00
import assert = require("assert");
import sinon = require ("sinon");
2017-05-16 21:17:46 +00:00
import nedb = require("nedb");
import express = require("express");
import winston = require("winston");
import speakeasy = require("speakeasy");
import u2f = require("u2f");
import nodemailer = require("nodemailer");
import session = require("express-session");
2017-05-16 21:17:46 +00:00
import { AppConfiguration, UserConfiguration } from "../../src/types/Configuration";
import { GlobalDependencies, Nodemailer } from "../../src/types/Dependencies";
import Server from "../../src/server/lib/Server";
2017-05-16 21:17:46 +00:00
describe("test server configuration", function () {
let deps: GlobalDependencies;
let sessionMock: sinon.SinonSpy;
2017-05-16 21:17:46 +00:00
before(function () {
const transporter = {
sendMail: sinon.stub().yields()
};
const createTransport = sinon.stub(nodemailer, "createTransport");
createTransport.returns(transporter);
sessionMock = sinon.spy(session);
2017-05-16 21:17:46 +00:00
deps = {
2017-05-20 07:49:05 +00:00
nodemailer: nodemailer,
2017-05-16 21:17:46 +00:00
speakeasy: speakeasy,
u2f: u2f,
nedb: nedb,
winston: winston,
ldapjs: {
createClient: sinon.spy(function () {
return { on: sinon.spy() };
})
},
session: sessionMock as any
2017-05-16 21:17:46 +00:00
};
});
it("should set cookie scope to domain set in the config", function () {
const config = {
session: {
domain: "example.com",
secret: "secret"
},
ldap: {
url: "http://ldap",
user: "user",
password: "password"
},
notifier: {
gmail: {
2017-05-20 07:49:05 +00:00
username: "user@example.com",
password: "password"
2017-05-16 21:17:46 +00:00
}
}
} as UserConfiguration;
const server = new Server();
server.start(config, deps);
assert(sessionMock.calledOnce);
assert.equal(sessionMock.getCall(0).args[0].cookie.domain, "example.com");
2017-05-16 21:17:46 +00:00
});
});