2017-05-17 04:17:46 +07:00
|
|
|
|
|
|
|
import * as assert from "assert";
|
|
|
|
import * as sinon from "sinon";
|
|
|
|
import nedb = require("nedb");
|
|
|
|
import * as express from "express";
|
|
|
|
import * as winston from "winston";
|
|
|
|
import * as speakeasy from "speakeasy";
|
|
|
|
import * as u2f from "authdog";
|
|
|
|
|
|
|
|
import { AppConfiguration, UserConfiguration } from "../../src/lib/Configuration";
|
2017-05-20 14:49:05 +07:00
|
|
|
import { GlobalDependencies, Nodemailer } from "../../src/lib/Dependencies";
|
2017-05-17 04:17:46 +07:00
|
|
|
import Server from "../../src/lib/Server";
|
|
|
|
|
|
|
|
|
|
|
|
describe("test server configuration", function () {
|
|
|
|
let deps: GlobalDependencies;
|
|
|
|
|
|
|
|
before(function () {
|
|
|
|
const transporter = {
|
|
|
|
sendMail: sinon.stub().yields()
|
|
|
|
};
|
|
|
|
|
2017-05-20 14:49:05 +07:00
|
|
|
const nodemailer: Nodemailer = {
|
2017-05-17 04:17:46 +07:00
|
|
|
createTransport: sinon.spy(function () {
|
|
|
|
return transporter;
|
|
|
|
})
|
|
|
|
};
|
|
|
|
|
|
|
|
deps = {
|
2017-05-20 14:49:05 +07:00
|
|
|
nodemailer: nodemailer,
|
2017-05-17 04:17:46 +07:00
|
|
|
speakeasy: speakeasy,
|
|
|
|
u2f: u2f,
|
|
|
|
nedb: nedb,
|
|
|
|
winston: winston,
|
|
|
|
ldapjs: {
|
|
|
|
createClient: sinon.spy(function () {
|
|
|
|
return { on: sinon.spy() };
|
|
|
|
})
|
|
|
|
},
|
|
|
|
session: sinon.spy(function () {
|
|
|
|
return function (req: express.Request, res: express.Response, next: express.NextFunction) { next(); };
|
|
|
|
})
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
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 14:49:05 +07:00
|
|
|
username: "user@example.com",
|
|
|
|
password: "password"
|
2017-05-17 04:17:46 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} as UserConfiguration;
|
|
|
|
|
|
|
|
const server = new Server();
|
|
|
|
server.start(config, deps);
|
|
|
|
|
|
|
|
assert(deps.session.calledOnce);
|
|
|
|
assert.equal(deps.session.getCall(0).args[0].cookie.domain, "example.com");
|
|
|
|
});
|
|
|
|
});
|