2017-07-19 19:06:12 +00:00
|
|
|
import { SessionConfigurationBuilder } from "../../../src/server/lib/configuration/SessionConfigurationBuilder";
|
|
|
|
import { AppConfiguration } from "../../../src/server/lib/configuration/Configuration";
|
2017-07-16 12:55:01 +00:00
|
|
|
import { GlobalDependencies } from "../../../src/types/Dependencies";
|
2017-07-19 19:06:12 +00:00
|
|
|
|
2017-07-02 20:24:51 +00:00
|
|
|
import ExpressSession = require("express-session");
|
|
|
|
import ConnectRedis = require("connect-redis");
|
2017-07-16 15:37:13 +00:00
|
|
|
import Sinon = require("sinon");
|
2017-07-02 20:24:51 +00:00
|
|
|
import Assert = require("assert");
|
|
|
|
|
2017-07-13 21:04:08 +00:00
|
|
|
describe("test session configuration builder", function () {
|
2017-07-02 20:24:51 +00:00
|
|
|
it("should return session options without redis options", function () {
|
|
|
|
const configuration: AppConfiguration = {
|
|
|
|
access_control: {
|
|
|
|
default: [],
|
|
|
|
users: {},
|
|
|
|
groups: {}
|
|
|
|
},
|
|
|
|
ldap: {
|
|
|
|
url: "ldap://ldap",
|
|
|
|
user: "user",
|
2017-09-02 20:38:26 +00:00
|
|
|
password: "password",
|
|
|
|
groups_dn: "ou=groups,dc=example,dc=com",
|
|
|
|
users_dn: "ou=users,dc=example,dc=com",
|
|
|
|
group_name_attribute: "",
|
|
|
|
groups_filter: "",
|
|
|
|
mail_attribute: "",
|
|
|
|
users_filter: ""
|
2017-07-02 20:24:51 +00:00
|
|
|
},
|
|
|
|
logs_level: "debug",
|
|
|
|
notifier: {
|
|
|
|
filesystem: {
|
|
|
|
filename: "/test"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
port: 8080,
|
|
|
|
session: {
|
|
|
|
domain: "example.com",
|
|
|
|
expiration: 3600,
|
|
|
|
secret: "secret"
|
|
|
|
},
|
2017-07-19 19:06:12 +00:00
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
in_memory: true
|
|
|
|
}
|
|
|
|
}
|
2017-07-02 20:24:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const deps: GlobalDependencies = {
|
2017-07-16 15:37:13 +00:00
|
|
|
ConnectRedis: Sinon.spy() as any,
|
|
|
|
ldapjs: Sinon.spy() as any,
|
|
|
|
nedb: Sinon.spy() as any,
|
|
|
|
nodemailer: Sinon.spy() as any,
|
|
|
|
session: Sinon.spy() as any,
|
|
|
|
speakeasy: Sinon.spy() as any,
|
|
|
|
u2f: Sinon.spy() as any,
|
|
|
|
winston: Sinon.spy() as any,
|
|
|
|
dovehash: Sinon.spy() as any
|
2017-07-02 20:24:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const options = SessionConfigurationBuilder.build(configuration, deps);
|
|
|
|
|
|
|
|
const expectedOptions = {
|
|
|
|
secret: "secret",
|
|
|
|
resave: false,
|
|
|
|
saveUninitialized: true,
|
|
|
|
cookie: {
|
|
|
|
secure: false,
|
|
|
|
maxAge: 3600,
|
|
|
|
domain: "example.com"
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
Assert.deepEqual(expectedOptions, options);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return session options with redis options", function () {
|
|
|
|
const configuration: AppConfiguration = {
|
|
|
|
access_control: {
|
|
|
|
default: [],
|
|
|
|
users: {},
|
|
|
|
groups: {}
|
|
|
|
},
|
|
|
|
ldap: {
|
|
|
|
url: "ldap://ldap",
|
|
|
|
user: "user",
|
2017-09-02 20:38:26 +00:00
|
|
|
password: "password",
|
|
|
|
groups_dn: "ou=groups,dc=example,dc=com",
|
|
|
|
users_dn: "ou=users,dc=example,dc=com",
|
|
|
|
group_name_attribute: "",
|
|
|
|
groups_filter: "",
|
|
|
|
mail_attribute: "",
|
|
|
|
users_filter: ""
|
2017-07-02 20:24:51 +00:00
|
|
|
},
|
|
|
|
logs_level: "debug",
|
|
|
|
notifier: {
|
|
|
|
filesystem: {
|
|
|
|
filename: "/test"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
port: 8080,
|
|
|
|
session: {
|
|
|
|
domain: "example.com",
|
|
|
|
expiration: 3600,
|
|
|
|
secret: "secret",
|
|
|
|
redis: {
|
|
|
|
host: "redis.example.com",
|
|
|
|
port: 6379
|
|
|
|
}
|
|
|
|
},
|
2017-07-19 19:06:12 +00:00
|
|
|
storage: {
|
|
|
|
local: {
|
|
|
|
in_memory: true
|
|
|
|
}
|
|
|
|
}
|
2017-07-02 20:24:51 +00:00
|
|
|
};
|
|
|
|
|
2017-07-16 15:37:13 +00:00
|
|
|
const RedisStoreMock = Sinon.spy();
|
2017-07-13 21:04:08 +00:00
|
|
|
|
2017-07-02 20:24:51 +00:00
|
|
|
const deps: GlobalDependencies = {
|
2017-07-16 15:37:13 +00:00
|
|
|
ConnectRedis: Sinon.stub().returns(RedisStoreMock) as any,
|
|
|
|
ldapjs: Sinon.spy() as any,
|
|
|
|
nedb: Sinon.spy() as any,
|
|
|
|
nodemailer: Sinon.spy() as any,
|
|
|
|
session: Sinon.spy() as any,
|
|
|
|
speakeasy: Sinon.spy() as any,
|
|
|
|
u2f: Sinon.spy() as any,
|
|
|
|
winston: Sinon.spy() as any,
|
|
|
|
dovehash: Sinon.spy() as any
|
2017-07-02 20:24:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const options = SessionConfigurationBuilder.build(configuration, deps);
|
|
|
|
|
|
|
|
const expectedOptions: ExpressSession.SessionOptions = {
|
|
|
|
secret: "secret",
|
|
|
|
resave: false,
|
|
|
|
saveUninitialized: true,
|
|
|
|
cookie: {
|
|
|
|
secure: false,
|
|
|
|
maxAge: 3600,
|
|
|
|
domain: "example.com"
|
2017-07-13 21:04:08 +00:00
|
|
|
},
|
2017-07-16 15:37:13 +00:00
|
|
|
store: Sinon.match.object as any
|
2017-07-02 20:24:51 +00:00
|
|
|
};
|
|
|
|
|
2017-07-16 15:37:13 +00:00
|
|
|
Assert((deps.ConnectRedis as Sinon.SinonStub).calledWith(deps.session));
|
2017-07-13 21:04:08 +00:00
|
|
|
Assert.equal(options.secret, expectedOptions.secret);
|
|
|
|
Assert.equal(options.resave, expectedOptions.resave);
|
|
|
|
Assert.equal(options.saveUninitialized, expectedOptions.saveUninitialized);
|
|
|
|
Assert.deepEqual(options.cookie, expectedOptions.cookie);
|
|
|
|
Assert(options.store != undefined);
|
2017-07-02 20:24:51 +00:00
|
|
|
});
|
|
|
|
});
|