2017-05-16 21:17:46 +00:00
|
|
|
|
2017-05-20 17:16:57 +00:00
|
|
|
import assert = require("assert");
|
2017-07-16 15:37:13 +00:00
|
|
|
import Sinon = require("sinon");
|
2017-05-16 21:17:46 +00:00
|
|
|
import nedb = require("nedb");
|
2017-05-20 17:16:57 +00:00
|
|
|
import express = require("express");
|
|
|
|
import winston = require("winston");
|
|
|
|
import speakeasy = require("speakeasy");
|
2017-05-25 13:09:29 +00:00
|
|
|
import u2f = require("u2f");
|
2017-05-20 17:16:57 +00:00
|
|
|
import nodemailer = require("nodemailer");
|
|
|
|
import session = require("express-session");
|
2017-05-16 21:17:46 +00:00
|
|
|
|
2017-07-16 12:55:01 +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;
|
2017-07-16 15:37:13 +00:00
|
|
|
let sessionMock: Sinon.SinonSpy;
|
2017-05-16 21:17:46 +00:00
|
|
|
|
|
|
|
before(function () {
|
|
|
|
const transporter = {
|
2017-07-16 15:37:13 +00:00
|
|
|
sendMail: Sinon.stub().yields()
|
2017-05-16 21:17:46 +00:00
|
|
|
};
|
|
|
|
|
2017-07-16 15:37:13 +00:00
|
|
|
const createTransport = Sinon.stub(nodemailer, "createTransport");
|
2017-05-20 17:16:57 +00:00
|
|
|
createTransport.returns(transporter);
|
|
|
|
|
2017-07-16 15:37:13 +00:00
|
|
|
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: {
|
2017-07-16 15:37:13 +00:00
|
|
|
createClient: Sinon.spy(function () {
|
2017-06-14 22:22:16 +00:00
|
|
|
return {
|
2017-07-16 15:37:13 +00:00
|
|
|
on: Sinon.spy(),
|
|
|
|
bind: Sinon.spy(),
|
2017-06-14 22:22:16 +00:00
|
|
|
};
|
2017-05-16 21:17:46 +00:00
|
|
|
})
|
|
|
|
},
|
2017-06-29 17:41:05 +00:00
|
|
|
session: sessionMock as any,
|
2017-07-16 15:37:13 +00:00
|
|
|
ConnectRedis: Sinon.spy(),
|
|
|
|
dovehash: Sinon.spy() 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);
|
|
|
|
|
2017-05-20 17:16:57 +00:00
|
|
|
assert(sessionMock.calledOnce);
|
|
|
|
assert.equal(sessionMock.getCall(0).args[0].cookie.domain, "example.com");
|
2017-05-16 21:17:46 +00:00
|
|
|
});
|
|
|
|
});
|